We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent c309e35 commit 669dd0dCopy full SHA for 669dd0d
LED Control with LDR.ino
@@ -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