0% found this document useful (0 votes)
114 views4 pages

Esp32 Thingspeak

The document describes connecting an ESP32 to Thingspeak to send temperature and humidity sensor readings from a DHT22 sensor and control an LED based on those readings. The ESP32 connects to WiFi, initializes the DHT22 sensor and ThingSpeak client, reads the sensor data in a loop, sends it to the ThingSpeak channel, and turns an LED on or off depending on whether the readings exceed thresholds.

Uploaded by

usama2003113m
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)
114 views4 pages

Esp32 Thingspeak

The document describes connecting an ESP32 to Thingspeak to send temperature and humidity sensor readings from a DHT22 sensor and control an LED based on those readings. The ESP32 connects to WiFi, initializes the DHT22 sensor and ThingSpeak client, reads the sensor data in a loop, sends it to the ThingSpeak channel, and turns an LED on or off depending on whether the readings exceed thresholds.

Uploaded by

usama2003113m
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/ 4

ESP32 THINGSPEAK

const char* server = "api.thingspeak.com";


DHTesp dhtSensor;
WiFiClient client;

void setup()
{
Serial.begin(115200);
dhtSensor.setup(DHT_PIN, DHTesp::DHT22);
pinMode(LED_PIN, OUTPUT);
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
while (WiFi.status() != WL_CONNECTED){
delay(1000);
Serial.println("Wifi not connected");
}
Serial.println("Wifi connected !");
Serial.println("Local IP: " + String(WiFi.localIP()));
WiFi.mode(WIFI_STA);
ThingSpeak.begin(client);
}
void loop()
{
TempAndHumidity data = dhtSensor.getTempAndHumidity();
ThingSpeak.setField(1,data.temperature);
ThingSpeak.setField(2,data.humidity);
if (data.temperature > 35 || data.temperature < 12 ||
data.humidity > 70 || data.humidity < 40)
{
digitalWrite(LED_PIN, HIGH);
}
else{
digitalWrite(LED_PIN, LOW);
}
int x = ThingSpeak.writeFields(myChannelNumber,myApiKey);
Serial.println("Temp: " + String(data.temperature, 2) + "°C");
Serial.println("Humidity: " + String(data.humidity, 1) + "%");
if(x == 200){
Serial.println("Data pushed successfull");
LDR

CODE;

int LDR =34;


int LED =12;

void setup()
{
pinmode(LDR,INPUT);
pinmode(LED,OUTPUT);
}

void loop()
{
int sensor = analogRead(LDR);
int brightness = map(sensor,0,4095,0,255);
analogWrite(LED,BRIGHTNESS);
delay(100);
}
#include "Arduino.h"
#include "uRTCLib.h"
// uRTCLib rtc;
uRTCLib rtc(0x68);
char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday",
"Saturday"};
void setup () {
Serial.begin(9600);
delay(3000); // wait for console opening

URTCLIB_WIRE.begin();

rtc.set(0, 56, 12, 5, 13, 1, 22);


// rtc.set(second, minute, hour, dayOfWeek, dayOfMonth, month, year)
// set day of week (1=Sunday, 7=Saturday)
}
void loop() {
rtc.refresh();
Serial.print("Current Date & Time: ");
Serial.print(rtc.year());
Serial.print('/');
Serial.print(rtc.month());
Serial.print('/');
Serial.print(rtc.day());

Serial.print(" (");
Serial.print(daysOfTheWeek[rtc.dayOfWeek()-1]);
Serial.print(") ");

Serial.print(rtc.hour());
Serial.print(':');
Serial.print(rtc.minute());
Serial.print(':');
Serial.println(rtc.second());

delay(1000);}

You might also like