Devices & Components
Arduino Uno Rev3
Resistor 10k ohm
LED (generic)
Breadboard (generic)
Jumper wires (generic)
Pushbutton switch 12mm
Servos (Tower Pro MG996R)
Project description
Code
arduino code for password protected gate
arduino
1#include<Servo.h> 2Servo myservo; 3Servo myservo1; 4 5 int led1=5; 6 int led2=6; 7 int led3=7; 8 int push1=2; 9 int push2=3; 10 int push3=4; 11 int push4=A4; 12 int counter1=0; 13 int counter2=0; 14 int counter3=0; 15 int counter4=0; 16 17 18void setup() { 19 // put your setup code here, to run once: 20 21 pinMode(led1,OUTPUT); 22 pinMode(led2,OUTPUT); 23 pinMode(led3,OUTPUT); 24 pinMode(push1,INPUT); 25 pinMode(push2,INPUT); 26 pinMode(push3,INPUT); 27 pinMode(push4,INPUT); 28 Serial.begin(9600); 29 myservo.attach(9); 30 31 myservo1.attach(10); 32 33 34} 35 36void loop() { 37 int buttonState1=digitalRead(push1); 38 int buttonState2=digitalRead(push2); 39 int buttonState3=digitalRead(push3); 40 int buttonState4=digitalRead(push4); 41 42if(buttonState1==1){ 43 44 counter1=1; 45 } 46 47if(buttonState1==1 && buttonState3==1){ 48 49 counter2=2; 50 } 51 if(buttonState2==1 && buttonState3==1){ 52 53 counter3=3; 54 } 55 56if(buttonState4==1){ 57 58 counter4=4; 59 60 } 61 62 63 64 65 66 67 68Serial.println("counter2"); 69Serial.println(counter2); 70delay(50); 71Serial.println("counter1"); 72Serial.println(counter1); 73delay(50); 74Serial.println("counter3"); 75Serial.println(counter3); 76delay(50); 77 78 79 80if(counter1==1 && counter2==2 && counter3==3){ 81 digitalWrite(led1,HIGH); 82 digitalWrite(led2,HIGH); 83 digitalWrite(led3,HIGH); 84 myservo.write(90); 85 myservo1.write(0); 86 87 88 89 90 } 91 else{ 92 digitalWrite(led1,LOW); 93 digitalWrite(led2,LOW); 94 digitalWrite(led3,LOW); 95 myservo.write(0); 96 myservo1.write(75); 97 98 99 100 101 102 } 103 if(buttonState4==1){ 104 counter1=0; 105 counter2=0; 106 counter3=0; 107 108 109 110 111 } 112 113 114Serial.println("buttonState4"); 115Serial.println(buttonState4); 116delay(50); 117 118} 119 120 121 122 123
arduino code for password protected gate
arduino
1#include<Servo.h> 2Servo myservo; 3Servo myservo1; 4 5 int led1=5; 6 7 int led2=6; 8 int led3=7; 9 int push1=2; 10 int push2=3; 11 int push3=4; 12 13 int push4=A4; 14 int counter1=0; 15 int counter2=0; 16 int counter3=0; 17 18 int counter4=0; 19 20 21void setup() { 22 // put your setup code here, 23 to run once: 24 25 pinMode(led1,OUTPUT); 26 pinMode(led2,OUTPUT); 27 pinMode(led3,OUTPUT); 28 29 pinMode(push1,INPUT); 30 pinMode(push2,INPUT); 31 pinMode(push3,INPUT); 32 33 pinMode(push4,INPUT); 34 Serial.begin(9600); 35 myservo.attach(9); 36 37 38 myservo1.attach(10); 39 40 41} 42 43void loop() 44 { 45 int buttonState1=digitalRead(push1); 46 int buttonState2=digitalRead(push2); 47 48 int buttonState3=digitalRead(push3); 49 int buttonState4=digitalRead(push4); 50 51 52if(buttonState1==1){ 53 54 counter1=1; 55 } 56 57if(buttonState1==1 58 && buttonState3==1){ 59 60 counter2=2; 61 } 62 if(buttonState2==1 && buttonState3==1){ 63 64 65 counter3=3; 66 } 67 68if(buttonState4==1){ 69 70 counter4=4; 71 72 73 } 74 75 76 77 78 79 80 81Serial.println("counter2"); 82Serial.println(counter2); 83delay(50); 84Serial.println("counter1"); 85Serial.println(counter1); 86delay(50); 87Serial.println("counter3"); 88Serial.println(counter3); 89delay(50); 90 91 92 93if(counter1==1 94 && counter2==2 && counter3==3){ 95 digitalWrite(led1,HIGH); 96 digitalWrite(led2,HIGH); 97 98 digitalWrite(led3,HIGH); 99 myservo.write(90); 100 myservo1.write(0); 101 102 103 104 105 106 } 107 else{ 108 digitalWrite(led1,LOW); 109 digitalWrite(led2,LOW); 110 111 digitalWrite(led3,LOW); 112 myservo.write(0); 113 myservo1.write(75); 114 115 116 117 118 119 120 } 121 if(buttonState4==1){ 122 counter1=0; 123 124 counter2=0; 125 counter3=0; 126 127 128 129 130 } 131 132 133 134Serial.println("buttonState4"); 135Serial.println(buttonState4); 136delay(50); 137 138} 139 140 141 142 143 144
Downloadable files
arduino controlled password protected gate
circuit diagram
arduino controlled password protected gate

Comments
Only logged in users can leave comments