/* NightLight Turn an LED on when the ambient light is below a certain value. */ const int lightThreshold = 800; // value below which LED turns on const int inputPin = A0; // use analog 0 (A0) as input pin const int ledPin = 13; // connect the LED to pin 13 int lightLevel = 0; // used to store the input value void setup() { pinMode(ledPin, OUTPUT); // make LED's pin an output } void loop() { lightLevel = analogRead(inputPin); // get an analog reading if (lightLevel <= lightThreshold) digitalWrite(ledPin, HIGH); // turn the LED on else digitalWrite(ledPin, LOW); // turn the LED off }