I have an ESP32 with an 1602 LCD with backpack (i2c). I alsp have connected an DHT22 temperature and humidity sensor, one relay (Relay is not connected yet), an LDR sensor and å led diode.
All contacts are soldered on to a PCB and all worked fine the same day i tested. LCD shows the temperature and humidity and turns on an off when light in the room changes.
My only issue is that LCD suddenly wan't show the humidity and temperature and shows strange characters and just squares. That happens specially if i disconnect the power and connect it again.
LCD worked fine for 5 hours ago when i turned the computer on and connected LCD, but suddenly it starts to show strange character and squares.
When i try to install an simple "hello world" scetch i get it to work after one push on the reset button after installing, så i suspect it is something in the code taht i can have missed?
EDIT:
One little thing i forgot to mention:
When LCD works and shows humidity and temperature i can see it turns on an off when i load the code. When i see the strange characters and squares on the display nothing happend when i load the code. The display stays on an does not react to anyting.
Her is my code:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>;
int lcdColumns = 16;
int lcdRows = 2;
LiquidCrystal_I2C lcd(0x27, lcdColumns, lcdRows);
#define DHTPIN 19 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
int chk;
float hum; //Stores humidity value
float temp; //Stores temperature value
#define BLYNK_PRINT Serial
#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>
int sensorPin = 34;
int sensorValue = 0;
int relay = 23;
int powerLed = 5;
char auth[] = "****";
char ssid[] = "*****";
char pass[] = "'*****";
void setup()
{
// Debug console
Blynk.begin(auth, ssid, pass);
Serial.begin(9600);
// some code that activates and the same time turns LCD in to "sleep mode"
lcd.init();
dht.begin();
pinMode(powerLed, OUTPUT);
pinMode(relay, OUTPUT);
pinMode(sensorPin, INPUT);
digitalWrite(relay, HIGH);
digitalWrite(powerLed, HIGH);
}
void loop() {
// Some code that enables Blynk
Blynk.run();
// some code for writing temperature and humidity values to serial monitor
hum = dht.readHumidity();
temp = dht.readTemperature();
Serial.print("Fuktighet: ");
Serial.print(hum);
Serial.print(" %, Temperatur: ");
Serial.print(temp);
Serial.println(" Celsius");
// code for showing temperature values on LCD display
lcd.setCursor(0, 0);
lcd.print("Temp: ");
lcd.print(temp);
// code for showing the celcius symbol on LCD display
lcd.write(0b11011111);
lcd.setCursor(12, 0);
lcd.print("C");
// code for showing humidity values on LCD display
lcd.setCursor(1, 1);
lcd.print("Hum: ");
lcd.print(hum);
lcd.print("%");
// some code that makes the value "sensorValue"
sensorValue = analogRead(sensorPin); // read the value from the sensor
Serial.println(sensorValue); //prints the values coming from the sensor on the
// some statements that turns on and off the LCD display regards to light in the room
if (sensorValue > 100) {
lcd.noDisplay();
lcd.noBacklight();
digitalWrite(powerLed, LOW);
}
if(sensorValue < 100) {
lcd.display();
lcd.backlight();
digitalWrite(powerLed, HIGH);
}
// some code that sends virtual data to the Blynk app
Blynk.virtualWrite(V5, temp);
Blynk.virtualWrite(V6, hum);
// Some delay for not blowing the Blynk server up
delay(3000);
}