Antares
Antares
en
en
  • Getting Started
    • Account Registration
    • Create App
    • Add Devices to the Application
    • Installation Board and Library
      • ESP8266
      • ESP32
      • STM32
    • Arduino IDE Installation
    • Arduino Library Installation
      • Antares LoRaWAN
      • Antares Wi-Fi HTTP
      • Antares Wi-Fi MQTT
      • DHT11 Sensor Library
      • Adafruit SSD1306
    • STM32 Cube IDE Installation
    • Expansion Pack I-CUBE-LRWAN Installation
    • Software Installation
      • MQTTX Installation
      • Postman Installation
      • Operating System (OS) on SD Card Installation
    • Quickstart
  • Antares Insight Hub
    • Getting Started
      • Request Demo
      • Request Free Trial
    • Usecase
      • Power Meter
        • Power Meter Usecase Prerequisites
        • Power Meter Device Recommendation
        • Payload Example Power Meter
        • Setup Device Threshold Power Meter
      • Water Meter
        • Water Meter Usecase Prerequisites
        • Water Meter Device Recommendation
        • Payload Example Water Meter
        • Setup Device Threshold Water Meter
      • Water Level
        • Water Level Usecase Prerequisites
        • Water Level Device Recommendation
        • Payload Example Water Level
        • Setup Device Threshold Water Level
      • Environment Monitoring
        • Prerequisites for Use of Environmental Monitoring
        • Environment Monitoring Device Recommendation
        • Payload Example Environment Monitoring
        • Setup Device Threshold Environment Monitoring
    • Settings
      • Manage Alert Recipient (Telegram)
      • Manage User
      • Roles
  • Subscription and Payment
    • Platform
      • How to Use Platform Packages
      • How to Purchase a Platform Subscription
        • Payment Using Antares Coins
        • Payment Using Virtual Account
          • Mandiri Bank
          • Permata Bank
          • BRI Bank
          • BNI Bank
        • Payment Using e-Wallet (LinkAja)
        • Payment Using Credit Cards (CC)
      • Procedure for Renewing a Platform Subscription
      • Procedure for Changing Platform Subscription
    • Connectivity
      • How to Use Connectivity Packages
      • How to Purchase a Connectivity Subscription
        • Payment Using Antares Coins
        • Payment Using Virtual Account
          • Mandiri Bank
          • Permata Bank
          • BRI Bank
          • BNI Bank
        • Payment Using e-Wallet (LinkAja)
        • Payment Using Credit Cards (CC)
      • Procedure for Renewing a Platform Subscription
      • Procedure for Changing Connectivity Subscription
    • Antares Coins
      • Antares Coins Top Up Payment Procedures
        • Payment Using Virtual Account
          • Mandiri Bank
          • Permata Bank
          • BRI Bank
          • BNI Bank
        • Payment Using e-Wallet (LinkAja)
        • Payment Using Credit Cards (CC)
  • Code and library examples
    • ESP8266 (Wi-Fi)
      • General Prerequisites ESP8266 Wi-Fi
      • ESP8266 (Wi-Fi) HTTP Protocol
        • Sending Simple Data to Antares with HTTP Protocol
        • Retrieve the Last Data from Antares Server with HTTP Protocol
        • Simple Project ESP8266 HTTP Antares
          • Periodic Post DHT 11 Data
          • Post DHT 11 Data with Push Button
          • Post DHT 11 data and Display on OLED
          • Get Data displayed on OLED
          • Post and Get DHT 11 Data displayed on OLED
          • Controlling Relays and LEDs Through Get Commands
      • ESP8266 (Wi-Fi) MQTT Protocol
        • Sending Simple Data to Antares with the MQTT Protocol
        • Retrieve Last Data from Antares Server with MQTT Protocol
        • Simple Project ESP8266 MQTT Antares
          • Periodic Send DHT 11 Data
          • Send DHT 11 Data with Push Button
          • Send DHT 11 data and display on OLED display
          • Retrieve Data displayed on OLED Display
          • DHT 11 Send Data and Retrieve Data displayed on OLED Display
          • Controlling Relays and LEDs Through Get Commands
    • Arduino Uno
      • Arduino IDE Installation
      • Antares Ethernet Shield Library Installation
      • Configuration
      • Send Simple Data to Antares
    • ESP32 (Wi-Fi)
      • General Prerequisites ESP32 Wi-Fi
      • ESP32 (Wi-Fi) HTTP Protocol
        • Sending Simple Data to Antares with HTTP Protocol
        • Retrieve the Last Data from Antares Server with HTTP Protocol
        • Simple Project Lynx-32 HTTP Antares
          • Periodic Post DHT 11 Data
          • Post DHT 11 Data with Push Button
          • Post DHT 11 Data and Display on OLED
          • Get Data displayed on OLED
          • Post and Get DHT 11 Data displayed on OLED
          • Controlling Relays and LEDs Through Get Commands
      • ESP32 (Wi-Fi) MQTT Protocol
        • Sending Simple Data to Antares with the MQTT Protocol
        • Retrieve Last Data from Antares Server with MQTT Protocol
        • Simple Project Lynx-32 MQTT Antares
          • Periodic Send DHT 11 Data
          • Send Data DHT 11 dengan Push Button
          • Send DHT 11 Data and Display on OLED
          • Retrieve Data displayed on OLED Display
          • DHT 11 Send Data and Retrieve Data displayed on OLED
          • Controlling Relays and LEDs Through Retrieve Commands
      • HTTP & MQTT Protocol
    • ESP32 (LoRa)
      • General Prerequisites ESP32 LoRa
      • Sending Simple Data to Antares
      • Project Simple Lynx-32 LoRa Antares
        • Uplink DHT11 Data Periodically
        • Uplink Data DHT11 dengan Push Button
        • Uplink DHT11 Data and Display on OLED Display
        • Downlink Data Displayed on OLED
        • DHT 11 Uplink Data and Downlink Data displayed on OLED
        • Controlling Relay and LED via Downlink Command
      • LoRaWAN Class
    • STM32 (LoRa) STM32Cube IDE
      • General Prerequisites STM32 (LoRa) STM32Cube IDE
      • Sending Simple Data to Antares
    • STM32 (LoRa) Arduino IDE
      • General Prerequisites STM32 (LoRa) Arduino IDE
      • Sending Simple Data to Antares
    • Raspberry Pi
      • GUI (Graphical User Interface)
        • Raspberry GUI General Prerequisites
        • Sending Data Using Node.js
        • Temperature and Humidity Monitoring Using DHT11 Sensor
      • SSH (Secure Shell)
        • Common Raspberry SSH Prerequisites
        • Sending Data Using Node.js
        • Temperature and Humidity Monitoring Using DHT11 Sensor
    • NB-IoT
      • NB-Lynx-7000
        • General Prerequisites NB-Lynx-7000
        • Sending Simple Data to Antares
        • Retrieving GNSS (Global Navigation Satellite System) Data
      • NB-Lynx-95
        • General Prerequisites NB-Lynx-95
        • Sending Simple Data to Antares
    • Android
      • Retrieve data from ANTARES using Android
      • Coding Stuff
    • MIT App Inventor
    • Node-RED
    • Postman
    • MQTT | Push data to Device
    • HTTP | Subscribe and Notify Mechanism
    • PHP Library
    • MQTT | Subscribe LoRa Device
    • LoRaWAN | Downlink Tutorial
    • LoRaWAN Device Register
      • Register Menu
    • GPS TrackerID
  • Data Model
  • Port Configuration
  • API | HTTP
    • Device
    • Data of Device
    • Subscriber
  • API | MQTT
    • Device
    • Subscriber
  • List of Acronyms
  • Relevant Software
