I have tried the following code but no value appeared. changed my wemos, sensor and cable but still does not work.
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "-";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "SINGTEL-FA54";
char pass[] = "zucheohaen";
#define DHTPIN D4 // What digital pin we're connected to
#define DHTTYPE DHT22 // DHT 22, AM2302, AM2321
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
// This function sends Arduino's up time every second to Virtual Pin (5).
// In the app, Widget's reading frequency should be set to PUSH. This means
// that you define how often to send data to Blynk App.
void sendSensor()
{
float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit
if (isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
return;
}
Blynk.virtualWrite(V12, t);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
dht.begin();
timer.setInterval(1000L, sendSensor);
}
void loop()
{
Blynk.run();
timer.run();
}
It says fail to read sensor but I’m not too sure why. As mentioned, I have changed all components for multiple times. My device is online on Blynk App as well.
I have been trying to troubleshoot this issue for weeks… temperature on blynk app is either garbage value or no reading.
Add some serial print lines to see exactly what nan (not a number) values the sensor is giving.
Check that your DHT library is up to date, and maybe delete it and install a different one instead.
Pin D4 (GPIO2) isn’t a great choice of pin either:
You only get the “failed to read…” message if the value returned by the sensor is not a number.
I was suggesting that you add some serial print messages to see what was being returned.
And what about the suggestion to change the library?