0% found this document useful (0 votes)
42 views

Subhan

This document contains code for a sketch that reads temperature and humidity values from a DHT11 sensor using an ESP8266 WiFi module. It connects to a WiFi network and sends the sensor readings alternately to two fields on a ThingSpeak channel every 30 seconds. The sketch was verified.

Uploaded by

manoj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Subhan

This document contains code for a sketch that reads temperature and humidity values from a DHT11 sensor using an ESP8266 WiFi module. It connects to a WiFi network and sends the sensor readings alternately to two fields on a ThingSpeak channel every 30 seconds. The sketch was verified.

Uploaded by

manoj
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

ALLOTMENT ID 17M21A0317

NUMBER
NAME OF THE INTERN MOHD ABDUL
SUBHAN
WORKSHEET NUMBER 07
COMPANY/ORGANISAT INVENTIVE CORE
ION INTEGRATIONS
TRAINER NAME S.K.MOINUDDIN
#include <DHT.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ThingSpeak.h>

#define DHTPIN D5
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);

const char* ssid = "AndroidAPF183";


const char* password = "subhan317";
WiFiClient client;
unsigned long myChannelNumber = 1009991;
const char* myWriteAPIKey =
"R8VC8RPU33FFILC0";

uint8_t temperature, humidity;

void setup()
{
Serial.begin(115200);
dht.begin();
delay(10);
// 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.println(".");
}
Serial.println("");
Serial.println("WiFi connected");
// Print the IP address
Serial.println(WiFi.localIP());
ThingSpeak.begin(client);
}
void loop()
{
static boolean data_state = false;
temperature = dht.readTemperature();
humidity = dht.readHumidity();
Serial.print("Temperature Value is :");
Serial.print(temperature);
Serial.println("C");
Serial.print("Humidity Value is :");
Serial.print(humidity);
Serial.println("%");

if( data_state )
{
ThingSpeak.writeField(myChannelNumber, 1,
temperature, myWriteAPIKey);
data_state = false;
}
else
{
ThingSpeak.writeField(myChannelNumber, 2,
humidity, myWriteAPIKey);
data_state = true;
}
delay(30000);
}

SKETCH VERIFIED.

You might also like