Project tutorial
WiFi ESP8266 and DHT22 Sensor

WiFi ESP8266 and DHT22 Sensor © GPL3+

This is a quick implementation project using a ESP8266 WiFi module and recording temperature and humidity (DHT22) on Thingspeak channel.

  • 25,901 views
  • 7 comments
  • 24 respects

Components and supplies

About this project

I wanted to design a small weather station and use it for tracking for long periods of time the outdoor weather variables automatically and recording into a spreadsheet. It was really just for fun, to understand how is the behavior of these weather factors in my county and at home. My county has very good condition for farmers and produce vegetables and others green food. In excess. To sell food for our main city.

Step 1

Step 2

Connect ESP8266 with Arduino and upload the code from IDE.

Using the serial port upload the code directly to the ESP8266 module. Remember that once you do this the original firmware is erased. If you want the original firmware again in your ESP8266 you will need a long process to do that. Check this video which can give you a shortcut about it.

Flash Firmware ESP8266

Step 3

Connect DHT22 sensor:

Step 4

Check your communication with the Thingspeak channel you previously had configured:

These are mandatory code lines to communicate with your channel:

#include <ThingSpeak.h> 
unsigned long myChannelNumber = 167x1x; 
const char * myWriteAPIKey = "VXXXXV86RWRXX9Y"; 
ThingSpeak.writeField(myChannelNumber, 1, h, myWriteAPIKey); 
delay(20000);  
ThingSpeak.writeField(myChannelNumber, 2, t, myWriteAPIKey); 
delay(20000);  

Step 5

Remember your ESP8266 needs a big amount of current, so a cause of failure is that you need to feed it from your PC USB port and from an external power source.

Step 6

If you can record 8 fields in a channel please start to thinking what other weather sensors you can add to your station - barometric pressure? Maybe!

Code

temphumwifi.inoArduino
#include <ThingSpeak.h>

/* DEVELOPER: hernando Bolanos - Colaborations - original code and libraries for wifi modules and code uploaded in GITHUB for send information to Thinhspeak-Libraries according to each author
 *  
 *  This code send to  Thingspeak DHT22 data each 20 seconds -using wifi 
 *  This program do not use arduino just use the GPIO2 to receive DHT22 sensor information and demux it. How to load directly to de esp8266 from arduino IDE is a chellenge- take a look to the "el profe garcia videos on youtube"
 */
#include <DHT.h> //cargamos la librera DHT
#define DHTPIN 2 //Seleccionamos el pin en el que se conectar el sensor
#define DHTTYPE DHT22 //Se selecciona el DHT22(hay otros DHT)
DHT dht(DHTPIN, DHTTYPE); //Se inicia una variable que ser usada por Arduino para comunicarse con el sensor
#include <ESP8266WiFi.h>

unsigned long myChannelNumber = 167319;
const char * myWriteAPIKey = "XXXP9V86RWR7R9Y";

const char* ssid = "XXXX ";
const char* password = "XXXX";

 WiFiClient  client;
// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);
   dht.begin(); //Se inicia el sensor

 

 
  
  
  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);
  
  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");  
  
  // Start the server
 // server.begin();
 // Serial.println("Server started");
   
 

  // Print the IP address
  Serial.println(WiFi.localIP());

ThingSpeak.begin(client);
   
}

void loop() {

float h = dht.readHumidity(); //Se lee la humedad
  float t = dht.readTemperature(); //Se lee la temperatura
  //Se imprimen las variables
  Serial.println("Humedad: "); 
  Serial.println(h);
  Serial.println("Temperatura: ");
  Serial.println(t);
  delay(2000); //Se espera 2 segundos para seguir leyendo //datos
 

ThingSpeak.writeField(myChannelNumber, 1, h, myWriteAPIKey);
  delay(20000); 
  

ThingSpeak.writeField(myChannelNumber, 2, t, myWriteAPIKey);
  delay(20000); 
  
  


 
   }
 
    
  
  
 

Schematics

DHT22_ESP8266 scheme
Wifidht22

Comments

Author

Hernanduino
Hernanduino
  • 3 projects
  • 19 followers

Additional contributors

  • Wifi esp8266 explanation-serial port using and arduino without micro controller by "el profe garcia" colombian youtuber
  • Example code and libraries for wifi apps by thingspeak

Published on

October 8, 2016

Members who respect this project

DefaultKd1qmln69zd91ifbvfkoOverwatch 04 27 2017 19 54 04 529 fbtefhzjv1Default12314000 10206853886297679 5107180040113470709 nClcrosbyDefaultPhoto

and 16 others

See similar projects
you might like

Similar projects you might like

Control Arduino Uno Using ESP8266 WiFi Module and Blynk App

Project tutorial by Adithya TG

  • 5,253 views
  • 10 comments
  • 18 respects

Connect to Blynk using ESP8266 as Arduino Uno wifi shield

Project tutorial by Nolan Mathews

  • 71,138 views
  • 11 comments
  • 50 respects

ESP8266 ESP-01 Webserver

by Robin

  • 100,366 views
  • 18 comments
  • 131 respects
Add projectSign up / Login