How to Set Up the DHT11 Humidity Sensor on the Raspberry Pi
2 min read
6 months ago
Published on Apr 22, 2024
This response is partially generated with the help of AI. It may contain inaccuracies.
Table of Contents
Tutorial: Setting Up DHT11 Humidity Sensor on Raspberry Pi
Step 1: Gather Materials
- Raspberry Pi
- DHT11 digital humidity and temperature sensor
- Breadboards
- Jumper wires
- 10k potentiometers
- LCD display
Step 2: Connect DHT11 Sensor to Raspberry Pi
- Connect the negative pin of the DHT11 sensor to the ground pin (pin 6) of the Raspberry Pi.
- Connect the VCC pin of the DHT11 sensor to the 5V pin of the Raspberry Pi.
- Connect the data pin of the DHT11 sensor to pin 7 of the Raspberry Pi.
Step 3: Write and Compile C Program
- Write a C program to read temperature and humidity data from the sensor.
- Save the code in a file with a
.c
extension using thenano
text editor. - Compile the program using the provided command.
- Run the program using
sudo ./example
to display temperature and humidity readings in the terminal.
Step 4: Display Data on an LCD
- Connect the LCD display to the breadboard.
- Insert a 10k potentiometer for contrast and backlight brightness.
- Connect the pins of the LCD display to specific GPIO pins of the Raspberry Pi as described.
- Adjust potentiometers for contrast and backlight brightness.
- Compile and run a new code to display temperature and humidity readings on the LCD.
Step 5: Use Python for DHT11 Sensor
- Install the Adafruit DHT Python library using the provided commands.
- Download and install the library using
sudo python setup.py install
. - Write and run a Python program to output temperature and humidity values to an SSH monitor.
Step 6: Display Data on LCD using Python
- Install the RPLCD Python library using
sudo pip install RPLCD
. - Modify the Python example program to display temperature and humidity readings on the LCD.
- Run the program using
sudo python example.py
.
Step 7: Finalize and Test
- Make necessary adjustments to display data in Celsius if needed.
- Test the setup by running the programs and observing the temperature and humidity readings on the terminal and LCD display.
Congratulations! You have successfully set up the DHT11 humidity sensor on your Raspberry Pi and displayed the temperature and humidity readings using both C and Python programming languages.