Hackpads are smart collaborative documents. .

Donald Undeen

118 days ago
Unfiled. Edited by Donald Undeen 118 days ago
 
 
 
 
Read the Photoresistor
Don U
  • /* Simple test of the functionality of the photo resistor
  • Connect the photoresistor one leg to pin 0, and pin to +5V
  • Connect a resistor (around 10k is a good value, higher
  • values gives higher readings) from pin 0 to GND. (see appendix of arduino notebook page 37 for schematics).
  • */
 
  • int lightPin = 0;  //define a pin for Photo resistor
  • int ledPin=11;     //define a pin for LED
  •  
  • void setup()
  • {
  •     Serial.begin(9600);  //Begin serial communcation
  •     pinMode( ledPin, OUTPUT );
  • }
  •  
  • void loop()
  • {
Donald U
  •     int photocellreading = analogRead(lightPin);
Don U
  •     Serial.println(photocellreading); //Write the value of the photoresistor to the serial monitor.
  •    delay(10); //short delay for faster response to light.
  • }
 
PhotoResister controlling LED, #1
 
  • {
Donald U
  •     int photocellreading = analogRead(lightPin);
  •  
  •     Serial.println(photocellreading); //Write the value of the photoresistor to the serial monitor.
  •     analogWrite(ledPin, photocellreading/2);  //send the value to the ledPin. Depending on value of resistor 
 
  • {
  •     int photocellreading = analogRead(lightPin);
  •  
  •     Serial.println(photocellreading); //Write the value of the photoresistor to the serial monitor.
 
131 days ago

Contact Support



Please check out our How-to Guide and FAQ first to see if your question is already answered! :)

If you have a feature request, please add it to this pad. Thanks!


Log in