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

How to add slider in blynk to control temperature setpoint


#41


#42

And is it any different if you disconnect the relay wiring?


#43

it is the same still failed to read from dht


#44

Flash the DHT sketch that works OK and keep the same Blynk token etc.

Paste Serial Monitor and sketch that gives correct temperature readings.


#45

here are the code that are working

#include <BlynkSimpleEsp8266.h>
#include <DHT.h>
int LED  = 5;

// 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[] = "";
char pass[] = "";
 
#define DHTPIN 0          // D3
 
// Uncomment whatever type you're using!
#define DHTTYPE DHT11     // DHT 11

 
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;
 
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;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, t);
  Blynk.virtualWrite(V6, h);
  
  
}

void setup()
{
 
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
  dht.begin();
 
 
  // Setup a function to be called every second
  timer.setInterval(1000L, sendSensor);
}
 
void loop()
{
  Blynk.run();
  timer.run();
}```

#46

This are the serial monitor, although it says failed to read but i can get reading normally on the blynk app


#47

I don’t know how Blynk can have accurate data if the sensor is not being read correctly.

Do you have a 1K resistor between pins 1 and 2 on the DHT11?


#48

Change the 1000L to 5000L.


#49

iam using the dht11 module with build in resistor ( that what the seller said)


#50

Are you connecting to 3.3 / 5V on the ESP? Needs to be 3.3V.


#51

yup i connected to 3.3v on the esp


#52

OK stick at it until you can get Serial Monitor to confirm actual DHT sensor readings.


#53

i have another code that can display the reading from serial monitor but it doesnt connected to blynk


#54

OK paste that for me to check it over but obviously we will need the Blynk stuff in the sketch to move forward.


#55

here the code

// Written by ladyada, public domain

#include "DHT.h"

#define DHTPIN 0     // what digital pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11


// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.
DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Serial.begin(9600);
  Serial.println("DHTxx test!");

  dht.begin();
}

void loop() {
  // Wait a few seconds between measurements.
  delay(2000);

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();
  // Read temperature as Fahrenheit (isFahrenheit = true)
  float f = dht.readTemperature(true);

  // 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!");
    return;
  }

  // Compute heat index in Fahrenheit (the default)
  float hif = dht.computeHeatIndex(f, h);
  // Compute heat index in Celsius (isFahreheit = false)
  float hic = dht.computeHeatIndex(t, h, false);

  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(hic);
  Serial.print(" *C ");
  Serial.print(hif);
  Serial.println(" *F");
}```

#56

here’s the serial monitor


#57

Change the delay(2000) to delay(5000). I would like to see a full page without errors before trying to move forward.

2000ms should be ok but you have any issue somewhere.

Do you just have the one DHT11?


#58

Try this loop() which just reads temperature:

void loop() {
  // Wait a 5 seconds between measurements.
  delay(5000);
  
  // Read temperature as Celsius (the default)
  float t = dht.readTemperature();

  // Check if any reads failed and exit early (to try again).
  if (isnan(t)) {
    Serial.println("Failed to read temperature!");
    return;
  }

  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.println(" *C ");
}

#59

i have 1 more dht for spare… Changed the delay to 5000 and here the result


#60

So the 2000ms looks to be a problem and therefore the interval of 1000ms you had in the Blynk sketch will certainly be a problem.

You can probably switch back to the Blynk sketch but ensure the interval is 5000ms (or higher).

You probably only need temperature so you could cut out the humidity reading.