#define BLYNK_TEMPLATE_ID "TMPL3ifK-hehi"
#define BLYNK_TEMPLATE_NAME "Automatic Screen Closer"
#define BLYNK_AUTH_TOKEN "9-myEnZr_nZmO_ArJX2Nd3Nl_YcIhBr6"
#include <WiFi.h>
#include "time.h"
//LDR Characteristics
const float GAMMA = 0.7;
const float RL10 = 50;
//Wifi Details
const char* ssid = "Wokwi-GUEST";
const char* password = "";
//Ntp Server Details
const char* ntpServer = "pool.ntp.org";
const long gmtOffset_sec = 0;
const int daylightOffset_sec = 19800;
void printLocalTime()
{
struct tm timeinfo;
if(!getLocalTime(&timeinfo)){
Serial.println("Failed to obtain time");
return;
}
Serial.println(&timeinfo, "%A, %B %d %Y %H:%M:%S");
}
void wificonnect()
{
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println(" CONNECTED");
}
/*void brightness()
{
int analogValue = analogRead(2);
float voltage = analogValue / 1024. * 5;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Serial.println(lux);
}*/
void bright()
{
float ADC;
float RLDR;
float Vout;
float Lux;
ADC = analogRead(2);
Serial.println(ADC);
Vout = (ADC * 0.0048828125);
Serial.println(Vout);
RLDR = (10000.0 * (5 - Vout))/Vout;
Serial.println(RLDR);
Lux = (500 / RLDR);
Serial.println(Lux);
}
void time()
{
time_t now = time(nullptr);
struct tm *timeinfo;
timeinfo = localtime(&now);
// Format time as string
char timeStr[20];
strftime(timeStr, sizeof(timeStr), "%Y-%m-%d %H:%M:%S", timeinfo);
// Print and/or use the time string
Serial.print("Current local time: ");
Serial.println(timeStr);
Serial.println(timeStr[11]);
delay(1000);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
pinMode(2,INPUT);
pinMode(15, OUTPUT);
wificonnect();
configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
printLocalTime();
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(15,HIGH);
delay(100);
int a=analogRead(2);
Serial.println(a);
delay(10);
// bright();
time();
// this speeds up the simulation
}