Temperature Sensor Tutorial for DHT11, DHT22, AM2302, RHT03
In this section we’ll walk through creating a Temperature Sensor using ESP32, ESP8266 and then view the temperature via Alexa, Google Home or SmartThings.
Prerequisites :
- ESP32, ESP8266 x 1.
- DHT11 or DHT22, AM2302, RHT03 x 1.
- Jumper Wires.
Quick introduction to Temperature Sensor
The DHT and AM series are low-cost digital sensor for sensing temperature and humidity. It uses a capacitive humidity sensor and a thermistor to measure the surrounding air and then spits out a digital signal on the data pin.
Wiring
Note: Some DHT22 sensors do not come with a pull-up resistor, so you may need to connect one yourself. A 10k resistor is typically used, and it should be connected from the data pin of the sensor to the +3.3V or +5V power supply.
MCU | DHT Pin |
---|---|
ESP32 | 16 |
ESP8266 | 14 (D5) |
Let’s verify that temperature is wired correctly and working.
Arduino IDE Serial Monitor will show the current temperature like this
Step 1 : Create a new device in Sinric Pro
- Login to your Sinric Pro account, go to Devices menu on your left and click Add Device button (On top left).
- Enter the device name Temperature Sensor, description My Temperature Sensor and select the device type as Temperature Sensor.
- Click Next the in the Notifications tab
You can set the threshold here to receive a push notification via the Sinric Pro app when the temperature goes below or above a certain temperature. Use the Retrigger Time to set the delay between notifications.
-
Click Others tab and Click Save
-
Next screen will show the credentials required to connect the device you just created.
- Copy the Device Id, App Key and App Secret Keep these values secure. DO NOT SHARE THEM ON PUBLIC FORUMS !
Step 2 : Connect to Sinric Pro
Step 2.1 Install Sinric Pro Library
You can generate the code using Zero Code feature or write it by your self. If you do not have programming experice, we recommend to use Zero Code feature in the Portal to generate the code, download and flash.
2.2 Complete Code
Now you should be able to view the temperature via Sinric Pro App
Charts via Portal
Alexa, Google Home and SmartThings
Please note that Google Home App shows the temperature sensor as a Thermostat due to Google Home limitations.
Troubleshooting
-
error: no matching function for call to ‘DHT::DHT()’ or error: ‘class DHT’ has no member named ‘getMinimumSamplingPeriod’
Solution: Please make sure correct DHT library is installed. This example was made with https://github.com/markruys/arduino-DHT. Remove any other DHT libraries you may have previously installed eg: https://github.com/adafruit/DHT-sensor-library
-
Please refer to our Troubleshooting page for more details.
This document is open source. See a typo? Please create an issue