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
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
2. photoresistor
3.LED
4.resistor:220 ohm
5.resistor:10K ohm
6.the jumper
Wire Diagram
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);
}
}
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
Bright light environments
Results
Dark environments