Night Light – Solution

Night Light LED Wiring Diagram
/*NAME
Photocell Project
Engineering Period 1
DATE

Revision History
DATE  |    NAME    |     Changes Made
------|------------|------------------------------
TODAY |  My Name   |  Initial Implementation
*/

// the setup routine runs once when you press reset or apply power:
void setup() {
     // initialize serial communication at 9600 bits per 
     //second:
     Serial.begin(9600);
     //Set pin A0 For Input - Allow us to read the value
     pinMode(A0, INPUT);
     //Set the digital pin out LED is connected to as 
     //output
     pinMode(8,OUTPUT);

}

void LedOn(){
     digitalWrite(8,HIGH);
}
void LedOff(){
     digitalWrite(8,LOW);
}

// the loop routine runs over and over again forever:
void loop() {
 
     // read the input on analog pin 0:
     int sensorValue = analogRead(A0);

     //Send the output to the Serial Port
     Serial.println(sensorValue);

     //Convert the sesorValue to volts
     int sensorVolts=sensorValue*(5.0/1023);
     
     if(sensorVolts<2.0){
          //It's dark  turn on the LED!
          LedOn();
     }else{
          //It's bright enough -> turn the LED Off
          LedOff();
     }
}