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);
}
3 posts - 3 participants