I have a small problem with my weather station project. I use arduino mega 2650, dht22 sensor and i2c lcd 2x16. I see humidity and temperature on screen, but backlight not working. Please help, i'm a beginner.
Code:
#include <LiquidCrystal_PCF8574.h>
//DHT11 Sensor:
#include "DHT.h"
#define DHTPIN 2 // what digital pin we're connected to
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE);
//I2C LCD:
#include <Wire.h> // Comes with Arduino IDE
// Set the LCD I2C address
LiquidCrystal_PCF8574 lcd(0x3f);
#define Rs_pin 0
#define Rw_pin 1
#define En_pin 2
#define BACKLIGHT_PIN 3
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
void setup() {
Serial.begin(9600);
lcd.begin(16,2);
Serial.println("Mohamed Chaara Temp and Humidity Sensor Test");
dht.begin();
}
void loop() {
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
int h = dht.readHumidity();
int t = dht.readTemperature();
// set the cursor to (0,0):
lcd.setCursor(0, 0);
// print from 0 to 9:
lcd.print("Temp: ");
lcd.print(t);
lcd.print("C");
// set the cursor to (16,1):
lcd.setCursor(0,1);
lcd.print("Humidity: ");
lcd.print(h);
lcd.print("%");
Serial.print("Temp: ");
Serial.print(t);
Serial.print("C, Humidity: ");
Serial.print(h);
Serial.println("%");
}