ESP 12E devkit with Nextion Screen 3.5

Yes, you can use both SoftSerial for the Nextion and I2C for sensor, but they do have to be on different pins. I’m not sure where the I2C pins on the ESP12 are, so you may have to adjust your softserial pins to other pins if they currently overlap.

I’m not even sure the ESP has hardware I2C to be honest.

This might be useful:

I2C (Wire library)

Wire library currently supports master mode up to approximately 450KHz. Before using I2C, pins for SDA and SCL need to be set by calling Wire.begin(int sda, int scl), i.e. Wire.begin(0, 2) on ESP-01, else they default to pins 4(SDA) and 5(SCL)

From https://github.com/esp8266/Arduino/blob/master/doc/libraries.md#i2c-wire-library

Ok thanks. And if i use Wire.begin(0, 2) : so 0 is D3 to SDA and 2 is D4 to SCL ?right

And have i to do define ? : #define I2C_SCL 0 #define I2C_SDA 2

@Jiri_Bam 0 and 2 is just for the ESP01’s that ONLY have 0 and 2.

For all other ESP’s you should use the allocated pins of 4 and 5 (D2 and D1 respectively). Then you can just call Wire.begin().

If you are already using 4 and 5 for the Nextion or whatever try other pins and modify the Wire.begin() call.
0 and 2 would be the last pins I would use as they are special. I assume you have a pinout diagram for your hardware.

Ok. THat is my problem. SO can i use for Nextion pin D5 and D6?
SoftwareSerial HMISerial(12,14,false,256);//RX-D5 , TX-D6

Try it and see, the worst that can happen is it all blows up :slight_smile:

1 Like

So blows up wasnt. But i see something wrong is with SI7021 sensor. If i delete //SI7021 sensor; from sketch so are data show on Nextion. BUt BH1750 show bad data… Thanks.

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#include <BH1750.h>
#include <Wire.h>
#include <SI7021.h>
 
 float temp, hum;
 bool SI7021_present = true;
#define I2C_SCL 4    //d2         // Barometric Pressure Sensor (BMP085)
#define I2C_SDA 5   //d1
 //SI7021 sensor;

#include <Nextion.h>
#include <SoftwareSerial.h>
BH1750 lightMeter;

#define DHTPIN 2 //D4
#define DHTTYPE DHT22   // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";  // Put your Auth Token here. (see Step 3 above)

SoftwareSerial HMISerial(12,14,false,256);//RX-D1 5 , TX-D2 6
Nextion myNextion(HMISerial, 9600);

SimpleTimer timer;

void setup()
{     
  Wire.begin();
  //sensor.begin();
 lightMeter.begin();
  
  Serial.begin(9600); // See the connection status in Serial Monitor
  Blynk.begin(auth, "", ""); //insert here your SSID and password

  myNextion.init();
 
  // Setup a function to be called every second
  timer.setInterval(10000L, sendUptime);
}

void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
   //Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  Blynk.virtualWrite(2, t); // virtual pin 
  Blynk.virtualWrite(3, h); // virtual pin 


int16_t lux = lightMeter.readLightLevel();
  Blynk.virtualWrite(4, lux);
myNextion.setComponentText("t5", String(lux));
 
  myNextion.setComponentText("t1", String(t));
  myNextion.setComponentText("t2", String(h));
  delay(1000);

  String dim = "dim=50";         //pro podsvíceni 
  myNextion.sendCommand(dim.c_str()); //pro podsvícení

}



