Parts
-Arduino microcontroller and carrier board
-LiPo battery
-Photoresistor
-Jumper wires
-10kOhm resistor
Prepare the breadboard
Connect the photoresistor to GND, other leg to an A5.
Connect a resistor (around 10k is a good value, higher values gives higher readings) from pin 5 to +5V.
PhotoR 10K
GND o---/\/\/--.--/\/\/---o +5
|
Pin A5 o-----------
For a different setup:
Program the Microcontroller
/** * @file: photoresistor example * * @description * serial monitor output from photoresistor * turns LED off when it is dark * photoresistor, 100K resistor */
// include additional headers
//global declarations#define LED 13 //define a pin for LED#define PHOTOR 5 //define a pin for Photo resistorconst int threshold = 20; // will depend on what resistor is used
//--- Function: Setup ()void setup(){
pinMode(LED, OUTPUT); // setup LED Serial.begin(9600); // setup serial output}
//--- Function: loop ()void loop(){ Serial.println(analogRead(PHOTOR)); // reading values to serial monitor
if(analogRead(PHOTOR) > threshold ) { digitalWrite(LED, HIGH); // turns on LED when it is dark Serial.println("high"); } else { digitalWrite(LED, LOW); Serial.println("low"); } delay(200);}