Devices & Components
Arduino Uno Rev3
LDR, 5 Mohm
Resistor 1k ohm
Jumper wires (generic)
Breadboard (generic)
LED, Blue
Software & Tools
Arduino IDE
Project description
Code
Code
c_cpp
1/*Inventor DIY Inventor (Krishna Agarwal) 2Desingner DIY Inventor (Krishna Agarwal) 3Codder DIY Inventor (Krishna Agarwal) 4*/ 5 6//set pin numbers 7//const won't change 8const int ledPin = 12; //the number of the LED pin 9const int ldrPin = A0; //the number of the LDR pin 10 11 12void setup() { 13 14 Serial.begin(9600); 15 pinMode(ledPin, OUTPUT); //initialize the LED pin as an output 16 pinMode(ldrPin, INPUT); //initialize the LDR pin as an input 17} 18 19void loop() { 20 int ldrStatus = analogRead(ldrPin); //read the status of the LDR value 21 22 //check if the LDR status is <= 500 23 //if it is, the LED is HIGH 24Serial.println(ldrStatus); 25/*Inventor DIY Inventor (Krishna Agarwal) 26Desingner DIY Inventor (Krishna Agarwal) 27Codder DIY Inventor (Krishna Agarwal) 28*/ 29 if (ldrStatus <=80) { 30 31 digitalWrite(ledPin, HIGH); //turn LED on 32 33 } 34 else { 35 36 digitalWrite(ledPin, LOW); //turn LED off 37 } 38} 39
Code
c_cpp
1/*Inventor DIY Inventor (Krishna Agarwal) 2Desingner DIY Inventor (Krishna Agarwal) 3Codder DIY Inventor (Krishna Agarwal) 4*/ 5 6//set pin numbers 7//const won't change 8const int ledPin = 12; //the number of the LED pin 9const int ldrPin = A0; //the number of the LDR pin 10 11 12void setup() { 13 14 Serial.begin(9600); 15 pinMode(ledPin, OUTPUT); //initialize the LED pin as an output 16 pinMode(ldrPin, INPUT); //initialize the LDR pin as an input 17} 18 19void loop() { 20 int ldrStatus = analogRead(ldrPin); //read the status of the LDR value 21 22 //check if the LDR status is <= 500 23 //if it is, the LED is HIGH 24Serial.println(ldrStatus); 25/*Inventor DIY Inventor (Krishna Agarwal) 26Desingner DIY Inventor (Krishna Agarwal) 27Codder DIY Inventor (Krishna Agarwal) 28*/ 29 if (ldrStatus <=80) { 30 31 digitalWrite(ledPin, HIGH); //turn LED on 32 33 } 34 else { 35 36 digitalWrite(ledPin, LOW); //turn LED off 37 } 38} 39
Downloadable files
Circuit Diagram
Connection of LED Connect to Long Pin (+5V Pin) of LED to (Pin 12) of Arduino Connect to Small Pin (GND Pin) of LED to (GND) of Arduino Connection of LDR Connect LDR (Any One Pin) to (+5V) Of Arduino Connect 1K Resistor to Another Pin OF LDR and Connect Resistor Pin to GND of Arduino Connect Ldr 2 Pin To A0 Of Arduino
Circuit Diagram

Comments
Only logged in users can leave comments