Concept and Idea:
I was working on an Arduino project in my core class, where we were playing with the light sensor and I thought about this idea to use for my unusual switch. So basically an LED using a light sensor: it reads the light level, converts it to a simplified scale, and then turns the LED on in dark conditions and off in light conditions. The sensor measures how much light is in the environment. Based on this measurement, the Arduino decides whether it’s dark or light around. If it’s dark, the LED turns on to provide light. If there’s enough light, the LED stays off. This setup is a practical way to automatically turn a light on or off depending on the surrounding light level.
Video:
Code:
const int sensorPin = A0; const int ledPin = 7; // Initialize the setup void setup() { pinMode(ledPin, OUTPUT); // Setup LED pin as an output } // Function to read and process light level int readAndProcessLight(int pin) { int sensorValue = analogRead(pin); // Read the light sensor // Convert the sensor reading from its original range to 0-10 return map(sensorValue, 1023, 0, 10, 0); } // Function to update LED status based on light level void updateLedStatus(int lightLevel, int threshold, int pin) { if (lightLevel < threshold) { digitalWrite(pin, HIGH); // Turn LED on } else { digitalWrite(pin, LOW); // Turn LED off } } void loop() { int lightLevel = readAndProcessLight(sensorPin); // Read and process light level updateLedStatus(lightLevel, 6, ledPin); // Update LED status based on light level delay(200); // Short delay to avoid flickering }
Improvements:
I was trying to incorporate the idea of replacing one LED light with 3 LED lights. With an RGB LED to enable color changes based on light levels. For example, so different colors could indicate different intensities of the light, and I was testing with the sunlight that was falling from my window, from morning to evening.