Week 9 – BrightSafe: The Dual-Mode Lighting Guardian

BrightSafe: The Dual-Mode Lighting Guardian

Concept:

My idea, which focuses on house safety and comfort. My code cleverly models a dual lighting system that mimics real-life conditions. The green LED functions as a depiction of “normal life” lighting, changing its brightness dependent on ambient light and producing illumination that closely resembles natural light conditions throughout the day. As the sun goes down the house will receive less light. Conversely, the red LED functions as an emergency light and is managed by a straightforward switch. It is not dependent on the level of ambient light. This arrangement guarantees that residents will have a dependable source of manually activated light providing a safety and convenient light in unforeseen circumstances.

 

Code:

const int ledPinRed = 9;      // Digital LED pin
const int ledPinGreen = 10;   // Analog LED pin 
const int buttonPin = 2;      // Pushbutton pin
const int ldrPin = A0;        // Photoresistor pin

void setup() {
  pinMode(ledPinRed, OUTPUT);
  pinMode(ledPinGreen, OUTPUT);
  pinMode(buttonPin, INPUT_PULLUP); // Enable internal pull-up
  Serial.begin(9600); 
}

void loop() {
  int ldrValue = analogRead(ldrPin); // Read the light level
  int brightness = map(ldrValue, 0, 1023, 0, 255); // Map to PWM range
  analogWrite(ledPinGreen, brightness); // Set brightness of green LED

  // Check if button is pressed (LOW when pressed due to pull-up resistor)
  if (digitalRead(buttonPin) == LOW) {
    digitalWrite(ledPinRed, HIGH); // Turn on red LED
  } else {
    digitalWrite(ledPinRed, LOW); // Turn off red LED
  }


}

Project: 

https://youtube.com/shorts/w3vne8FGQ2k?feature=share

Difficulties: 

I had a hard time connecting the wires to the Arduino as the holes were very small. Also having to write down the code was the most challenging as I’m still not comfortable with this language

Improvements:

My idea is to improve the system by using a separate battery to power the red light. With this improvement, safety lighting is guaranteed to continue even in the event of a power outage, replacing traditional power sources.

Leave a Reply