int photocellPin = A0; int ledPin = 3; int val = 0; void setup() { pinMode(ledPin, OUTPUT); pinMode(photocellPin, INPUT); } void loop() { val = analogRead(photocellPin); if(val<=512) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } }