top of page

Light Controlled LED Code
void setup() {
Serial.begin(9600); //Begin in the serial monitor in to check light levels
}
void loop() {
int lightValue = analogRead(A0); //Read pin A0 to measure the signal returning from the light sensor
if (lightValue < 50) //If it gets darker that a value of 50
{
digitalWrite (8, HIGH); //Turn the light on
}
else
{
digitalWrite (8, LOW); //If it is not dark enough, leave the light off
}
delay (10);
}
bottom of page