Any ideas on why I keep getting strange readings from my Temperature sensor? Seems like it should be pretty straightforward, but alas have not had any luck. I have tried 2 different sensors so I think it must be my code or wiring configuration.
// This #include statement was automatically added by the Particle IDE.
#include <Adafruit_DHT.h>
// This example assumes the sensor to be plugged into CONN2
#define DHTPIN D1 // what pin we're connected to
// Here we define the type of sensor used
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
// We open up a serial port to monitor the sensor values
Serial.begin(9600);
Serial.println("DHT11 test!");
dht.begin();
}
void loop() {
// Wait a few seconds between measurements.
delay(5000);
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds
float h = dht.getHumidity();
// Read temperature as Celsius
float t = dht.getTempCelcius();
// Read temperature as Farenheit
float f = dht.getTempFarenheit();
// Check if any reads failed and exit early (to try again).
// if (isnan(h) || isnan(t) || isnan(f)) {
// Serial.println("Failed to read from DHT sensor!");
// Particle.publish("error", "No data collected");
// return;
// }
// Print the data over serial
Serial.print("Humid: ");
Serial.print(h);
Serial.print("% - ");
Serial.print("Temp: ");
Serial.print(f);
Serial.print("*F ");
Serial.println(Time.timeStr());
// Publish data to the Particle cloud.
// Remember that you'll consume data every time you publish to the cloud.
Particle.publish("temp", String (f));
Particle.publish("humi", String (h));
}