Status | ||||||
---|---|---|---|---|---|---|
|
...
- OpenDevice server up and running (guide)
- Arduino IDE (with required OpenDevice Libraries)
- ESP8266 module (like NodeMCU)
- DHT22 sensor (and Adafruit's DHT22 library)
DHT22 | NodeMCU |
---|
Wiring
The most basic DHT humidity and temperature sensor comes in two variants with different levels of accuracy.
DHT-11 | DHT-22 | |
---|---|---|
Humidity range | 20%-80%RH (±5%RH) | 0%-100%RH (±2%RH) |
Temperature range | 0-50°C (±2°C) | -40-80°C (±0.5°C) |
Measurement time | 1s per sample | 2s per sample |
Setup
To program the NodeMCU, we are going to use Arduino's IDE. It's the easiest way to get up and running with the DHT22.
First, you'll have to set up your machine: Device Setup Instructions. These instructions take you through installing the IDE, ESP8266 and the proper libraries.
In addition to this, you'll have to install DHT sensor library to read the sensor, we are going to use Adafruit's DHT22 library.
Code / Firmware
The OpenDevice for Arduino software greatly simplifies application development, managing devices and communicating with the server in a completely transparent way, so you can really focus on your project.
...
Code Block |
---|
const char* ssid = "--"; const char* password = "--"; void setup() { ODev.enableDebug(); ODev.name(ODEV_MODULE_NAME); ODev.apiKey(ODEV_API_KEY); ODev.server("192.168.3.106"); // Change Server ! ODev.addDevice("LED", 2, Device::DIGITAL); -- XXXXXXXXXXXX DHT WiFi.mode(WIFI_AP_STA); WiFi.begin(ssid, password); ODev.begin(); } void loop() { ODev.loop(); } |
HTML Comment |
---|
<b>teste</b> |
Next, upload code to the board and open up your serial monitor, you should see the data:
...