1

Hi everyone I am beginning learn coding and the second language English. I have small project I use Arduino uno , esp8266 , dht11 , lcd I2C and use blynk app in my project I have the code and work probably when WiFi ON but I have question How I can get the information data from dht to lcd without open the WiFi. Now I get information ( Temp and humidity ) on LCD when WiFi ON only. How I can make Temp and humidity display on LCD with and without WiFi.

#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F, 20, 4);
char auth[] = "*******************************";
char ssid[] = "***********";
char pass[] = "*********";
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(2, 3); // TX, RX
#define ESP8266_BAUD 9600
ESP8266 wifi(&EspSerial);
#define DHTPIN 8
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);

void setup()
{
  Serial.begin(9600);
  lcd.init();
  lcd.backlight();
  EspSerial.begin(ESP8266_BAUD);
  Blynk.begin(auth, wifi, ssid, pass);
  dht.begin();
}

void loop()
{
  LCD();
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  Blynk.virtualWrite(V1, t);
  Blynk.virtualWrite(V2, h);
}
void LCD()
{
  int h = dht.readHumidity();
  int t = dht.readTemperature();
  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print(" ******************");
  lcd.setCursor(3, 1);
  lcd.print("TEMP: ");
  lcd.print(t);
  lcd.setCursor(3, 2);
  lcd.print("HUM : ");
  lcd.print(h);
}
AbuWeSaM
  • 11
  • 2
  • 1
    you just read the tenperarure and humidity and then display the values on the lcd ... why would you need wifi? – jsotola Jul 18 '20 at 12:28
  • because use as IOT by Blynk – AbuWeSaM Jul 18 '20 at 12:43
  • So take the code that writes to the lcd out of the function that is called by your timer and simply call it from loop. Use the blink without delay style of timing with millis to make it happen at one second intervals. There are thousands of tutorials on how to handle timing on Arduino without blynk. – Delta_G Jul 18 '20 at 13:44
  • Thanks dear,,, You can help me more for this because I don't have idea – AbuWeSaM Jul 18 '20 at 15:30
  • Start with a simple example that just prints the values from the DHT11 and work your way up from there. The code you included does some very strange and unnecessary things and I do not recommend you re-use it. Where did this code come from? – StarCat Jul 18 '20 at 20:39
  • Thanks I try to make the code easy but still the same problem to display on LCD without WiFi On – AbuWeSaM Jul 19 '20 at 17:33
  • I´m working with a nano v3 (clone) and a esp-01 as wifi shield to send data from sensors like dht11, a DS18B20 and a light sensor based on ldr from an hidroponic system and controls a water pump and 1 water heater with a 2 relay module. I use Blynk app to read this data because I don't want to go see an lcd outside the house. So my sketch do somethings similar to yours and others not, obviously. But I´ve got the same problem. I´ll like to run my sketch without need to be connected to blynk like in case I´ve lost connection for some how. I noticed that in your sketch there are some things that – Cristian Sep 12 '20 at 04:04

1 Answers1

1

Blynk.connected() returns true when hardware is connected to Blynk Server, so you can guard Blynk code with

if( Blynk.connected() ){
  // do Blynk things here
}

// Update the LCD anywhere outside of the above "if" statement.
JRobert
  • 14,769
  • 3
  • 20
  • 49