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

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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

2 People Made This Project!

Recommendations

  • Made with Math Contest

    Made with Math Contest
  • Multi-Discipline Contest

    Multi-Discipline Contest
  • Robotics Contest

    Robotics Contest

6 Discussions

None
jagganath

1 year ago

there are several TYPES of photoresistor, from GL5506 to GL5539. Which one did you use? and which one is the best?

None
RăzvanN4

2 years ago

Can i make the same project (photoresistor-LED-on/off) combined with a speedometer, using the same arduino board and the same breadboard?

None
HarDizzeR

2 years ago

Can I use 12v led strips ?

None
Lionbait

3 years ago

Any one else getting this message, when trying to load the code

Arduino: 1.6.5 (Windows 8.1), Board: "Arduino Uno"

sketch_feb23a.ino: In function 'void loop()':
sketch_feb23a:37: error: expected '}' at end of input
expected '}' at end of input

This report would have more information with
"Show verbose output during compilation"
enabled in File > Preferences.

1 reply
None
PaigeK8Lionbait

Reply 3 years ago

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) {

digitalWrite(8, HIGH);

} else {

digitalWrite(8, LOW); }

}

None
PaigeK8

3 years ago

USE THIS

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) {

digitalWrite(8, HIGH);

} else {

digitalWrite(8, LOW); }

}