Displaying DHT Sensor Values on LCD
In this step, we will combine the previous functionalities of reading temperature and humidity from the DHT sensor and displaying messages on the LCD. The DHT sensor readings will be shown on the LCD screen, providing real-time information about the environmental conditions.
Pinout and Connections:
Ensure that you have followed the previous instructions to connect the LCD display and the DHT to the Arduino correctly.
Code:
Open a new file on the Arduino IDE, copy this code and paste it in the new file.
Code Explanation:
The code starts by including the necessary libraries:
Wire.h
for I2C communication,LiquidCrystal_I2C.h
for controlling the LCD, andDHT.h
for interacting with the DHT sensor.The LCD module's address, number of columns, and number of rows are declared.
An LCD object,
lcd
, and a DHT object,dht
, are created using the respective addresses and pins.In the
setup()
function, the LCD is initialized usinglcd.begin()
, and the welcome messages are printed on the LCD.The DHT sensor is started with
dht.begin()
.Within the
loop()
function, temperature and humidity values are read from the DHT sensor usingdht.readTemperature()
anddht.readHumidity()
respectively.The LCD display is cleared using
lcd.clear()
to remove any previous content.The temperature and humidity values are displayed on the LCD using
lcd.setCursor()
to set the cursor position andlcd.print()
to display the text and values.A delay of 2 seconds (2000 milliseconds) is added before the next reading.
Explanation of Technology:
By combining the functionality of reading temperature and humidity values from the DHT sensor and displaying messages on the LCD, we can create a more comprehensive user interface. The LCD provides a visual representation of the environmental conditions, allowing users to easily monitor the temperature and humidity levels in real-time.
In the code, the LCD is initialized and the welcome messages are displayed at the beginning. Then, within the main loop, the temperature and humidity readings are obtained from the DHT sensor. The LCD display is cleared, and the temperature and humidity values are printed on the LCD screen.
This integration of the DHT sensor and LCD display enhances the user experience by providing an intuitive and informative interface for monitoring the smart garden system.
Last updated