#include <WiFi.h>
#include <WiFiClient.h>
#include "ThingSpeak.h"
// Pin connected to the LDR
#define LDR_PIN 32
// WiFi credentials
const char* WIFI_NAME = "Wokwi-GUEST";
const char* WIFI_PASSWORD = "";
// ThingSpeak channel info
const int myChannelNumber = 3370798;
const char* myApiKey = "Y2R9H89UX1ASIBTQ";
const char* server = "api.thingspeak.com";
WiFiClient client;
void setup() {
pinMode(LDR_pin, INPUT); // Set the LDR pin as input
WiFi.begin(WIFI_NAME, WIFI_PASSWORD); // Connect to Wi-Fi
ThingSpeak.begin(client); // Initialize ThingSpeak with your network client
Serial.begin(115200); // Start serial communication at 115200 baud
}// put your setup code here, to run once:
}
void loop() {
int ldr = analogRead(LDR_pin); // Read analog value from LDR
Serial.println(ldr); // Print value to serial monitor
ThingSpeak.setField(1, ldr); // Set field 1 in ThingSpeak with LDR value
ThingSpeak.writeFields(myChannelNumber, myApiKey); // Send data to ThingSpeak
}
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
}