How to Set Up the DHT11 Humidity Sensor on the Raspberry Pi

2 min read 4 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

  1. Raspberry Pi
  2. DHT11 digital humidity and temperature sensor
  3. Breadboards
  4. Jumper wires
  5. 10k potentiometers
  6. LCD display

Step 2: Connect DHT11 Sensor to Raspberry Pi

  1. Connect the negative pin of the DHT11 sensor to the ground pin (pin 6) of the Raspberry Pi.
  2. Connect the VCC pin of the DHT11 sensor to the 5V pin of the Raspberry Pi.
  3. Connect the data pin of the DHT11 sensor to pin 7 of the Raspberry Pi.

Step 3: Write and Compile C Program

  1. Write a C program to read temperature and humidity data from the sensor.
  2. Save the code in a file with a .c extension using the nano text editor.
  3. Compile the program using the provided command.
  4. Run the program using sudo ./example to display temperature and humidity readings in the terminal.

Step 4: Display Data on an LCD

  1. Connect the LCD display to the breadboard.
  2. Insert a 10k potentiometer for contrast and backlight brightness.
  3. Connect the pins of the LCD display to specific GPIO pins of the Raspberry Pi as described.
  4. Adjust potentiometers for contrast and backlight brightness.
  5. Compile and run a new code to display temperature and humidity readings on the LCD.

Step 5: Use Python for DHT11 Sensor

  1. Install the Adafruit DHT Python library using the provided commands.
  2. Download and install the library using sudo python setup.py install.
  3. Write and run a Python program to output temperature and humidity values to an SSH monitor.

Step 6: Display Data on LCD using Python

  1. Install the RPLCD Python library using sudo pip install RPLCD.
  2. Modify the Python example program to display temperature and humidity readings on the LCD.
  3. Run the program using sudo python example.py.

Step 7: Finalize and Test

  1. Make necessary adjustments to display data in Celsius if needed.
  2. 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.