Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- https://imgur.com/a/Zv4ioBx
- int lightSensorValue = 0; // Variable to store the light sensor reading
- void setup()
- {
- pinMode(A0, INPUT); // Set A0 pin as an input for the light sensor
- pinMode(9, OUTPUT); // Set pin 9 as an output to control the LED
- Serial.begin(9600); // Initialize serial communication at 9600 baud
- }
- void loop()
- {
- lightSensorValue = analogRead(A0);
- // Read the light sensor value
- Serial.println(lightSensorValue);
- // Print the sensor value to the Serial Monitor
- int ledBrightness = map(lightSensorValue, 0, 1023, 0, 255);
- // Map the sensor value to LED brightness
- analogWrite(9, ledBrightness);
- // Control LED brightness based on the sensor reading
- delay(100);
- // Wait for 100 milliseconds before the next loop iteration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement