#include <WiFi.h>
#include <WiFiClient.h>
#include "ThingSpeak.h"
#define LDR_pin 32
const char* WIFI_NAME = "Wokwi-GUEST";
const char* WIFI_PASSWORD = "";
const int myChannelNumber = 3049334;
const char* myApiKey = "NZB65N1SWBTZDOOM";
const char* server = "api.thingspeak.com";
WiFiClient client;
void setup() {
pinMode(LDR_pin, INPUT);
WiFi.begin(WIFI_NAME, WIFI_PASSWORD);
ThingSpeak.begin(client);
Serial.begin(115200);
}
void loop() {
int ldr = analogRead(LDR_pin); // Raw 0–4095
int scaledValue = map(ldr, 0, 4095, 0, 1023); // Scaled 0–1023
Serial.print("Raw: ");
Serial.print(ldr);
Serial.print(" | Scaled: ");
Serial.println(scaledValue);
if (scaledValue > 1016) {
Serial.println("Full moon");
}
else if (scaledValue >= 853 && scaledValue <= 1016) {
Serial.println("Twilight");
}
else if (scaledValue >= 170 && scaledValue < 853) {
Serial.println("Overcast day");
}
else if (scaledValue >= 8 && scaledValue < 170) {
Serial.println("Full daylight");
}
delay(1000);
ThingSpeak.setField(1,scaledValue);
ThingSpeak.writeFields(myChannelNumber, myApiKey);
}