loading

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! ;)

<p>Can I use 12v led strips ?</p>
<p>This is a very nice and simple project. I built it onto a PCB, and used terminals for the LED and for the photo resistor, so that I can change them or extend the wires without having to solder anything</p>
<p>Made it.... I am currently testing how how many/what type of LED will work on this setup. I would like to see if I can get something like the LED light bars but only a 4 LED pod to work on something like this. But thanks for the easy write up and how to..</p>
<p>Any one else getting this message, when trying to load the code</p><p>Arduino: 1.6.5 (Windows 8.1), Board: &quot;Arduino Uno&quot;<br><br>sketch_feb23a.ino: In function 'void loop()':<br>sketch_feb23a:37: error: expected '}' at end of input<br>expected '}' at end of input<br><br> This report would have more information with<br> &quot;Show verbose output during compilation&quot;<br> enabled in File &gt; Preferences.</p>
<p>int Pr = 0; // will be used for analog 0.</p><p>int PrValue = 0; // value of output</p><p>int Pr_Input = 19; // value of when light is on</p><p>void setup() {</p><p>Serial.begin(9600); //start serial Monitor</p><p>pinMode(8, OUTPUT); // pin 8 as output</p><p>}</p><p>void loop() {</p><p>PrValue = analogRead(Pr);</p><p>Serial.println(PrValue); //prints photoresistor value</p><p>delay(100); // value updated every 0.1 second.</p><p>if (PrValue &lt; Pr_Input) {</p><p>digitalWrite(8, HIGH);</p><p>} else {</p><p>digitalWrite(8, LOW); }</p><p>}</p>
<p>USE THIS </p><p>int Pr = 0; // will be used for analog 0.</p><p>int PrValue = 0; // value of output</p><p>int Pr_Input = 19; // value of when light is on</p><p>void setup() {</p><p>Serial.begin(9600); //start serial Monitor</p><p>pinMode(8, OUTPUT); // pin 8 as output</p><p>}</p><p>void loop() {</p><p>PrValue = analogRead(Pr);</p><p>Serial.println(PrValue); //prints photoresistor value</p><p>delay(100); // value updated every 0.1 second.</p><p>if (PrValue &lt; Pr_Input) {</p><p>digitalWrite(8, HIGH);</p><p>} else {</p><p>digitalWrite(8, LOW); }</p><p>}</p>

About This Instructable

32,150views

25favorites

License:

More by A Style Tech:Arduino Photoresistor LED on/off Simple Arduino LED Flag Flasher 
Add instructable to: