BLYNK
HOME       📲 GETTING STARTED       📗 DOCS       ❓HELP CENTER       👉 SKETCH BUILDER

Dht11 esp8266

esp8266

#1

I HAVE A PROBLEM WITH THE FOLLOWING CODE.
EVERYTHING WORKS I SEE THE DATA IN THE SERIAL MONITOR BUT IN THE GAUGE TEMPERATURE AND HUMIDITY APP BLINK DOES NOT RECEIVE ANY DATA.
WHO CAN HELP ME

#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "XXXXXXXXXXXXXXX";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "XXXXXXXXXXXXX";
char pass[] = "XXXXXXXXX";


#include <DHT.h>

#define DHTPIN 14 // what pin we're connected to
#define DHTTYPE DHT11   // DHT 11 
//#define DHTTYPE DHT22   // DHT 22
DHT dht(DHTPIN, DHTTYPE);

#define BLYNK_GREEN     "#23C48E"
#define BLYNK_RED       "#D3435C"
#define BLYNK_BLUE      "#04C0F8"

float t, h;
float setpoint;
int value = 0;

BlynkTimer timer;
WidgetLED led1(V1);

// 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 h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }

    Blynk.virtualWrite(V3,h);
  Blynk.virtualWrite(V4,t);
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Serial.println(h);
  Serial.println(t);
  

 
  if ((setpoint > t ) && (value == 1)) {
    digitalWrite(5, LOW);
  } else {
    digitalWrite(5, HIGH);
  }
}
void ledCaldaia()
{

  if (digitalRead(5) == 1) {
    Serial.println("RELE OFF");
    led1.off();
    led1.setColor(BLYNK_BLUE);
  } else {
    Serial.println("RELE ON");
    led1.on();
    led1.setColor(BLYNK_RED);
  }
}

void setup() {
  // Debug console
  Serial.begin(9600);
  dht.begin();
  timer.setInterval(5000L, sendSensor);
  timer.setInterval(2000L, ledCaldaia);
  Blynk.begin(auth, ssid, pass);
  digitalWrite(5, HIGH);
  pinMode(5, OUTPUT);   // rele caldaia

}

BLYNK_CONNECTED() {
  Blynk.syncAll();
}

void loop() {
  Blynk.run();
  timer.run();
}
BLYNK_WRITE(V2)
{
  setpoint = param.asInt(); // Get value as integer
  Serial.println(setpoint);
}
BLYNK_WRITE(V0)
{
  value = param.asInt();  // Use param as usual.
  Serial.println(value);
}



#2

(Gauge Widget only takes integers… - EDIT: Wrong!! :blush: ) try the Labeled Display Widget… or better yet, since the DHT11 also only does integers, switch from float to int


#3

:thinking:

14-026120


#4

Alexis can you give me some advice … I converted the float integer and now I see the data on the widget … But how do you read the float on the gauge?


#5
float h, t, t2, TempPer, DewPoint, Pente, Parallele;

Blynk.virtualWrite(V32, TempPer);

14-026132


#6

@Alexis_Cabrera Right you are!! I think I had a sleep typing moment or something :blush: becasue I have no idea why I said that?? I have even used it myself that way… doh :man_facepalming:


#7

I have tried to get float value on DHT11 but i always get int value. I think DHT11 cant provide float value. I might be wrong but here again in Almighty Gunner’s example, used float but got int value…


#8

That is correct. The DHT22 can do floats, but not the DHT11 which is also limited in accuracy by -+2 degrees as well.


#9

the best way to display 2 decimals with DHT11, is to display the temperature you feel.