Dev: Night Flower

Inspiration

Pictures: Flowers Glow Under UV-Induced Visible Fluorescence

Source: Read more in this article 

For this weeks assignment I drew inspiration from this kind of night glowing flowers that only bloom up at night in the absence of sunlight/UV light. I wanted to create something similar with LED and the photo sensor in order to glow up the flower in the absence of light. In order to do this I had to use a photosensor add mad the brightness on to the range of values between 0 and 255.

This also allowed me to control the brightness level as the intensity of light changed. As shown in the video below I wanted to mimic a sunrise and sunset effect where the flower would brighten up as the environment becomes darker.

Implementation

I started by hooking up a LED and a push down button with the basic on off implementation. On top of this I used a photosensor in a 10k resistor for the connection on the circuit. The LED and button served as digital input to read data into the program while the photo center served as analog input for this project. In order to control the light I thought of doing something different than the traditional HIGH and LOW method. I thought of implementing it by varrying its light value depending on the brightness level. This was done by using analogWrite by sending the mapped light value to the LED pin.

As shown in the code below I tried to play around with the values in order to map it in a way that allowed the brightness to smoothly transition and show the dimming and fading feature. (Although this is was very satisfying for me unfortunately the camera on my phone was not able to capture the dimming effect).

Demo Video

Arduino Code

int led = 3; // LED pin 
int ldr = A0; // LDR pin
int button = 5; // Button pin
bool on = false; // Boolean variable for the state of the LED 

void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT); // Set the LED pinmode
  pinMode(ldr, INPUT); // Set the LDR pinmode
  pinMode(button, INPUT); // Set the button pinmode
}
void loop() {
  
// read the brightness from the ldr
  int brightness = analogRead(ldr);
// check if switch is clicked
  if (on == false && digitalRead(button)== HIGH){
    on = true; // Setting on to be true
  }
  if (on == true && digitalRead(button) == HIGH){
    on = false;  // Setting on to be false
  }

   int mappedLightValue = map(brightness, 60, 700, 255, 0); // nothing the brightness onto the range 0 to 255 but in reverse order
  // if switch is clicked, then proceed 
  if (on==true){ // if the on state is true
    if (brightness < 370) { // 
      analogWrite(led, mappedLightValue); // writing the lights value to the LED pin
//      Serial.println(mappedLightValue); // call printing out the mapped light value for checking
    }
    else {
      digitalWrite(led, LOW); // turning the light off if it's too bright
    }
  }
  else if (on==false) {digitalWrite(led, LOW);}  // Setting the on state to be false otherwise
}

 

 

Leave a Reply