Devices & Components
Arduino Uno Rev3
Resistor 100 ohm
Breadboard (generic)
Photo resistor
Jumper wires (generic)
LED (generic)
Resistor 1k ohm
Software & Tools
Arduino Web Editor
Arduino IDE
Project description
Code
LED_PR_Light_Read
arduino
1int light = 0; // store the current light value 2 3void setup() { 4 // put your setup code here, to run once: 5 Serial.begin(9600); //configure serial to talk to computer 6 pinMode(13, OUTPUT); // configure digital pin 13 as an output 7 pinMode(12, OUTPUT); // configure digital pin 12 as an output 8} 9 10void loop() { 11 // put your main code here, to run repeatedly: 12 light = analogRead(A0); // read and save value from PR 13 14 Serial.println(light); // print current light value 15 16 if(light > 450) { // If it is bright... 17 Serial.println("It is quite light!"); 18 digitalWrite(13,LOW); //turn left LED off 19 digitalWrite(12,LOW); // turn right LED off 20 } 21 else if(light > 229 && light < 451) { // If it is average light... 22 Serial.println("It is average light!"); 23 digitalWrite(13, HIGH); // turn left LED on 24 digitalWrite(12,LOW); // turn right LED off 25 } 26 else { // If it's dark... 27 Serial.println("It is pretty dark!"); 28 digitalWrite(13,HIGH); // Turn left LED on 29 digitalWrite(12,HIGH); // Turn right LED on 30 } 31 delay(1000); // don't spam the computer! 32}
Downloadable files
Component Setup
Component Setup

Component Setup
Component Setup

Comments
Only logged in users can leave comments