I try to send 4 sensor data to Particle.io cloud. I use cds, gas sensors and DHT11.
Cds and Gas sensor combo works OK, but after I connect DHT11 problem sterts. Photon is restarting over and over. LED on Photon is switching magenta to green over and over. So I cannot update firmware to the photon.
I am wondering it is code problem or hardware problem. Here is my code.
Please please let me know. THank you people.
// This #include statement was automatically added by the Particle IDE.
#include "Adafruit_DHT/Adafruit_DHT.h"
#include "thingspeak/thingspeak.h"
ThingSpeakLibrary::ThingSpeak thingspeak ("DAB3KTRWFUCAI7RX");
#define DHTPIN 6
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
int led1 = D0;
int led2 = D7;
int cdsInput = A0;
int gasInput = A1;
int cdsValue = 0;
int gasValue = 0;
int humidValue = 0;
int tempValue = 0;
void setup() {
Serial.begin(9600);
Serial.println("DHTxx test!");
dht.begin();
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
//Particle.function("led",ledToggle);
Particle.variable("cdsRead", &cdsValue, INT);
Particle.variable("gasRead", &gasValue, INT);
//Particle.variable("humidRead", &humidValue, INT);
//Particle.variable("tempRead", &tempValue, INT);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
}
void loop() {
Serial.println("Loop start");
float humidValue = dht.getHumidity();
float tempValue = dht.getTempCelcius();
float faren = dht.getTempFarenheit();
/*
if (isnan(humidValue) || isnan(tempValue) || isnan(faren)) {
Serial.println("Failed to read from DHT sensor!");
humidValue = -5000;
tempValue = -5000;
return;
}
*/
cdsValue = analogRead(cdsInput);
gasValue = analogRead(gasInput);
//Sending data to Particle.io cloud Server;
Particle.publish("cdsRead", String(cdsValue));
Particle.publish("gasRead", String(gasValue));
//Particle.publish("humidRead", String(humidValue));
//Particle.publish("tempRead", String(tempValue));
// Sending data to Thingspeak
bool valSet1 = thingspeak.recordValue(1, String(gasValue, DEC));
bool valsSent1 = thingspeak.sendValues();
bool valSet2 = thingspeak.recordValue(2, String(cdsValue, DEC));
bool valsSent2 = thingspeak.sendValues();
bool valSet3 = thingspeak.recordValue(3, String(humidValue, DEC));
bool valsSent3 = thingspeak.sendValues();
bool valSet4 = thingspeak.recordValue(4, String(tempValue, DEC));
bool valsSent4 = thingspeak.sendValues();
if(valSet1) {
Serial.println("Value set to field 1 : " + String(gasValue, DEC));
} else {
Serial.println("Value not set successfully");
}
if(valsSent1) {
Serial.println("Value successfully sent to thingspeak");
} else {
Serial.println("Sending to thingspeak failed");
}
if(valSet2) {
Serial.println("cdsValue set to field 2 : " + String(cdsValue, DEC));
} else {
Serial.println("cdsValue not set successfully");
}
if(valsSent2) {
Serial.println("gasValue successfully sent to thingspeak");
} else {
Serial.println("gasSending to thingspeak failed");
}
delay(5000);
}