void loop()
{
  Blynk.run();
  timer.run();
}
[1848] Free RAM: 44576
[5001] Connecting to blynk-cloud.com:8442
[6464] <[02|00|01|00] c7e6d0b5b68a476a9711ca56b76372ab
[6877] >[00|00|01|00]Č
[6877] Ready (ping: 232ms).
[6877] <[11|00|01|00]Hver[00]0.4.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Feb 10 2017 22:51:03[00]
[8360] >[00|00|01|00]Č
[18030] <[06|00|02|00|00]
[18455] <[14|00|03|00|0B]vw[00]2[00]23.800
[18531] <[14|00|04|00|0B]vw[00]3[00]48.900
[18680] <[14|00|05|00|0B]vw[00]4[00]-10924
[19953] >[00|00|02|00]Č
[28455] <[14|00|06|00|0B]vw[00]2[00]23.800
[28511] <[14|00|07|00|0B]vw[00]3[00]48.700
[28713] <[14|00|08|00|0B]vw[00]4[00]-10924
[29961] <[06|00|09|00|00]
[30128] >[00|00|09|00]Č

SO now it is working good. My problem was in :sensor.begin(4,5); Wire.begin(4,5);

But now i dont know how i add to my sketch this sketch;
On arduino it is working good… But there i have //CO21; in void loop

#define pwmPin 5 //CO2
#define LedPin 13
int prevVal = LOW;  //CO2
long th, tl, h, l, ppm;

myNextion.setComponentText("t0", String(ppm));

//CO21;
long tt = millis();
  int myVal = digitalRead(pwmPin);

  //Если обнаружили изменение
  if (myVal == HIGH) {
    digitalWrite(LedPin, HIGH);
    if (myVal != prevVal) {
      h = tt;
      tl = h - l;
      prevVal = myVal;
    }
  }  else {
    digitalWrite(LedPin, LOW);
    if (myVal != prevVal) {
      l = tt;
      th = l - h;
      prevVal = myVal;
      ppm = 5000 * (th - 2) / (th + tl - 4);
      Serial.println("PPM = " + String(ppm));


Create a function called CO21, put the CO21 code in the function and call the function every 10s with SimpleTimer.

Do you mean?
But something is wrong with: timer.setInterval(10000L, readCO2,);

THanks.


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#define DHTPIN 12 //pin gpio 12 in sensor
#define DHTTYPE DHT22   // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";  // Put your Auth Token here. (see Step 3 above)

SimpleTimer timer;

#define pwmPin 5 //CO2
#define LedPin 13
int prevVal = LOW;  //CO2
long th, tl, h, l, ppm;

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
   Blynk.begin(auth, "", ""); //insert here your SSID and password
 
  // Setup a function to be called every second
  timer.setInterval(10000L, sendUptime);

  timer.setInterval(10000L, readCO2,);
}

void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
   //Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  Blynk.virtualWrite(12, t); // virtual pin 
  Blynk.virtualWrite(13, h); // virtual pin 

 Blynk.virtualWrite(11, ppm); // virtual pin 
 myNextion.setComponentText("t0", String(ppm));
}

