Temperature,Humidity Measurement Using Arduino with ESP8266
Im using esp8266 with arduino uno
Components and supplies
1
DHT11 Temperature & Humidity Sensor (4 pins)
1
Arduino UNO
1
Jumper wires (generic)
1
Breadboard (generic)
1
ESP8266 ESP-01
Apps and platforms
1
Think speak web
1
Arduino IDE
Project description
Code
The code
c_cpp
1#include <dht11.h> 2#include <SoftwareSerial.h> 3 4 5String agAdi = "network"; // We write the name of our network here. 6String agSifresi = "network password"; // We write the password of our network here. 7 8int rxPin = 10; //ESP8266 RX pini 9int txPin = 11; //ESP8266 TX pini 10int dht11Pin = 2; 11 12String ip = "184.106.153.149"; //Thingspeak ip adresi 13float sicaklik, nem; 14 15dht11 DHT11; 16 17SoftwareSerial esp(rxPin, txPin); // We make serial communication pin settings. 18 19void setup() { 20 21 Serial.begin(9600); // We are starting our communication with the serial port. 22 Serial.println("Started"); 23 esp.begin(115200); // We are starting serial communication with ESP8266. 24 esp.println("AT"); // We do the module control with the AT command. 25 Serial.println("AT sent "); 26 while(!esp.find("OK")){ // We wait until the module is ready. 27 esp.println("AT"); 28 Serial.println("ESP8266 Not Find."); 29 } 30 Serial.println("OK Command Received"); 31 esp.println("AT+CWMODE=1"); // We set the ESP8266 module as a client. 32 while(!esp.find("OK")){ // We wait until the setting is done. 33 esp.println("AT+CWMODE=1"); 34 Serial.println("Setting is ...."); 35 } 36 Serial.println("Set as client"); 37 Serial.println("Connecting to the Network ..."); 38 esp.println("AT+CWJAP=\\""+agAdi+"\\",\\""+agSifresi+"\\""); // We are connecting to our network. 39 while(!esp.find("OK")); // We wait until it is connected to the network. 40 Serial.println("connected to the network."); 41 delay(1000); 42} 43void loop() { 44 esp.println("AT+CIPSTART=\\"TCP\\",\\""+ip+"\\",80"); // We connect to Thingspeak. 45 if(esp.find("Error")){ // We check the connection error. 46 Serial.println("AT+CIPSTART Error"); 47 } 48 DHT11.read(dht11Pin); 49 sicaklik = (float)DHT11.temperature; 50 nem = (float)DHT11.humidity; 51 String veri = "GET https://api.thingspeak.com/update?api_key=9D9YPGYTPOO0QKMR"; // Thingspeak command. We write our own api key in the key part. 52 veri += "&field1="; 53 veri += String(sicaklik);// The temperature variable we will send 54 veri += "&field2="; 55 veri += String(nem);// The moisture variable we will send 56 veri += "\ \ 57\ \ 58"; 59 esp.print("AT+CIPSEND="); // We give the length of data that we will send to ESP. 60 esp.println(veri.length()+2); 61 delay(2000); 62 if(esp.find(">")){ // The commands in it are running when ESP8266 is ready.. 63 esp.print(veri); // We send the data. 64 Serial.println(veri); 65 Serial.println("Data sent."); 66 delay(1000); 67 } 68 Serial.println("Connection Closed."); 69 esp.println("AT+CIPCLOSE"); // we close the link 70 delay(1000); // We wait 1 minute for sending new data. 71}
Downloadable files
the shematic
the shematic

the shematic
the shematic

Comments
Only logged in users can leave comments