Hello! This is my first project and I have no idea what's wrong. The code is verified and uploaded correctly. But after uploading, nothing changed on the LDC. Here is my code and how everything is set up Can anyone please help a newbie? Thank you!
.
#include <DHT.h>
#include <LiquidCrystal_I2C.h>
DHT dht (2, DHT11) ;
int temp;
int humidity;
int dt = 2000;
LiquidCrystal_I2C ldc(0x27, 16, 2);
void setup() {
// put your setup code here, to run once:
dht.begin();
ldc.init();
ldc.backlight();
}
void loop() {
// put your main code here, to run repeatedly:
delay(dt);
temp = dht.readTemperature(true);
humidity = dht.readHumidity();
ldc.setCursor(0, 0);
ldc.print("Temp: ");
ldc.print(temp);
ldc.print(" F");
ldc.setCursor(0, 1);
ldc.print("Humidity: ");
ldc.print(humidity);
ldc.print(" %");
}
I don't like the choice of wire colours that you have used.
You have got red wires for GND connections, better to use black there.
Have you tried adjusting the contrast potentiometer?
Add serial prints to your code so you can see on serial monitor what is happening.
Do the individual components work correctly? Run some of the example sketches for the LCD and the DHT11.
Your code is for a LCD with an I2C backpack.
However your wiring looks like it is for a conventional non I2C LCD.
What type of LCD do you have?
Can you give us a link to the LCD or it's datasheet?
In support of my theory that you are using the wrong code for the LCD that you have, here is a photograph of the rear of a typical I2C LCD module:

Note that:
-
The backpack being soldered on to the LCD module pins prevents the LCD module fitting on to a breadboard.
-
Only 4 connections are required Vcc, GND, SCL, and SDA.
-
The connections generally go towards the side.
-
There is a contrast potentiometer built in to the back pack.
I'm totally using the wrong code. I followed someone's wiring diagram for the LCD display I have and used another guy's code. I didn't realize the LCDs were different. Time to rewrite everything. Thank you all for the help!
Here's where I'm at now. I have the code but the temp and humidity both read "nan". Any ideas?
#include "DHT.h"
#define Type DHT11
#include <LiquidCrystal.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int sensePin=2;
DHT HT(sensePin,Type);
float humidity;
float tempC;
float tempF;
int setTime=500;
int dt=1000;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
HT.begin();
delay(setTime);
lcd.begin(16,2);
}
void loop() {
humidity=HT.readHumidity();
tempC=HT.readTemperature();
tempF=HT.readTemperature(true);
lcd.setCursor(0,0);
lcd.print("Temp F= ");
lcd.print(tempF);
lcd.setCursor(0,1);
lcd.print("Humidity= ");
lcd.print(humidity);
lcd.print(" %");
delay(500);
lcd.clear();
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.print("% Temperature ");
Serial.print(tempC);
Serial.print(" C ");
Serial.print(tempF);
Serial.println(" F ");
}
GOT IT WORKING!!! Thank you for your help!!!