Concept:
For this Arduino class project, I set out to create a straightforward yet multifunctional night light. The design includes an automatic feature where the light adjusts its brightness based on the room’s lighting conditions, ensuring the perfect level of illumination at all times. Additionally, it features a manual override button that allows users to adjust the brightness to their preference through a different LED at any moment.
A highlight of some code that you’re particularly proud of:
const int lightSensorPin = A0; const int buttonPin = 2; const int redLED = 8; // Red LED on digital pin 8 for on/off control const int yellowLED = 9; // Yellow LED on digital pin 9 for analog control const int lightThreshold = 500; // Light level threshold for the yellow LED int lastButtonState = HIGH; bool redLEDState = LOW; void setup() { pinMode(lightSensorPin, INPUT); pinMode(buttonPin, INPUT_PULLUP); pinMode(redLED, OUTPUT); pinMode(yellowLED, OUTPUT); } void loop() { int lightLevel = analogRead(lightSensorPin); int buttonState = digitalRead(buttonPin); // Button controls the red LED if (buttonState == LOW && lastButtonState == HIGH) { // Toggle the red LED state redLEDState = !redLEDState; digitalWrite(redLED, redLEDState); // Set the red LED according to the toggled state delay(50); // Debounce delay } // Light sensor controls the yellow LED if(lightLevel < lightThreshold) { // If it's dark, set the yellow LED to a brightness proportional to the darkness int brightness = map(lightLevel, 0, lightThreshold, 255, 0); analogWrite(yellowLED, brightness); } else { // If it's light, turn off the yellow LED analogWrite(yellowLED, 0); } // Update last button state lastButtonState = buttonState; }
Video of Project:
Reflection and ideas for future work or improvements:
Reflecting on this Arduino night light project, I initially hoped to make the visual structure more intriguing and implement the design in a more creative way. However, I’ve come to realize that I’m still in the process of getting comfortable with the actual wiring and coding aspects of the project, which consumed the majority of my time. Despite these challenges, I’m proud of the work I’ve accomplished. If I had more time to devote to this project, I would focus on better integrating the button’s functionality with the light sensor to create a more seamless interaction between user input and the device’s automatic responses. In the future, I aim to explore more sophisticated design and programming techniques that could enhance both the aesthetic and functional elements of projects like this, ensuring they are not only practical but also visually appealing.