void readCO2()
{
long tt = millis();
  int myVal = digitalRead(pwmPin);

  //Если обнаружили изменение
  if (myVal == HIGH) {
    digitalWrite(LedPin, HIGH);
    if (myVal != prevVal) {
      h = tt;
      tl = h - l;
      prevVal = myVal;
    }
  }  else {
    digitalWrite(LedPin, LOW);
    if (myVal != prevVal) {
      l = tt;
      th = l - h;
      prevVal = myVal;
      ppm = 5000 * (th - 2) / (th + tl - 4);
      Serial.println("PPM = " + String(ppm));

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

@Jiri_Bam is the “PPM = …” showing in Serial Monitor every 10 seconds?

You should move this part from sendUptime() to the end of readCO2():

Blynk.virtualWrite(11, ppm); // virtual pin 
myNextion.setComponentText("t0", String(ppm));

You have prevVal defined as a global and local variable. I would remove the global declaration.

So in serial monitor is bad ppm.

DO you mean delete: int prevVal = LOW; //CO2

#define BLYNK_DEBUG

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#include <DHT.h>
#include <SoftwareSerial.h>
#include <Nextion.h>
#define DHTPIN 12 //pin gpio 12 in sensor
#define DHTTYPE DHT22   // DHT 22 Change this if you have a DHT11
DHT dht(DHTPIN, DHTTYPE);

SoftwareSerial HMISerial(12,14,false,256);//RX-D1 5 , TX-D2 6
Nextion myNextion(HMISerial, 9600);


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";  // Put your Auth Token here. (see Step 3 above)

SimpleTimer timer;

#define pwmPin 14 //CO2  //D5
#define LedPin 13
int prevVal = LOW;  //CO2
long th, tl, h, l, ppm;

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
   Blynk.begin(auth, "", ""); //insert here your SSID and password
 
  // Setup a function to be called every second
  timer.setInterval(10000L, sendUptime);

  timer.setInterval(10000L, readCO2);
  myNextion.init();
}

void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
   //Read the Temp and Humidity from DHT
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  
  Blynk.virtualWrite(12, t); // virtual pin 
  Blynk.virtualWrite(13, h); // virtual pin 

  
}

void readCO2()
{
long tt = millis();
  int myVal = digitalRead(pwmPin);

  //Если обнаружили изменение
  if (myVal == HIGH) {
    digitalWrite(LedPin, HIGH);
    if (myVal != prevVal) {
      h = tt;
      tl = h - l;
      prevVal = myVal;
    }
  }  else {
    digitalWrite(LedPin, LOW);
    if (myVal != prevVal) {
      l = tt;
      th = l - h;
      prevVal = myVal;
      ppm = 5000 * (th - 2) / (th + tl - 4);
      Serial.println("PPM = " + String(ppm));

  Blynk.virtualWrite(11, ppm); // virtual pin 
  myNextion.setComponentText("t0", String(ppm));

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

serial monitor:

1826] Free RAM: 44720
[5001] Connecting to blynk-cloud.com:8442
[5048] <[02|00|01|00] 75a3e91cbdf1457c9498b35eea63e9c1
[5104] >[00|00|01|00]Č
[5104] Ready (ping: 2ms).
[5104] <[11|00|01|00]Hver[00]0.4.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Feb 12 2017 18:49:21[00]
[5342] >[00|00|01|00]Č
[5343] >[14|1E]b[00|05]
[5344] >vr[00]10
[5344] >[14|1E]b[00|04]
[5344] >vr[00]1
[5344] >[14|1E]b[00|04]
[5349] >vr[00]4
[5367] >[14|1E]b[00|05]
[5393] >vr[00]13
[5411] >[14|1E]b[00|04]
[5437] >vr[00]9
[5455] >[14|1E]b[00|05]
[5481] >vr[00]11
[5500] >[14|1E]b[00|04]
[5526] >vr[00]5
[5544] >[14|1E]b[00|04]
[5570] >vr[00]6
[6333] >[14|1E]b[00|04]
[6333] >vr[00]1
[7341] >[14|1E]b[00|05]
[7341] >vr[00]10
[7341] >[14|1E]b[00|04]
[7341] >vr[00]1
[7341] >[14|1E]b[00|04]
[7341] >vr[00]4
[7341] >[14|1E]b[00|05]
[7367] >vr[00]13
[7385] >[14|1E]b[00|04]
[7411] >vr[00]9
[7429] >[14|1E]b[00|05]
[7455] >vr[00]11
[7474] >[14|1E]b[00|04]
[7500] >vr[00]5
[7518] >[14|1E]b[00|04]
[7544] >vr[00]6
[9336] >[14|1E]b[00|05]
[9336] >vr[00]10
[9336] >[14|1E]b[00|04]
[9336] >vr[00]1

I’ll check.

You only show the first 9.336s in Serial Monitor. I need at least 10s as it is a 10s timer. Can I have first 30s with debug off.

1 Like

[1827] Free RAM: 44720
[5001] Connecting to blynk-cloud.com:8442
[5057] <[02|00|01|00] 75a3e91cbdf1457c9498b35eea63e9c1
[5124] >[00|00|01|00]Č
[5124] Ready (ping: 7ms).
[5124] <[11|00|01|00]Hver[00]0.4.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Feb 12 2017 18:49:21[00]
[5369] >[00|00|01|00]Č
[15488] <[14|00|02|00|09]vw[00]12[00]nan
[15586] <[14|00|03|00|09]vw[00]13[00]nan
[15664] <[06|00|04|00|00]
[15734] >[00|00|04|00]Č
[25488] <[14|00|05|00|09]vw[00]12[00]nan
[25579] <[14|00|06|00|09]vw[00]13[00]nan
[25735] <[06|00|07|00|00]
[25787] >[00|00|07|00]Č
[35489] <[14|00|08|00|09]vw[00]12[00]nan
[35594] <[14|00|09|00|09]vw[00]13[00]nan
[35789] <[06|00|0A|00|00]
[35893] >[00|00|0A|00]Č
[45488] <[14|00|0B|00|09]vw[00]12[00]nan
[45657] <[14|00|0C|00|09]vw[00]13[00]nan
[45894] <[06|00|0D|00|00]
[46034] >[00|00|0D|00]Č
[55488] <[14|00|0E|00|09]vw[00]12[00]nan
[55561] <[14|00|0F|00|09]vw[00]13[00]nan
[56036] <[06|00|10|00|00]
[56082] >[00|00|10|00]Č
[65488] <[14|00|11|00|09]vw[00]12[00]nan
[65572] <[14|00|12|00|09]vw[00]13[00]nan
[66083] <[06|00|13|00|00]
[66143] >[00|00|13|00]Č
[75488] <[14|00|14|00|09]vw[00]12[00]nan
[75623] <[14|00|15|00|09]vw[00]13[00]nan
[76145] <[06|00|16|00|00]
[76433] >[00|00|16|00]Č
[85488] <[14|00|17|00|09]vw[00]12[00]nan
[90489] Cmd error
[90490] Cmd skipped:20
[90491] Connecting to blynk-cloud.com:8442
[91480] <[02|00|01|00] 75a3e91cbdf1457c9498b35eea63e9c1
[91571] >[00|00|01|00]Č
[91571] Ready (ping: 27ms).
[91571] <[11|00|19|00]Hver[00]0.4.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Feb 12 2017 18:49:21[00]
[91694] >[00|00|19|00]Č
[95488] <[14|00|1A|00|09]vw[00]12[00]nan
[95594] <[14|00|1B|00|09]vw[00]13[00]nan
[101696] <[06|00|1C|00|00]
[101871] >[00|00|1C|00]Č


the nan entries mean your DHT22 is not working, I’ll leave you to find out why.

I asked for the two following 2 lines to go at the end of readCO2()

Blynk.virtualWrite(11, ppm); // virtual pin 
myNextion.setComponentText("t0", String(ppm));

You have put them inside the else statement (which it looks like is never triggered).

Move the 3rd last } of the function above these 2 lines and see what this gives you and I will see what bug you have that isn’t triggering the else statement.

THanks. I maked it and now:

[1817] Free RAM: 44736
[5001] Connecting to blynk-cloud.com:8442
[5028] <[02|00|01|00] 75a3e91cbdf1457c9498b35eea63e9c1
[5054] >[00|00|01|00]Č
[5054] Ready (ping: 1ms).
[5054] <[11|00|01|00]Hver[00]0.4.4[00]h-beat[00]10[00]buff-in[00]1024[00]dev[00]NodeMCU[00]build[00]Feb 12 2017 19:20:59[00]
[5328] >[00|00|01|00]Č
[15176] <[06|00|02|00|00]
[15218] <[14|00|03|00|07]vw[00]11[00]0
[15340] >[00|00|02|00]Č
[16639] >[14|00|01|00|02]
[16639] >pm
[16855] >[14|1E]b[00|05]
[16855] >vr[00]10
[16856] >[14|1E]b[00|04]
[16856] >vr[00]1
[16856] >[14|1E]b[00|04]
[16856] >vr[00]4
[16861] >[14|1E]b[00|05]
[16889] >vr[00]13
[16908] >[14|1E]b[00|04]
[16935] >vr[00]9
[16954] >[14|1E]b[00|05]
[16981] >vr[00]11
[17001] >[14|1E]b[00|04]
[17028] >vr[00]1
[17047] >[14|1E]b[00|04]
[17074] >vr[00]5
[17093] >[14|1E]b[00|04]
[17120] >vr[00]6
[18890] >[14|1E]b[00|05]
[18890] >vr[00]10
[18890] >[14|1E]b[00|04]
[18890] >vr[00]1
[18890] >[14|1E]b[00|04]
[18890] >vr[00]4
[18896] >[14|1E]b[00|05]
[18923] >vr[00]13
[18943] >[14|1E]b[00|04]
[18970] >vr[00]9
[18988] >[14|1E]b[00|05]
[19016] >vr[00]11
[19035] >[14|1E]b[00|04]
[19062] >vr[00]5
[19081] >[14|1E]b[00|04]
[19108] >vr[00]6
[19914] >[14|1E]b[00|05]
[19914] >vr[00]10
[19914] >[14|1E]b[00|04]
[19915] >vr[00]1
[19915] >[14|1E]b[00|04]
[19915] >vr[00]4
[19920] >[14|1E]b[00|05]
[19947] >vr[00]13
[19967] >[14|1E]b[00|04]
[19994] >vr[00]9
[20013] >[14|1E]b[00|05]
[20040] >vr[00]11
[20060] >[14|1E]b[00|04]
[20087] >vr[00]5
[20106] >[14|1E]b[00|04]
[20133] >vr[00]6
[21845] >[14|1E]b[00|05]
[21845] >vr[00]10
[21845] >[14|1E]b[00|04]
[21845] >vr[00]1
[21845] >[14|1E]b[00|04]
[21846] >vr[00]4
[21851] >[14|1E]b[00|05]
[21878] >vr[00]13
[21898] >[14|1E]b[00|04]
[21925] >vr[00]9
[21944] >[14|1E]b[00|05]
[21971] >vr[00]11
[21991] >[14|1E]b[00|04]
[22018] >vr[00]5
[22037] >[14|1E]b[00|04]
[22064] >vr[00]6
[23844] >[14|1E]b[00|05]
[23844] >vr[00]10
[23844] >[14|1E]b[00|04]
[23844] >vr[00]1
[23844] >[14|1E]b[00|04]
[23844] >vr[00]4
[23850] >[14|1E]b[00|05]
[23877] >vr[00]13
[23897] >[14|1E]b[00|04]
[23924] >vr[00]9
[23943] >[14|1E]b[00|05]
[23970] >vr[00]11
[23989] >[14|1E]b[00|04]
[24017] >vr[00]5
[24035] >[14|1E]b[00|04]
[24062] >vr[00]6
[25176] <[14|00|04|00|07]vw[00]11[00]0
[25844] >[14|1E]b[00|05]
[25845] >vr[00]10
[25845] >[14|1E]b[00|04]
[25845] >vr[00]1
[25845] >[14|1E]b[00|04]
[25845] >vr[00]4
[25851] >[14|1E]b[00|05]
[25878] >vr[00]13
[25897] >[14|1E]b[00|04]
[25925] >vr[00]9
[25943] >[14|1E]b[00|05]
[25970] >vr[00]11
[25990] >[14|1E]b[00|04]
[26017] >vr[00]5
[26036] >[14|1E]b[00|04]
[26063] >vr[00]6
[27851] >[14|1E]b[00|05]
[27851] >vr[00]10
[27851] >[14|1E]b[00|04]
[27851] >vr[00]1
[27852] >[14|1E]b[00|04]
[27852] >vr[00]4
[27857] >[14|1E]b[00|05]
[27884] >vr[00]13
[27904] >[14|1E]b[00|04]
[27931] >vr[00]9
[27950] >[14|1E]b[00|05]
[27977] >vr[00]11
[27997] >[14|1E]b[00|04]
[28024] >vr[00]5
[28043] >[14|1E]b[00|04]
[28070] >vr[00]6
[29846] >[14|1E]b[00|05]
[29846] >vr[00]10
[29846] >[14|1E]b[00|04]
[29846] >vr[00]1
[29846] >[14|1E]b[00|04]
[29846] >vr[00]4
[29852] >[14|1E]b[00|05]
[29879] >vr[00]13
[29899] >[14|1E]b[00|04]
[29926] >vr[00]9
[29945] >[14|1E]b[00|05]
[29972] >vr[00]11
[29992] >[14|1E]b[00|04]
[30019] >vr[00]5
[30037] >[14|1E]b[00|04]
[30065] >vr[00]6
[31856] >[14|1E]b[00|05]
[31856] >vr[00]10
[31856] >[14|1E]b[00|04]
[31856] >vr[00]1
[31856] >[14|1E]b[00|04]
[31857] >vr[00]4
[31862] >[14|1E]b[00|05]
[31889] >vr[00]13
[31909] >[14|1E]b[00|04]
[31936] >vr[00]9
[31955] >[14|1E]b[00|05]
[31982] >vr[00]11
[32002] >[14|1E]b[00|04]
[32029] >vr[00]5
[32048] >[14|1E]b[00|04]
[32075] >vr[00]6
[33848] >[14|1E]b[00|05]
[33848] >vr[00]10
[33848] >[14|1E]b[00|04]
[33848] >vr[00]1
[33848] >[14|1E]b[00|04]
[33849] >vr[00]4
[33854] >[14|1E]b[00|05]
[33881] >vr[00]13
[33901] >[14|1E]b[00|04]
[33928] >vr[00]9
[33947] >[14|1E]b[00|05]
[33974] >vr[00]11
[33994] >[14|1E]b[00|04]
[34021] >vr[00]5
[34040] >[14|1E]b[00|04]
[34067] >vr[00]6
[35176] <[14|00|05|00|07]vw[00]11[00]0

And in app blynk is 0…

Is your CO2 sensor connected to D1 i.e. GPIO 5?

Correction is it D5 GPIO 14?

#define pwmPin 2 //CO2  //D4
#define LedPin 13

i had same pins on nextion so now i connect to 2 D4…
but it is same…

Post the full sketch so I can check the pins.
Meanwhile you need to do likewise. Right them all down for all devices and ensure they are no duplicates etc.

#define BLYNK_DEBUG

#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>

#include <SoftwareSerial.h>
#include <Nextion.h>


SoftwareSerial HMISerial(12,14,false,256);//RX-D1 5 , TX-D2 6
Nextion myNextion(HMISerial, 9600);


// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "";  // Put your Auth Token here. (see Step 3 above)

SimpleTimer timer;

#define pwmPin 2 //CO2  //D4
#define LedPin 13
int prevVal = LOW;  //CO2
long th, tl, h, l, ppm;

void setup()
{
  Serial.begin(9600); // See the connection status in Serial Monitor
   Blynk.begin(auth, "", ""); //insert here your SSID and password
 
  // Setup a function to be called every second
  timer.setInterval(10000L, sendUptime);

  timer.setInterval(10000L, readCO2);
  myNextion.init();
}

void sendUptime()
{
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
   //Read the Temp and Humidity from DHT


  
}

void readCO2()
{
long tt = millis();
  int myVal = digitalRead(pwmPin);

  //Если обнаружили изменение
  if (myVal == HIGH) {
    digitalWrite(LedPin, HIGH);
    if (myVal != prevVal) {
      h = tt;
      tl = h - l;
      prevVal = myVal;
    }
  }  else {
    digitalWrite(LedPin, LOW);
    if (myVal != prevVal) {
      l = tt;
      th = l - h;
      prevVal = myVal;
      ppm = 5000 * (th - 2) / (th + tl - 4);
      Serial.println("PPM = " + String(ppm));

 

 }
 }
  Blynk.virtualWrite(11, ppm); // virtual pin 
  myNextion.setComponentText("t0", String(ppm));
}
void loop()
{
  Blynk.run();
  timer.run();
}