Experiment 7: Light Control of LED Switch

by pcduino in Workshop > Lighting

1908 Views, 12 Favorites, 0 Comments

Experiment 7: Light Control of LED Switch

light.jpg

Photoresistor is a special resistor, it referred to light resistance also , and its resistance related to the intensity of light directly; light intensity increases, the resistance reduction; light intensity decreases, the resistance increases.

Here, we take a look at using the photoresistor to make a LED light control switch.

 

 

Parts List

1. PcDuino experimental platform

2. photoresistor

3.LED

4.resistor:220 ohm

5.resistor:10K ohm

6.the jumper

Wire Diagram

LDR.jpg

Sample Code

 
int photoresistancePin = 0;
int ledPin = 11;
int val = 0;
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
val = analogRead(photoresistancePin);
if(val<=40){
digitalWrite(ledPin, LOW);
}
else{
digitalWrite(ledPin, HIGH);
}
}

Results

4148-1024x768-300x225.jpg
Bright light environments

Results

IMG_4149-1024x768-300x2258.jpg
Dark environments