Adaptive light

Made by Felicia Luo

The adaptive light will automatically dim itself if the surrounding is bright, and brighten itself if the surrounding is dark.

Created: November 7th, 2022

0

Outcome

  • This circuit has two inputs: the switch and the photoresistor, and one output: the LED. Reading of the photoresistor is available online. 
  • This prototype is meant to mimic an adaptive light: when turned on, it will sense the surrounding brightness and automatically dim itself if the surrounding is bright, or brighten itself if the surrounding is dark. 
  • The goal is achieved by reversely mapping the sensor reading (4095-2000) to the LED brightness (0-200). Only when the switch is on will this mapping happen. 

0
// define pins
int ledPin = D2;
int switchPin = D3;
int lightSensorPin = A2;
// create a variable to store light sensor reading
int lightReading = 0;
// create a variable to store LED brightness
int ledBrightness = 0;

void setup() {
    // define switchPin as INPUT_PULLUP
    pinMode(switchPin, INPUT_PULLUP);
    // define ledPin as OUTPUT
    pinMode(ledPin, OUTPUT);
    // create a cloud variable
    Particle.variable("light", lightReading);

}

void loop() {
    // read button state
    int buttonState = digitalRead(switchPin);
    
    if(buttonState == LOW){
        digitalWrite(ledPin, HIGH);
        
        // use analogRead to read light sensor (analogRead gives range 0-4095)
        lightReading = analogRead(lightSensorPin);
        
        // map lightReading to PWM range (0-255) and store it as ledBrightness
        ledBrightness = map(lightReading, 4095, 2000, 0, 255);
        
        // fade the LED to the desired brighness
        analogWrite(ledPin, ledBrightness);
        
        delay(100);
    }
    else{
        digitalWrite(ledPin, LOW);
    }
}
Click to Expand
0

Process

  • I first did not connect a resistor to the photoresistor in series, and I noticed the reading is always similarly high. After consulting with Daragh and fixing this issue, I also noticed that the LED brightness change is too subtle to tell. Daragh inspired me to map the reading from a smaller range, and the LED brightness change is there more obvious.
  • Thinking about a real-life implication, I changed the mapping to reverse. So the LED is considered as a light that responds to the surrounding.
0

Reflection

  • There are many more opportunities that can be added to this prototype. For example, a potentiator can be added to allow for manual control of the LED brightness. Another LED can be added to indicate if the adaptive LED is on or off, in case the surrounding is too bright and the adaptive one adjust itself to the darkest. 
x
Share this Project

Courses

About

The adaptive light will automatically dim itself if the surrounding is bright, and brighten itself if the surrounding is dark.