Hello everyone, We badly need our help. How to display temperature and humidity readings to LCD I2C display? The first DHT22 is ok but the second DHT22 only reads 3 on temperature and humidity. Here's my code thank you!
#include <DHT.h>
#include <Wire.h>
#include <hd44780.h>
#include <hd44780ioClass/hd44780_I2Cexp.h>
#define DHTPin1 4
#define DHTPin2 7
#define DHTTYPE1 DHT22
#define DHTTYPE2 DHT22
hd44780_I2Cexp lcd;
DHT dht1(DHTPin1, DHTTYPE1);
DHT dht2(DHTPin2, DHTTYPE2);
const int LCD_COLS = 16;
const int LCD_ROWS = 4;
// Define variables
float hum = 0.0;
float hum2 = 0.0;
float temp = 0.0;
float temp2 = 0.0;
void setup()
{
Serial.begin(9600);
dht1.begin();
dht2.begin();
lcd.begin(LCD_COLS, LCD_ROWS);
}
void loop()
{
delay(4000);
hum = dht1.readHumidity(); //
Serial.print(dht2.readHumidity());
temp = dht1.readTemperature();
Serial.print(dht2.readTemperature());
lcd.setCursor(0, 0);
lcd.print("Temp1:");
lcd.print(temp);
lcd.print("C");
lcd.setCursor(0, 1);
lcd.print("Temp2:");
lcd.print(Serial.print(dht2.readTemperature()));
lcd.print("C");
delay(4000);
lcd.setCursor(4, 2);
lcd.print("Humi1:");
lcd.print(hum);
lcd.print("%");
lcd.setCursor(4, 3);
lcd.print("Humi2:");
lcd.print(Serial.print(dht2.readHumidity()));
lcd.print("%");
}
What happens when you swap the sensors?
Why all the global variables?
Please remember to use code tags when posting code.
dave30:
We badly need our help.
Hmmm
dave30
June 2, 2021, 10:01am
4
Sorry im new to this forum please bear with me
dave30
June 2, 2021, 10:02am
5
I swapped sensors and tried swapping pins still the same results
I suggest you ditch the LCD and concentrate on just using Serial prints to debug the sensors.
@dave30 , your topic has been moved to a more suitable location on the forum.
Can you please read How to get the best out of this forum (again?) and apply the code tags as described.
1 Like
lcd.print(Serial.print(dht2.readHumidity()));
Oops.
Second time I've seen this one today!
(Must've been asleep earlier,sorry)
Hi,
To add code please click this link;
Hello,
Welcome to the Arduino Forum.
This guide explains how to get the best out of this forum. Please read and follow the instructions below.
Being new here you might think this is having rules for the sake of rules, but that is not the case. If you don’t follow the guidelines all that happens is there is a long exchange of posts while we try to get you to tell us what we need in order to help you, which is frustrating for you and frustrating for us.
The people who try to help with your pro…
Can I suggest you read ALL your sensor values at the start of the loop and store them as variables.
Then use those variables in the rest of your code.
In other words take a snapshot of your inputs and use those.
This will save all the
dht2.readTemperature()
etc all over your code.
for example;
hum1 =
temp1 =
hum2 =
temp2=
Thanks.. Tom...
dave30
June 2, 2021, 12:39pm
10
I will if I ever use this forum again. Thanks for correcting
dave30
June 3, 2021, 12:51pm
12
Update: Both 2 sensors are working! It just lacks power because I used 5V supply. Thanks for your help guys.
system
Closed
October 1, 2021, 12:51pm
13
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.