#include <ESP8266WiFi.h>
#include <DHT.h>
////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define DHTPIN 2 // what pin we’re connected to
String apiKey = "yourAPIKey"; //API key from ThingSpeak channel
const char* ssid = "WifiSSID"; //SSID of your wifi
const char* password = "password123"; //password of your wifi
int duration=5;//delay between each data measure and uploading
////////////////////////////////////////////////////////////////////////////////////////////////////////////
const char* server = "api.thingspeak.com";
DHT dht(DHTPIN, DHT11, 15);// Start DHT sensor
WiFiClient client; //Start clinet
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
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");
}
void loop() {
//Get temperature and humidity data
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
delay(1000);
return;
}
if (client.connect(server, 80)) {
String postStr = apiKey;
postStr += "&field1=";
postStr += String(t);
postStr += "&field2=";
postStr += String(h);
postStr += "\r\n\r\n";
//Uplad the postSting with temperature and Humidity information every
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius Humidity: ");
Serial.print(h);
Serial.println("% send to Thingspeak");
}
client.stop();
Serial.println("Waiting…");
// thingspeak needs minimum 15 sec delay between updates
delay(duration*1000);
}
#include <DHT.h>
////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define DHTPIN 2 // what pin we’re connected to
String apiKey = "yourAPIKey"; //API key from ThingSpeak channel
const char* ssid = "WifiSSID"; //SSID of your wifi
const char* password = "password123"; //password of your wifi
int duration=5;//delay between each data measure and uploading
////////////////////////////////////////////////////////////////////////////////////////////////////////////
const char* server = "api.thingspeak.com";
DHT dht(DHTPIN, DHT11, 15);// Start DHT sensor
WiFiClient client; //Start clinet
void setup() {
Serial.begin(115200);
dht.begin();
WiFi.begin(ssid, password);
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");
}
void loop() {
//Get temperature and humidity data
float h = dht.readHumidity();
float t = dht.readTemperature();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
delay(1000);
return;
}
if (client.connect(server, 80)) {
String postStr = apiKey;
postStr += "&field1=";
postStr += String(t);
postStr += "&field2=";
postStr += String(h);
postStr += "\r\n\r\n";
//Uplad the postSting with temperature and Humidity information every
client.print("POST /update HTTP/1.1\n");
client.print("Host: api.thingspeak.com\n");
client.print("Connection: close\n");
client.print("X-THINGSPEAKAPIKEY: " + apiKey + "\n");
client.print("Content-Type: application/x-www-form-urlencoded\n");
client.print("Content-Length: ");
client.print(postStr.length());
client.print("\n\n");
client.print(postStr);
Serial.print("Temperature: ");
Serial.print(t);
Serial.print(" degrees Celcius Humidity: ");
Serial.print(h);
Serial.println("% send to Thingspeak");
}
client.stop();
Serial.println("Waiting…");
// thingspeak needs minimum 15 sec delay between updates
delay(duration*1000);
}
Nice blog..
ReplyDeleteThanks for Sharing...
Humidity Meter, Controller, pH Controller, Meter, Temperature Logger, Controller
"• Nice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating IOT Online Training
ReplyDelete"
It was really a nice article and i was really impressed by reading this Data Science Online course Bangalore
ReplyDeleteDid the code work?
DeleteHi,
ReplyDeleteI am using Arduino Uno, ESP8266 wifi module and DHT11. I used your program and getting error while compiling it on Arduino IDE
WiFiClient1' does not name a type
I am I missing something here
I have added API key, wifi credentials and used DHT pin 2 same as code.
ReplyDeleteThe information which you have provided is very good. It is very useful who is looking for at machine learning online course
ReplyDeleteThanks for sharing a scenario of Wireless Temperature Sensor. IoT devices are becoming a part of the mainstream electronics culture and people are adopting smart devices based on IoT platform into their homes faster than ever. Whereas Wireless temperature & humidity sensor with cloud based monitoring smartly.
ReplyDeleteWireless GS1 temperature & humidity sensor
Thank you for your post. This is excellent information. It is amazing and wonderful to visit your site.
ReplyDeleteComputer Repairing Course in Delhi
This comment has been removed by the author.
ReplyDeleteNice and good article. It is very useful for me to learn and understand easily. Thanks for sharing your valuable information and time. Please keep updating .
ReplyDeleteDigital Marketing Training in Chennai
Digital Marketing Course in Chennai