ESP8266 HVAC control

how convert dht fahrenheit to celcius in this code?

@Jean_Masse ask Google.

1 Like

I think you just change the line

  float ReadF = dht.readTemperature(true);


  float ReadF = dht.readTemperature();
1 Like

If the above solution doesn’t work, you might have to revert to math :scream: I do not like math, or is it math doesn’t like me?

Hi there Everyone!!

First i wanna say, your code is awesome @chrome1000 It help me a lot. Im new in this.

I was wondering how can i get counts of how many times the “Fan” is ON. The code function in frequency, soo if a put a counter when the “FAN” gets “ON” it will count all the time cycle begins.

Thanks from Panama!!

int Counter = 0; 

if (HumAct < HumDes){
    else if (HumAct >= (HumDes)) {

Just to pitch in, this is how I’m doing it:

void totalRuntime()
  if (digitalRead(blowerPin) == LOW) // If fan is running...
    ++currentCycleSec;               // accumulate the running time, however...
    currentCycleMin = (currentCycleSec / 60);
  else if (digitalRead(blowerPin) == HIGH && currentCycleSec > 0) // if fan is off but recorded some runtime...
    Blynk.virtualWrite(110, ++hvacTodaysStartCount);              // Stores how many times the unit has started today... adds one start.

    currentCycleSec = 0;                                          // Reset the current cycle clock
    currentCycleMin = 0;

totalRuntime is something that I have running every second. As you can see, this solution is intertwined with recording a current fan cycle runtime… something you may or may not be interested in! I reset all these values at midnight.

A post was merged into an existing topic: WIFI temperature level control with set point and hysteresis, DHT22 and relay on/off

When I first posted this project, it occurred to me that my particular 2-pipe HVAC system was pretty specific, and I wondered how it might to adapt it to other systems (e.g. forced air or radiant). Is anyone using it for another type of heating / cooling system, and if so, what changes were necessary to make for it to work?

I am using it for auxilary heater in my camping car. The only modifications I have made is visual appearance on blynk control pannel :wink:

1 Like

@structure7 thanks for the support!!.

@chrome1000 I´m using for control humidity for mushroom! thanks for the contribution and support. I will post it soon here,

1 Like

I am using it in my camper to controll Webasto heater and the first idea was to use gsm module (actually I have attached it, but never managed to properly configure it) Since I am not using it every day, i just put a spare android phone in my camper with turned on a mobile hotspot and use normal wemos wifi solution.

But most used scenario. I am laying on my bed in a camper and I am too lazy to adjust the thermostat. I just create a mobile hot spot on the phone I am using, wemos automatically connects to it and then I just adjust the temperature.

I tweaked the code to work with a DS18B20 1-wire sensor and am using it to control a fermentation fridge.

Thanks for the great code

What more noble cause could there be than bringing more beer to the world? :beers:

Now I just need to figure out the code to make the fridge only run for 5 minutes at a time, otherwise the temp is a roller coaster and I don’t want to be quick cycling it too much.

Well, the fermentation fridge was the first on my list, next up is my reef aquarium heater

Shutting it off after 5 minutes sort of defeats the purpose of having a thermostat. It might make more sense set the Simple Timer to run TempUpdate less frequently (e.g. every 15 minutes), or to increase the hysteresis level in the App settings, so that the compressor runs for longer periods, but less frequently. That assumes, of course, that whatever you’re fermenting can handle the temperature swings.

If the problem stems from large fluctuations in the sensor readings, you could try average together more readings from the sensor to get a more stable TempAct.

I have it checking every 5 minutes(ill have to check my code), but what is happening is that in that time frame, the temp drops too low. I have the hysteria set at 2. Trying to get me my temp prob down into the Carboy which should work a lot better, but not a lot of space on the cap to install a thermowell. This is the kind of temp swing I am getting.

Assuming you’re getting good readings from your temperature probe (which you’ve already noted may be a problem), the nature of any thermostat is that temperature control precision increases proportionally with the frequency of heating / cooling cycles. If you need both precise temperature control AND infrequent cycles, the answer is to use better insulation on the carboy.

Hi there,

This is what i did with your code @chrome1000, Im using to control humidity for mushrooms.

Items List:

  • Arduino Uno
  • Relay module
  • Ethernet Shield
  • Sensor Shield v5 (to have better wiring for sensors)
  • 2 DHT22 Sensors

I use two sensors, one is just for reading and the other is for controlling humidity. The first sensor is wired 12m and the other 16m from the arduino.

I was using a electrovalve to control the water that goes in to mist system. Now i bought a ultrasonic fogger machine beacuse it make better Fog for grow mushrooms.

Now i have a problem to control this ultrasonic machine. I want to add a Delay when it turn ON beacuse i dont want to turn on/off it every second when the humidity goes down. This machine runs in 220v, soo i control it with electrical contactor.

If someone have a clue to solve it, it will be a good one. I appreciate that!:pray::grin:

I´m new in this stuff, soo if you see something wrong or to be improve please let me known.

P.S: - sorry for my grammar, english is not my native language. :sweat_smile:
- Soon i will post some pics. of the proyect.

Blink dashboard:

  • Incubacion = Incubation room Temperature (red one)
  • Incubacion= Incubation room Humidity (green one)
  • Frutificacion= grow room Temperature(yellow one)
  • Seleccionar humedad deseada= Select desired humidity (Slider)
  • Humedad Frutificacion= grow room Humidity
  • Humedad Deseada= Selected Humidity


#include <SPI.h>
#define BLYNK_PRINT Serial   
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>
#include <avr/wdt.h> 
#include <DHT.h>

char auth[] = "authToken";
//setup Ethernet 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { IP };
byte gateway[] = { gateway };
byte subnet[] = { subnet };

SimpleTimer timer;

#define DHTPIN 5
#define DHTPIN1 3     
#define DHTTYPE DHT22 //sensor 1
#define DHTTYPE1 DHT22 //sensor 2


int HumDes = 85;
int PreviousHumDes = 85;
int HumAct = dht.readHumidity();
int HumCorrection = 0; // i dont use corrections for the sensors
int UpdateFrequency = 4000L; 
float LastRead;

int RelayPin = 7;

boolean FirstRead = true;
WidgetLED led1(V2); //for led on/off dashboard 

void setup() 
  Ethernet.begin(mac,ip, gateway, subnet); //call setup ethernet
  dht.begin(); //sensor 1
  dht1.begin(); //sensor 2


  Serial.print("IP = ");
  timer.setInterval(UpdateFrequency, HumUpdate);

  HumDes = param.asInt();

void HumUpdate() //Algorithm for turnig Electrovalve
  float ReadH = dht.readHumidity();
  float t = dht.readTemperature(); 
  float h1 = dht1.readHumidity();
  float t1 = dht1.readTemperature();
  Blynk.virtualWrite(V6, t);
  Blynk.virtualWrite(V7, h1);
  Blynk.virtualWrite(V8, t1);

  if (isnan(ReadH)) {
    Serial.println(F("Failed to read from DHT sensor!"));
  if (FirstRead == true){
    HumAct = (int)(ReadH + HumCorrection);
    FirstRead = false;
    Serial.print("First humidiy reading (corrected): ");
    LastRead = ReadH;
  else   { 
    int HumAvg = (int)((ReadH + LastRead + (2 * HumCorrection))/2);
    if (HumAvg >= HumAct + 1){
      HumAct = HumAct + 1;
    if (HumAvg <= HumAct - 1){
      HumAct = HumAct -1;

    LastRead = ReadH;
  Blynk.virtualWrite(V0,ReadH);  //I just wanna see the actual humidity
  Serial.print("Actual Humidity (corrected): ");
    if (HumAct < HumDes){
    else if (HumAct >= (HumDes)) {

void loop() 

The answer to preventing your humidifier from turning on and off so frequently is to include a hysteresis level. This is necessary in thermostats, as well. If you check my code, there are hysteresis levels included for both heating and cooling. Hysteresis is the amount of additional change that you want the system to make beyond the nominal level. If I have the heat set to 72F with a 2 degree hysteresis, the heat will turn on at 71F, but will actually remain on until the temperature reaches 74 degrees. The set temperature and hysteresis define a minimum and maximum acceptable range of temperatures.

For example, if you wanted to maintain 70% humidity in your growing environment, you might tell the humidifier to turn on when humidity drops below 68% (your minimum). If you added a hysteresis level of 5%, the humidifier would continue to run until it reached 73% humidity (your maximum).

Hope this is helpful.

1 Like

You could also define minimum run times, so that you wait until the minimum runtime has expired before you check if the humidity is below the minimum minimum humidity hysteresis level.


1 Like