Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Status
colourYellow
titleDRAFT

...

DHT22

NodeMCU DEVKIT 1.0.jpg

NodeMCU

Wiring


The most basic DHT humidity and temperature sensor comes in two variants with different levels of accuracy.


DHT-11DHT-22
Humidity range20%-80%RH (±5%RH)0%-100%RH (±2%RH)
Temperature range0-50°C (±2°C)-40-80°C (±0.5°C)
Measurement time1s per sample2s 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.

...

Next we need to configure the device name (you choose) and the api key (see this guide).

app code:App Code (full example)

Code Block
#define DHTPIN            D2         // Pin which is connected to the DHT sensor.

// Available types:  DHT11, DHT22, DHT21
DHT_Unified dht(DHTPIN, DHT11);

DHT_Unified::Temperature sTemp = dht.temperature();
DHT_Unified::Humidity sHumidity = dht.humidity();

void setup() {
  Serial.begin(115200); 
  
  ODev.name("ODevHT-01");
  ODev.apiKey("----APIKEY-----");
  ODev.server("----SERVER IP-----");

  dht.begin(); // Initialize device.
  
  ODev.addSensor("HT01_Temperature", new AdafruitSensor(sTemp))
    ->setInterval(1 * (1000)); // 1sec
    
  ODev.addSensor("HT01_Humidity", new AdafruitSensor(sHumidity))
    ->setInterval(1 * (1000)); // 1sec

  WiFi.mode(WIFI_AP_STA);
  WiFi.begin("---- WIFI----", "---- PASS----");

  ODev.begin();
}

void loop() {
  ODev.loop();
}

...

Sending data to the cloud

As I mentioned before, you You do not have to do much, just make sure you are looking at the console, if the WiFi connection and the server was successfully performed.

...

Start the OpenDevice (guide), access (http://localhost:8181), and verify that your devices have been registered correctly.

IMAGEMXXXXXXXXXXXXXXXXXXXXXXXXXXXX - devices

IMAGEMXXXXXXXXXXXXXXXXXXXXXXXXXXXX - interna dos devicesImage Added


Image Added

Create custom visualizations using Dashboards

...

First create the dashboardIMAGEM

On dashboards page click in " New Dashboard ", set the name and select it in the list.

Image Added

Then add Widgets

Vamos criar o  gráfico de linha para exibir as informações da temparatura nas útimas 4 horas

IMAGEMLet's create the line graph to display as temperature information in the last 4 hours.

Click and Add Item/Chart and select Line Chart

Image Added

You can also add more then on device on the chart:

Image Added

You have the freedom to edit and position and enlarge the graph as you wish

Vamos agora adicionar uma gauge que mostre o valor da temperatura em tempo real:

IMAGEMLet's now add a gauge that shows the temperature value in real time:

Image Added

After organizing our charts, dragging and expanding, we get the result:

Image Added

WHAT'S NEXT? 

At this point, you are collecting and visualizing data. But, what about reacting to it? The next step is to build a Rule(/wiki/spaces/DOC/pages/99352732) in Losant to send yourself a text message whenever the humidity gets too high. 

...