Output Devices
Automatic Night Lamp
Project Description
The night lamp is equipped with sensors that detect the level of ambient sunlight in its environment. Its design is both aesthetic and functional. During the day, as natural sunlight increases, these sensors trigger the light to dim gradually. As the sun sets or on cloudy days, the sensors adjust the light's brightness accordingly, brightening it to maintain optimal lighting conditions. This light is energy-efficient, reducing electricity usage during the day by utilizing natural light, and provides a comfortable, lighting experience that adjusts automatically to the changing light conditions throughout the day.
Process Documentation
PCB
My PCB worked again from last week. I just needed to reboot my PCB. For some reason it wasn't working during my input devices week. THis is the wiring stratergy above.
The system is composed of a lampshade, the xiao RP2040 as the mirco-controller, LED strip, and a photo-resistor. Both the led (OUTPUT) and the photo-resistor (INPUT) just uses the GPIO pin. But the Photo=resistor is actually a
Coding in Arduino
Arduino Code -> Photo-resistor to Brigthness values
const int psPin = 28; // PhotoSensor
const int ledPin = 6; // LED
int ps; // raw value
int lux;
int setLux = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(psPin, INPUT);
Serial.begin(9600);
}
void loop() {
ps = analogRead(psPin);
lux = map(ps, 0, 1023, 0, 300); //this probably won't be accurate LUX value tho.
// float lux = ps * (100.0 / 1023.0) + 0; <- dunno wat the actual coversion rate would be tho
int ledBrightness = calculateLEDBrightness(lux);
// int ledBrightness = 100000;
analogWrite(ledPin, ledBrightness);
Serial.print("Lux: ");
Serial.print(lux);
Serial.print(", LED Brightness: ");
Serial.println(ledBrightness);
delay(1000);
}
int calculateLEDBrightness(int lux) {
int diff = setLux - lux; //different between current and set lux value
int ledBrightness = constrain(map(lux, 0, 30, 300, -10), 0, 2000);
// I don't think the lux diff will be big than 200, but in the case that it does, it added a constrain.
return ledBrightness;
}
Demo of how the lux values from the photo-resistor is sync with the LED brightness. This is printed in serial monitor for feedback
Testing this with an LED strip
Longer Video of the system