Introduction: Arduino Photoresistor LED On/off
this is another simple arduino project that turn on light when it's dark and turn off when is light))
Step 1: Materials
You will need:
Arduino
Breadboard
2x 240ohm resistors
1x Clear White l.e.d
1x photoresistor
Some Jumper Cables
Step 2: Circuite
Step 3: The Code
//photoresistor A Style Tech.
int Pr = 0; // will be used for analog 0.
int PrValue = 0; // value of output
int Pr_Input = 19; // value of when light is on
void setup() {
Serial.begin(9600); //start serial Monitor
pinMode(8, OUTPUT); // pin 8 as output
}
void loop() {
PrValue = analogRead(Pr);
Serial.println(PrValue); //prints photoresistor value
delay(100); // value updated every 0.1 second.
if (PrValue < Pr_Input) // if sensor value is less than 19, light will turn on.
{ digitalWrite(8, HIGH);//LED on } else { digitalWrite(8, LOW);// LED off }
}
Step 4: Finish!!
if all went well, try to add more leds
and change sensitivity of photoresistor " int Pr_Input = 19; // value of when light is on"
GOOD LUCK! ;)