Week 9 – “Sunlight” meter


My concept for this homework was inspired by the “Oasis” project which imitates a robotic flower that blooms only at night. For my project, I decided to create a”Sunlight” meter for the plants that warns when there’s not enough light around to conduct photosynthesis, and provides a solution in the form of an artificial “sunlight. I use a light sensor as an analog sensor to measure the “sunlight”, and if it will be below the standard brightness threshold needed for photosynthesis, there will be a RED warning light coming from a blinking red LED. Also, I’m also using a switch and two other yellow LEDs. Yellow LEDs are placed around the light sensor to imitate artificial sunlight such that when the user presses the switch (i.e. when there’s not enough light around for the plant to perform photosynthesis), those two yellow LEDs will light up and will provide artificial sunlight for the plant.  P.S. I am not using anything to indicate a plant in this project as I don’t have any plant in my room, but this arduino board can be placed near any plant easily tom measure the light around.


Video Demonstration



const int threshold = 150; //threshold for turning on the warning 

void setup()
     pinMode(5,OUTPUT); //LED that signals the warning
     pinMode(7,OUTPUT); //light LED 1
     pinMode(8,OUTPUT); //light LED 2

     pinMode(A0,INPUT); //switch
     pinMode(A1,INPUT); //light sensor

void loop()
    //reading analog voltage from the light sensor and storing it in an integer 
    int sensorValue  = analogRead(1);

    //scale sensorValue, which is btw 0 to 1023, to values btw 0 to 255 form analogWrite funtion which only receives  values btw this range
    int brightness = map(sensorValue, 0, 1023, 0, 255); 

    //if the light sensor's brightness value will be less than threshold value
    if(brightness < threshold){

      //make the warning red LED blink
      digitalWrite(5, HIGH);
      digitalWrite(5, LOW);

    } else{
      digitalWrite(5, LOW);

  //switch will be a digital sensor
  int switchPosition = digitalRead(A0);

  //when the switch will be pressed, two yellow LEDs surrounding the light sensor will light up, imitating a sunlight
  if (switchPosition == HIGH) {
    digitalWrite(7, HIGH);
    digitalWrite(8, HIGH);
  else {
    digitalWrite(7, LOW);
    digitalWrite(8, LOW);



Leave a Reply