// Include necessary libraries
#include <Arduino.h>
// Define constants
const int ldrPin = 34; // LDR pin connected to GPIO 34
const int ledPin = 13; // LED pin connected to onboard LED (GPIO 13)
void setup() {
pinMode(ldrPin, INPUT); // Set LDR pin as input
pinMode(ledPin, OUTPUT); // Set LED pin as output
Serial.begin(9600); // Initialize serial communication for debugging
}
void loop() {
// Read the value from the LDR
int ldrValue = analogRead(ldrPin);
// Map the LDR value to the LED brightness (0-255)
int ledBrightness = map(ldrValue, 0, 4095, 0, 255);
// Set the LED brightness
analogWrite(ledPin, ledBrightness);
// Print the LDR value and LED brightness for debugging
Serial.print("LDR Value: ");
Serial.print(ldrValue);
Serial.print(" | LED Brightness: ");
Serial.println(ledBrightness);
delay(1000); // Delay for a second before the next reading
}