Devices & Components
Arduino Uno Rev3
Breadboard (generic)
Resistor 1k ohm
LDR, 5 Mohm
Jumper wires (generic)
Relay Module (Generic)
LED Light Bulb, Frosted GLS
Software & Tools
Arduino IDE
Project description
Code
Relay LDR
h
1int sensorPin = A0; 2int relayPin = 8; 3 4void setup() 5{ 6 7 Serial.begin(9600); 8 pinMode(sensorPin, INPUT); 9 pinMode(relayPin, OUTPUT); 10} 11void 12 loop() 13{ 14 int sensorValue = analogRead(sensorPin); 15 if( sensorValue 16 <= 25 ) // Change the value as per your requirement 17 { 18 digitalWrite(relayPin, 19 LOW); 20 Serial.println(sensorValue); 21 delay(100); 22 } 23 else 24 25 { 26 digitalWrite(relayPin, HIGH); 27 Serial.println(sensorValue); 28 29 } 30} 31
Relay LDR
h
1int sensorPin = A0; 2int relayPin = 8; 3 4void setup() 5{ 6 Serial.begin(9600); 7 pinMode(sensorPin, INPUT); 8 pinMode(relayPin, OUTPUT); 9} 10void loop() 11{ 12 int sensorValue = analogRead(sensorPin); 13 if( sensorValue <= 25 ) // Change the value as per your requirement 14 { 15 digitalWrite(relayPin, LOW); 16 Serial.println(sensorValue); 17 delay(100); 18 } 19 else 20 { 21 digitalWrite(relayPin, HIGH); 22 Serial.println(sensorValue); 23 } 24} 25
Downloadable files
Relay LDR
Check this Connection
Relay LDR

Comments
Only logged in users can leave comments