Hii, all, I am new to this platform. I am working on a little project for which I want to connect 4 temperature sensors, 3 temperature and humidity sensors and 2 pressure sensors and possible also some airflow sensors to my arduino UNO. (I am trying to dry a organic material, and measure its water content based on the air that flows through it)
I am currently testing just the basics, so I am playing around with a DHT22 Temp. and humid. sensor and an LCD display. This works fine. I also tested an AHT sensor and printed the data onto the serial control and this also works fine. However, when I try to combine them I have some trouble. The LCD does not show the DHT data anymore.
I am quite new to coding so it is probably a beginner mistake, but I can't seem to find the solution because I don't get any errors.
Here is my code:
// include libraries
#include <LiquidCrystal.h> //LCD screen library
#include <DHT.h> //Temperature and Humidity sensor library
#include <Adafruit_AHTX0.h> //Adafruit library for the AHT21 sensor
#include <Wire.h> // library to work with Inter-Integrated Circuit (I2C) Protocol
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
LiquidCrystal lcd(0, 1, 8, 9, 10, 11);
Adafruit_AHTX0 aht;
// defining the pin for the DHT sensor
#define datapin 7 // Digital pin the DHT is connected to
#define DHTTYPE DHT22
DHT dht(datapin, DHTTYPE);
// make custom temperature character
byte customChar[] = {
B01110,
B01010,
B01110,
B00000,
B00000,
B00000,
B00000,
B00000
};
void setup() {
// setup the DHT to start measuring
dht.begin();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.createChar(0, customChar);
Serial.begin(115200);
if (!aht.begin()) {
Serial.println("Could not find AHT? Check wiring");
while (1) delay(10);
}
}
void loop() {
//measure temp and humidity with IC2
sensors_event_t humidityA, tempA;
aht.getEvent(&humidityA, &tempA); //populate temp and humidity objects with fresh data
Serial.println(String("T.a:") + String(tempA.temperature));
Serial.println(String("RH.a:") + String(humidityA.relative_humidity));
// measure temperature and humidity with DHT
float tempD = dht.readTemperature();
float humidityD = dht.readHumidity();
// print the output on LCD screen
lcd.setCursor(0, 0); //setting for first lcd row
// Print a message to the LCD.
lcd.print(String("T.d:") + String(tempD) + String(" C"));
lcd.write(byte(0)); // write special character behind C
// setting second lcd row
lcd.setCursor(0, 1);
lcd.print(String("RH.a:") + String(humidityD) + String("%"));
delay(2000);
}
If you are using pins 0 and 1 because there are no other pins left,
you have 2 alternatives for the LCD.
Or use an LCD_I2C module,
or use the analog pins (From A0 to A5) pins 14 to 19,
like digital pins.
The LCD is connected to pin 0 and 1 and 8,9,10 and 11. digital
The DHT22 is connected to 7 digital
And the AHT21 is connected to SDA and SCL right now. But my plan is to change this to a I2C module. I ordered it so it's on its way.
mmm weird.
I have changed the pins from the LCD, rs and E from 0 and 1 to 12 and 13 digital pins.
The LCD now shows the data from the DHT22, however now the data from the AHT21 sensor are not printed in the serial monitor anymore..
Any ideas?
Maybe its the wiring maybe?
again here is my code to be sure:
// include libraries
#include <LiquidCrystal.h> //LCD screen library
#include <DHT.h> //Temperature and Humidity sensor library
#include <Adafruit_AHTX0.h> //Adafruit library for the AHT21 sensor
#include <Wire.h> // library to work with Inter-Integrated Circuit (I2C) Protocol
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
LiquidCrystal lcd(12, 13, 8, 9, 10, 11); // parameters (rs, e, d4,d5,d6,d7)
Adafruit_AHTX0 aht;
// defining the pin for the DHT sensor
#define datapin 7 // Digital pin the DHT is connected to
#define DHTTYPE DHT22
DHT dht(datapin, DHTTYPE);
// make custom temperature character
byte customChar[] = {
B01110,
B01010,
B01110,
B00000,
B00000,
B00000,
B00000,
B00000
};
void setup() {
// setup the DHT to start measuring
dht.begin();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.createChar(0, customChar);
Serial.begin(115200);
if (!aht.begin()) {
Serial.println("Could not find AHT? Check wiring");
while (1) delay(10);
}
}
void loop() {
//measure temp and humidity with IC2
// sensors_event_t humidityA, tempA;
//aht.getEvent(&humidityA, &tempA); //populate temp and humidity objects with fresh data
//Serial.println(String("T.a:") + String(tempA.temperature));
//Serial.println(String("RH.a:") + String(humidityA.relative_humidity));
// measure temperature and humidity with DHT
float tempD = dht.readTemperature();
float humidityD = dht.readHumidity();
// print the output on LCD screen
lcd.setCursor(0, 0); //setting for first lcd row
// Print a message to the LCD.
lcd.print(String("T.d:") + String(tempD) + String(" C"));
lcd.write(byte(0)); // write special character behind C
// setting second lcd row
lcd.setCursor(0, 1);
lcd.print(String("RH.a:") + String(humidityD) + String("%"));
delay(2000);
}
// include libraries
#include <LiquidCrystal.h> //LCD screen library
#include <DHT.h> //Temperature and Humidity sensor library
#include <Adafruit_AHTX0.h> //Adafruit library for the AHT21 sensor
#include <Wire.h> // library to work with Inter-Integrated Circuit (I2C) Protocol
// initialize the library by associating any needed LCD interface pin
// with the arduino pin number it is connected to
LiquidCrystal lcd(12, 13, 8, 9, 10, 11); // parameters (rs, e, d4,d5,d6,d7)
Adafruit_AHTX0 aht;
// defining the pin for the DHT sensor
#define datapin 7 // Digital pin the DHT is connected to
#define DHTTYPE DHT22
DHT dht(datapin, DHTTYPE);
// make custom temperature character
byte customChar[] = {
B01110,
B01010,
B01110,
B00000,
B00000,
B00000,
B00000,
B00000
};
void setup() {
// setup the DHT to start measuring
dht.begin();
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
lcd.createChar(0, customChar);
Serial.begin(115200);
if (!aht.begin()) {
Serial.println("Could not find AHT? Check wiring");
while (1) delay(10);
}
}
void loop() {
//measure temp and humidity with IC2
sensors_event_t humidityA, tempA;
aht.getEvent(&humidityA, &tempA); //populate temp and humidity objects with fresh data
Serial.println(String("T.a:") + String(tempA.temperature));
Serial.println(String("RH.a:") + String(humidityA.relative_humidity));
// measure temperature and humidity with DHT
float tempD = dht.readTemperature();
float humidityD = dht.readHumidity();
// print the output on LCD screen
lcd.setCursor(0, 0); //setting for first lcd row
// Print a message to the LCD.
lcd.print(String("T.d:") + String(tempD) + String(" C"));
lcd.write(byte(0)); // write special character behind C
// setting second lcd row
lcd.setCursor(0, 1);
lcd.print(String("RH.a:") + String(humidityD) + String("%"));
delay(2000);
}
As an exercise you could consider only printing the text once in setup() and only printing one or both of the values if they change. It would be good practice for you
Thanks that does sound like a good exercise, however I am also planning to create a plot/ graph about the changes in time. So then I would need to collect data also when it does not change but stay constant! So I think I will first watch some IOT and arduino cloud tutorials.