Photoresistor

From SainSmart Wiki
Jump to: navigation, search

Photoresistor

What’s photoresistor?

Photoresistor, also known as light pipes, common production materials is cadmium sulfide, There are also selenium, aluminum sulfide, lead sulfide and bismuth sulfide material. these production materials having characteristics in light of a specific wavelength, its resistance decreases rapidly. This is due to the light generated carriers are involved in the electrical conductivity, under the applied electric field drift motion, so that the photosensitive resistor rapid decline.

QQ图片20130716181126.jpg

Experiment component

  • Photoresistor : 1
  • Buzzer : 1
  • 10K resistor : 1
  • 220Ω resistor : 1
  • Breadboard & Jumper wires

Connect your circuit as the below diagram.

QQ图片20130716181141.jpg

Example code:

int photocellPin = 2; //define photocellsh=2, read the value of voltage. int ledPin = 12; //define ledPin12 is the output port of led’s level. int val = 0; //define original of val.


void setup() {

 pinMode(ledPin, OUTPUT);  //set ledPin output

}

void loop() {

 val = analogRead(photocellPin);    //get the value from sensor
   if(val<=512){             

//512=2.5V, if want the sensor be more sensitive, increase the number, or lese low the number.

   digitalWrite(ledPin, HIGH); //when the value of val is less than 512(2.5V), light up led lamp
   } 
   else{ 
   digitalWrite(ledPin, LOW);
   } 

}