Concept
Sometimes in the UAE sunlight levels are pretty strong and sometimes harmful, so I created this project to help people know whether it is safe to go outside based on how bright the sunlight is. It uses an LDR to measure how strong the light is. If the light level is too high, a red LED turns on to show that it might be unsafe due to strong sunlight. If the light is at a normal or low level, a green LED turns on to show it is safe. The system only works when a button is pressed, giving the user control over when to check.
Implementation and Setup
To build the project, I used an LDR sensor, a push button, two LEDs (red and green), and some resistors. The LDR is connected to analog pin A0 to measure light. The button is connected to digital pin 11, and the LEDs are connected to pins 3 and 5. When the button is held down, the Arduino reads the light level. If it is above the threshold of 900, the red LED turns on meaning the sunlight levels are too high. If it is below, the green LED turns on, so the light levels are safe. I also used the Serial Monitor to display the light values for testing.
Code:
const int ldrPin = A0; // LDR sensor const int buttonPin = 11; // push button const int redLED = 3; // red LED (too bright) const int greenLED = 5; // green LED (safe to go out) const int threshold = 900; // brightness threshold void setup() { pinMode(redLED, OUTPUT); pinMode(greenLED, OUTPUT); pinMode(buttonPin, INPUT); Serial.begin(9600); } void loop() { int lightValue = analogRead(ldrPin); // get light level int buttonState = digitalRead(buttonPin); // read button Serial.println(lightValue); // Serial.println(buttonState); //// to check button // only run if button is pressed if (buttonState == HIGH) { if (lightValue > threshold) { // if light value above threshold red LED on digitalWrite(redLED, HIGH); digitalWrite(greenLED, LOW); // green LED off } else { digitalWrite(redLED, LOW); // red LED off if light value below threshold digitalWrite(greenLED, HIGH); // green LED on } } else { // else both LEDS are off digitalWrite(redLED, LOW); digitalWrite(greenLED, LOW); } delay(100); // delay }
Video:
Future Improvements or Reflection
In the future, I could add a UV sensor to measure sunlight more accurately, since the LDR only measures brightness, not UV levels. I could also add a small screen or buzzer to make the warnings more clear.