Blynk+esp8266+DHT22

Hello I tryed this project code, work on my smartphone android and I’ve two value display
umidity and temperature.

//#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_HardSer.h>
#include <BlynkSimpleShieldEsp8266_HardSer.h>
#include <DHT.h>
#define DHTTYPE DHT22
#define DHTPIN A0

DHT dht(DHTPIN, DHTTYPE, 30); 
float humidity, temp_f;  // Values read from sensor

// Set ESP8266 Serial object
#define EspSerial Serial


ESP8266 wifi(EspSerial);

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

WidgetLED led1(0);

void setup()
{
  // Set console baud rate
  Serial.begin(115200);
  delay(10);
  // Set ESP8266 baud rate
  EspSerial.begin(115200);
  delay(10);

  Blynk.begin(auth, wifi, "WiFi", "12345678901234567890");
  dht.begin();           // initialize temperature sensor
}

BLYNK_READ(0) // Led at V0 as Input
{
if (digitalRead(13) == HIGH) { // if your digital input is high
led1.on();
} else {
led1.off();
}
}

BLYNK_READ(1) 
{ 
temp_f = dht.readTemperature(false)- 1.8;// Read temperature as Celsius
int value=temp_f*10;
String str;
char result[5];
result[0]=(value/100)+'0';
result[1]=((value/10)%10)+'0';
result[2]='.';
result[3]=(value%10)+'0';
result[4]='\0';
str +=result;
str +="℃";
//char buf[str.length()+1];
char buf[8];
str.toCharArray(buf,sizeof(buf));
Blynk.virtualWrite(1,buf); 
}


BLYNK_READ(2) 
{ 
humidity = dht.readHumidity();           // Read humidity (percent)
int value=humidity*10;
String str;
char result[5];
result[0]=(value/100)+'0'; 
result[1]=((value/10)%10)+'0';
result[2]='.';
result[3]=(value%10)+'0';
result[4]='\0';
str +=result;
str +="%";
//char buf[str.length()+1];
char buf[8];
str.toCharArray(buf,sizeof(buf));
Blynk.virtualWrite(2,buf); 
}



void loop()
{
  Blynk.run();
}

I need insert in my project
temperature graph (Graph Setting botton on smartphone)

how is possible it?

The widget History Graph 8.9 virtual pin connection data DHT22.

//#define BLYNK_PRINT Serial    // Comment this out to     disable prints and save space
    #include <ESP8266WiFi.h>
    #include <BlynkSimpleEsp8266.h>
    char auth[] = "------------";
    #include <DHT.h>
    #define DHTPIN 12 //pin gpio 12 in sensor
    #define DHTTYPE DHT22  
    DHT dht(DHTPIN, DHTTYPE);
    #include <SimpleTimer.h>
    SimpleTimer timer;

void sendUptime()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  t = ((int) (t * 10) / 10.0);
  h = ((int) (h * 10) / 10.0);
  
  Blynk.virtualWrite(8, t); // virtual pin
  Blynk.virtualWrite(9, h); // virtual pin
}

void setup()
{
  Blynk.begin(auth, "wifi", "pass");
  dht.begin(); 
  timer.setInterval(10000, sendUptime);//1000=1s

}

void loop() {
  Blynk.run();
  timer.run();

}
1 Like

Why is necessary this line? h = ((int) (h * 10) / 10.0);

Couldnt use just h ?

@alvaroaguero55 I know it’s not easy to always tell on the forum but the last post for this thread was 15th Dec 2015. Over a year ago, and as the libraries keep changing then anything older than a month or two is out of date and causes lots of problems when Blynkers try to use the sketches.

The line you refer to is a common coding “hack” relating to integers / floats and rounding etc. The 10.0 is the significant part.