Temperature and Humidity Monitoring Using DHT11 Sensor
Last updated
Last updated
In this project, you will be directed to monitor temperature and humidity using a DHT11 sensor connected to a Raspberry Pi. Furthermore, the temperature and humidity data read by the DHT11 sensor will be sent to the Antares IoT Platform.
The materials required follow the General Prerequisites on the previous page. If you have not prepared the requirements on that page, then you can visit the following page.
Here are some of the equipment you will need for temperature and humidity monitoring using the DHT11 Sensor:
Raspberry Pi
Sensor DHT11
Resistor 10kΩ
Breadboard
Jumper cables (3 jumper male to female and 3 jumper male to male)
The 10kΩ resistor is needed as a pull-up resistor used to stabilise the communication between the DHT11 sensor and the Raspberry Pi. This resistor is needed when you work with DHT11 sensors that have 4 pins.
For temperature and humidity monitoring, you need to connect the DHT11 sensor with the Raspberry Pi. You need to create a circuit as in the following image.
Connect the DHT11 VCC pin to the Raspberry Pi's 3.3 V pin, the DHT11 GND pin to the Raspberry Pi GND pin, and the DHT11 data pin to the Raspberry Pi's GPIO 4. Finally, connect the end of the 10kΩ resistor to the DHT11 VCC pin and the other end to the DHT11 data pin.
Here is a pinout diagram of the Raspberry Pi and DHT11 sensor that can make it easier for you to build a circuit.
To switch on the Raspberry Pi, insert the SD card that has the OS installed in the slot available on the Raspberry Pi board. Then connect the Raspberry Pi to the monitor using a Micro HDMI to HDMI cable. Also connect the keyboard and mouse to the USB slot on the Raspberry Pi as shown below. Finally, connect the Raspberry Pi board to the power source using USB-C.
A powered-on Raspberry Pi will be signalled by an illuminated LED indicator near the USB-C port.
After the Raspberry Pi is connected to the power source, then you can turn on the monitor. Raspberry Pi that has booted and entered the OS is shown as in the image below.
If after switching on the monitor nothing appears on the screen, this means that the Raspberry Pi is booting the OS. You can wait a while until the GUI appears.
Next, you can open the terminal on the top left as shown in the following icon image.
The opened terminal will look like the following image.
After assembling the hardware and turning on the Raspberry Pi via the monitor, you can open the terminal and install the DHT11 library from Adafruit by cloning from Github. The following syntax must be typed into the terminal.
After the cloning process is complete, the Adafruit_Python_DHT folder will appear, which can be checked by typing "ls" in the terminal.
To install the DHT11 library, enter the Adafruit_Python_DHT folder by typing the following syntax.
Once inside the folder, you can check the files inside by typing "ls" in the terminal.
In the terminal output above there is a setup.py file. This file is used to install the DHT11 library.
Type the syntax below to perform the installation.
After inputting the syntax above, the terminal output will be as shown below. In this condition, you have successfully installed the DHT11 library.
After successfully installing the required libraries, you need to create a Python file to input the required programme code. You need to enter the examples directory by typing the following syntax.
Then you need to create a new Python file by typing the syntax below.
You need to change your-file-name to your preferred filename.
After that, the display on the terminal will change to the one shown below.
The display above shows an empty Python file ready to be input with programme code.
Here is the programme code that you need to input to the Python file that you created earlier.
Don't forget to enter the device URL in the antares_url section and the access-key in the x-m2m-origin section according to the Antares IoT Platform. Make sure there are no programme writing errors and pay attention to the indentation.
After successfully inputting the programme code, the display will be as shown below.
After you have successfully inputted the programme code, next you need to save the Python file by pressing Ctrl + X > Y > Enter.
After the Node.js Request file has been successfully saved. Next you can execute the file by typing the following syntax in the terminal.
Don't forget to change your-file-name according to the name created earlier.
After the Python file is executed, the display on the terminal will be as shown below.
The image above shows that the DHT11 sensor has been able to read the temperature and humidity data. The data has also been successfully sent to the Antares IoT Platform with the message "Data sent successfully".
To ensure that the temperature and humidity data has been sent to the Antares IoT Platform, you can open your device URL. The following image shows the display on the Antares IoT Platform that has received data from the Raspberry Pi.