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

WOKW3I

The document contains code for three different ESP32 projects: 1) Connecting an ESP32 to Thingspeak to send temperature and humidity sensor readings and control an LED based on the readings. 2) Using an LDR light sensor on an ESP32 to control the brightness of an LED. 3) Setting up a real time clock (RTC) on an ESP32 and printing the current date and time.

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)
43 views4 pages

WOKW3I

The document contains code for three different ESP32 projects: 1) Connecting an ESP32 to Thingspeak to send temperature and humidity sensor readings and control an LED based on the readings. 2) Using an LDR light sensor on an ESP32 to control the brightness of an LED. 3) Setting up a real time clock (RTC) on an ESP32 and printing the current date and time.

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

#include <WiFi.h>
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");
}else{
Serial.println("Push error" + String(x));
}
Serial.println("---");
delay(10000);
}
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