Devices & Components
Arduino Nano
4pin Photoresistor, LDR Module
Relay SPDT, 12 Volts
RGB led diode
Power MOSFET IRF740
Hardware & Tools
Soldering kit
Software & Tools
Arduino IDE
Project description
Code
Arduino code
cpp
...
1#define Solenoid 12 2#define ldr 8 3int Buzzer = 4; 4int GreenLed = 6; 5int RedLed = 11; 6int val; 7int val2; 8String duration; 9 10void setup() { 11 // put your setup code here, to run once: 12 Serial.begin(9600); 13 pinMode(ldr, INPUT_PULLUP); 14 pinMode(Solenoid, OUTPUT); 15 pinMode(GreenLed, OUTPUT); 16 pinMode(RedLed, OUTPUT); 17 digitalWrite(RedLed, HIGH); 18} 19 20 void OpenDoor(){ //Lock opening function open for 3s 21 22 digitalWrite(Solenoid,HIGH); 23 tone(Buzzer, 500); 24 digitalWrite(RedLed, LOW); 25 digitalWrite(GreenLed, HIGH); 26 27 delay(3000); 28 digitalWrite(Solenoid,LOW); 29 noTone(Buzzer); 30 digitalWrite(RedLed, HIGH); 31 digitalWrite(GreenLed, LOW); 32} 33 34void loop() { 35 // put your main code here, to run repeatedly: 36 int val = digitalRead(ldr); 37 while(val == 0) 38 { 39 int val2 = digitalRead(ldr); 40 duration += val2; 41 42 if(duration == "0001") 43 { 44 45 OpenDoor(); 46 } 47 48 if(val2 == 1) 49 { 50 duration = ""; 51 break; 52 } 53 54 55 delay(200); 56 } 57 58}
Downloadable files
Schematic
...
Schematic1.jpg

Comments
Only logged in users can leave comments