Concept
Link: https://drive.google.com/file/d/1iGY1zePkL1vzLj20TXHqm8l7hkp8WpBZ/view?usp=sharing
For this assignment, I made a circuit that mimics the performance of solar-powered garden lights. The LED automatically turns on when the environment is dark and off when the environment is bright. I used a photoresistor to sense the light around the environment and included a button for manual control, controlling the LED when the environment is dark. The LED automatically turns on when the light is low. If the button is pressed during darkness, the LED turns off but with a brief delay before turning on again. When there is enough ambient light, the LED turns off automatically.
Code Highlight (Arduino Code)
const int LED_PIN = 9; // LED that turns on in dark, or with button const int LIGHT_SENSOR_PIN = A2; // Light sensor (photoresistor) const int BUTTON_PIN = A3; // Button input (wired to GND) const int LIGHT_THRESHOLD = 600; // Adjust based on your light conditions void setup() { pinMode(LED_PIN, OUTPUT); pinMode(BUTTON_PIN, INPUT_PULLUP); // Use internal pull-up resistor Serial.begin(9600); // Optional: monitor values for debugging } void loop() { int light_value = analogRead(LIGHT_SENSOR_PIN); int button_state = digitalRead(BUTTON_PIN); Serial.print("Light: "); Serial.print(light_value); Serial.print(" | Button: "); Serial.println(button_state); if (light_value < LIGHT_THRESHOLD) { // DARK: turn LED ON automatically digitalWrite(LED_PIN, HIGH); } else { // BRIGHT: turn LED ON only if button is PRESSED (LOW) if (button_state == LOW) { digitalWrite(LED_PIN, HIGH); } else { digitalWrite(LED_PIN, LOW); } } delay(100); // Short delay to reduce flicker and serial flooding }
The code reads the amount of light from a sensor and controls an LED based on that. When it’s dark, the LED turns on automatically. When it’s bright, the LED turns off, but if the button is pressed, the LED will turn on even in the light. The button works like a manual override. There’s a small delay in the code to avoid flickering, and the system checks the light level regularly to adjust the LED accordingly.
Challenges
I faced several issues while working on this project. First, it was confusing to make the photoresistor function properly, especially to understand how to make the LED respond to light and darkness. I also struggled to set the correct light threshold so that the LED would turn on at the right time. Plugging in the photoresistor correctly was challenging, and I had to figure out how to use a voltage divider. When I added the button, it didn’t work at first because I didn’t know how to connect it through the internal pull-up resistor. I also had trouble coding to make the LED turn on automatically when it’s dark and just the button when light. It was a lot of trial and error to make everything work the way I desired.