Arduino Projects Ideas - Light Sensitive LED (LDR)

 
Arduino Projects Ideas - Light Sensitive LED (LDR)

Components:
LDR
10kΩ resistor
LED + 220Ω resistor
Arduino UNO

Wiring:
LDR between 5V and A0
10kΩ resistor between A0 and GND
LED on pin 13 with 220Ω resistor to GND

Code:

void setup() {
  pinMode(13, OUTPUT);
}
void loop() {
  int light = analogRead(A0);
  if(light < 500) {digitalWrite(13, HIGH);
  } else {digitalWrite(13, LOW);
  }
  delay(500);
}