Skip to content

Commit 669dd0d

Browse files
Create LED Control with LDR.ino
1 parent c309e35 commit 669dd0d

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

LED Control with LDR.ino

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
const int ledPin = 13; //the number of the LED pin
2+
const int ldrPin = A0; //the number of the LDR pin
3+
4+
5+
void setup() {
6+
7+
Serial.begin(9600);
8+
pinMode(ledPin, OUTPUT); //initialize the LED pin as an output
9+
pinMode(ldrPin, INPUT); //initialize the LDR pin as an input
10+
}
11+
12+
void loop() {
13+
14+
int ldrStatus = analogRead(ldrPin); //read the status of the LDR value
15+
16+
//check if the LDR status is <= 300
17+
//if it is, the LED is HIGH
18+
19+
if (ldrStatus <=300) {
20+
21+
digitalWrite(ledPin, HIGH); //turn LED on
22+
Serial.println("LDR is DARK, LED is ON");
23+
24+
}
25+
else {
26+
27+
digitalWrite(ledPin, LOW); //turn LED off
28+
Serial.println("---------------");
29+
}
30+
}

0 commit comments

Comments
 (0)