Powered by GitBook
On this page
  • Prerequisites
  • Follow These Steps
  • 1. Menyiapkan Peralatan
  • 2. Assembling Hardware
  • 3. Switching on the Raspberry Pi
  • 4. Switching on the Monitor and Opening the Terminal
  • 5. Install Adafruit DHT11 Library
  • 6. Creating a Python File
  • 7. Inputting programme code
  • 8. Executing Python Files
  • 9. Check Data on Antares IoT Platform
  1. Code and library examples
  2. Raspberry Pi
  3. GUI (Graphical User Interface)

Temperature and Humidity Monitoring Using DHT11 Sensor

PreviousSending Data Using Node.jsNextSSH (Secure Shell)

Last updated 8 months ago

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.

Prerequisites

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.

Follow These Steps

1. Menyiapkan Peralatan

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.

2. Assembling Hardware

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.

3. Switching on the Raspberry Pi

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.

4. Switching on the Monitor and Opening the Terminal

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.

5. Install Adafruit DHT11 Library

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.

git clone https://github.com/adafruit/Adafruit_Python_DHT.git

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.

cd Adafruit_Python_DHT

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.

sudo python setup.py install

After inputting the syntax above, the terminal output will be as shown below. In this condition, you have successfully installed the DHT11 library.

6. Creating a Python File

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.

cd examples

Then you need to create a new Python file by typing the syntax below.

sudo nano your-file-name.py

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.

7. Inputting programme code

Here is the programme code that you need to input to the Python file that you created earlier.

import Adafruit_DHT
import time
import datetime
import requests

# Set DHT11 sensor type
sensor = Adafruit_DHT.DHT11

# Set GPIO pin where DHT11 sensor is connected
pin = 4

# Set Antares URL and headers
antares_url = 'masukkan URL'
headers = {
    'cache-control': 'no-cache',
    'content-type': 'application/json;ty=4',
    'x-m2m-origin': 'masukkan access-key'
}

while True:
    # Read data from DHT11 sensor
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)

    if humidity is not None and temperature is not None:
        print("Last valid input: " + str(datetime.datetime.now()))
        print("Temperature: %d C" % temperature)
        print("Humidity: %d %%" % humidity)

        # Create the data payload
        data = {
            "m2m:cin": {
                "con": "{\"Temperature\":%d,\"Humidity\":%d}" % (temperature, humidity)
            }
        }

        # Send the data to Antares
        try:
            response = requests.post(antares_url, headers=headers, json=data)
            response.raise_for_status()  # Check if the request was successful
            print('Data sent successfully.')
        except requests.exceptions.RequestException as e:
            print('Failed to send data:', e)

    else:
        print('Failed to get reading. Try again!')

    # Wait for 2 seconds before the next reading
    time.sleep(2)

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.

8. Executing Python Files

After the Node.js Request file has been successfully saved. Next you can execute the file by typing the following syntax in the terminal.

python your-file-name.py

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".

9. Check Data on Antares IoT Platform

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.

Raspberry GUI General Prerequisites
Equipment Required for Temperature and Humidity Monitoring
DHT11 to Raspberry Pi circuit
Pinout Raspberry Pi
Pinout Sensor DHT11
Connecting Raspberry Pi with Power Source and Monitor
GUI Raspberrry Pi
Terminal Icon Marked with Red Box
Terminal View on GUI
Adafruit_Python_DHT folder that appears after the cloning process
Enter the Adafruit_Python_DHT Folder and Display the Folder Contents
Library DHT11 Installation
Enter the Examples Directory
Empty Python file for writing programme code
Program Code that has been Inputted to Python File
Terminal Output when Python FIle is Executed
Display on Antares IoT Platform that has Received Data from Raspberry Pi