loading

Make your own home weather station. The device measures temperature, humidity and light. All data are send to a website name Ubitos.com.

This tutorial has 5 steps:

1. What do you need?

2. Device and electronic

3. Acquisition

4. Send data to Ubidots

5. Supply power

Step 1: Material Needed

Hardware:

· NodeMCU with ESP8266

· Sensor DHT22

· Light resistor

· Wires

· Supply card LiPo Rider Pro

· Rechargeable Battery

· Wireless Charging PCB Module 5-12V

· Resistor 2.7kΩ

· Resistor 10kΩ

Software:

· Last Arduino compiler

· Library “DHT.h” care to find one according to NodeMCU card

· Library “ESP8266WiFi.h”

Step 2: Device and Electronic

About sensors, we have an “RoHS Light resistor CE5/09 4mm” and a “DHT22” from Adafruit, it works as well with a “DHT11”.

Make the wiring on the picture above. The 10KΩ resistor with the DHT and the 2.7kΩ resistor with your light sensor.

Caution! If you don’t have the same light sensor, you have to calculate a new value’s resistor.

Step 3: Acquisition

Connect your NodeMCU to your computer and enter this code.

The device will send to the computer the variables.

#include "DHT.h"//Care to havea “DHT” library compatible to NodeMCU

#define SEC 1000

#define MIN (60*SEC)

#define DELAY (MIN)

int n = 0;

//FOR ACQUISITION

float temperature;

float humidity;

float OUTPUT_light_sensor;

float light;

//MODEMS
const char* ssid = "Your ssid";

const char* password = "Your password";

//FOR * CONNEXIONS
const int port = 80;

String url = "";

DHT dht;

void Acquisition_data (){ //this function read sensors and display data

n++;

delay(dht.getMinimumSamplingPeriod());

temperature = dht.getTemperature();

humidity = dht.getHumidity();

OUTPUT_light_sensor = analogRead(A0);

light = OUTPUT_light_sensor/1024*100;

Serial.print("n ");

Serial.println(n);

Serial.print("Light= ");

Serial.print(int(light));

Serial.println("%");

Serial.print("Humidity = ");

Serial.print(int(humidity));

Serial.println("%");

Serial.print("Temperature = ");

Serial.print(int(temperature));

Serial.println("C");

Serial.println("");

}

void setup() {

Serial.begin(115200);

dht.setup(14); // data pin 2 D4k

delay(1000);

}

void loop() {

Acquisition_data();

delay(DELAY);

}

Step 4: Send Data to Ubidots

Here send your data to Ubidots, but before you must register to website and do the tutorial. When you are ready, create your device with 3 variables (temperature, humidity and light).

This links should help you to create your Ubidots web site, good luck:

https://ubidots.com/docs/#get-started

Here the code doing the data sendind.

--->Before "your setup()" add :

"

#include "ESP8266WiFi.h"

//MODEMS
const char* ssid = "Your SSID";

const char* password = "Your password";

//FOR * CONNEXIONS

const int port = 80;

String url = "";

//FOR UBIDOTS

const char host_ubidots[] = "things.ubidots.com";

String API_Label = "Your API label";

String token = "Your token";

String ubidots_command;

String JSON_Temperature;

String JSON_Light;

String JSON_Humidity;

String data;

String len;

// Attempt to connect to WiFi
void connectWiFi() {

// Set WiFi mode to station (client)

WiFi.mode(WIFI_STA);

// Initiate connection with SSID and PSK

WiFi.begin(ssid, password);

// Blink LED while we wait for WiFi connection

Serial.println();

Serial.print("Connecting to ");

Serial.println(ssid);

while ( WiFi.status() != WL_CONNECTED ) {

delay(500);

Serial.print(".");

}

Serial.println("");

Serial.println("WiFi connected");

Serial.println("");

// Printing the ESP IP address

Serial.println("IP address: ");

Serial.println(WiFi.localIP());

Serial.println("");

}

"

--->In your setup add this line:

"

connectWiFi();

"

--->In your loop() add after the acquisition function and before the delay:

"

WiFiClient client;

//Ubidots
if ( !client.connect(host_ubidots, port) ) {

Serial.println("Connection to ubidots host failed !");

}

else{

//Ubidots HTTP POST request

JSON_Temperature = "\"temperature\": {\"value\": " + String(temperature) + "}";

JSON_Humidity = "\"humidity\": {\"value\": " + String(humidity) + "}";

JSON_Light = "\"light\": {\"value\": " + String(light) + "}";

data = "{" + JSON_Temperature + "," + JSON_Humidity + "," + JSON_Light + "}";

len = String(data.length());

url = "/api/v1.6/devices/" + API_Label + "/?token="+token; ubidots_command = (String("POST ") + url + " HTTP/1.1\r\n" + "Host: " + host_ubidots + "\r\n" + "Content-Type: application/json\r\n" + "Content-Length: " + len + "\r\n" + "Connection: close\r\n" + "\r\n" + data + "\r\n\r\n");

client.print(ubidots_command);

}

"

Step 5: Supply Power

In thislast step, you have a NodeMCU able to send your measures to a website.

Now you want this device can be autonomous.

With the Lipo Rider Pro card, you can supply your device with a battery and a supply source like a solar panel.

As you can see on the card’s picture, you have 3 ports.

The USB right port must be connected to your NodeMCU.

Put on the switch above to supply.

On the left, you can see 2 connections;

The one at the top is destined for the battery

The one at the bottom is destined for a solar panel or any power supply between 5 and 12V like

an induction charging PCB..

<p>I am getting nothing from my DHT11. I get the same value no matter what I do.</p><p>Humidity = 2147483647%<br>Temperature = 2147483647C</p><p>I even tried a different DHT11.</p><p>Also, Is there a way to display Fahrenheit?</p><p>Thank you!</p><p>Jay</p>
<p>Thanks for sharing :)</p>

About This Instructable

332views

12favorites

License:

More by paolosamo:NodeMCU Home Weather Station 
Add instructable to: