Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Aayush Sharma
Published © LGPL

Password-Protected, Arduino-Controlled Servo Gate

This project is about servo motors which are controlled by a push button. The servo motors only work when a certain algorithm is followed.

IntermediateFull instructions provided1 hour4,989
Password-Protected, Arduino-Controlled Servo Gate

Things used in this project

Story

Read more

Schematics

arduino controlled password protected gate

circuit diagram

Code

arduino code for password protected gate

Arduino
#include<Servo.h>
Servo myservo;
Servo myservo1;

  int led1=5;
  int led2=6;
  int led3=7;
  int push1=2;
  int push2=3;
  int push3=4;
  int push4=A4;
  int counter1=0;
  int counter2=0;
  int counter3=0;
   int counter4=0;
  

void setup() {
  // put your setup code here, to run once:

  pinMode(led1,OUTPUT);
  pinMode(led2,OUTPUT);
  pinMode(led3,OUTPUT);
    pinMode(push1,INPUT);
        pinMode(push2,INPUT);
            pinMode(push3,INPUT);
             pinMode(push4,INPUT);
            Serial.begin(9600);
            myservo.attach(9);
          
                 myservo1.attach(10);
  

}

void loop() {
  int buttonState1=digitalRead(push1);
   int buttonState2=digitalRead(push2);
    int buttonState3=digitalRead(push3);
       int buttonState4=digitalRead(push4);
    
if(buttonState1==1){
  
  counter1=1;
  }
      
if(buttonState1==1 && buttonState3==1){
  
  counter2=2;
  }
  if(buttonState2==1 && buttonState3==1){
  
  counter3=3;
  }

if(buttonState4==1){
  
  counter4=4;
  
  }






    
Serial.println("counter2");
Serial.println(counter2);
delay(50);
Serial.println("counter1");
Serial.println(counter1);
delay(50);
Serial.println("counter3");
Serial.println(counter3);
delay(50);



if(counter1==1 && counter2==2 && counter3==3){
  digitalWrite(led1,HIGH);
  digitalWrite(led2,HIGH);
  digitalWrite(led3,HIGH);
  myservo.write(90);
    myservo1.write(0);
     
  
  
  
  }
  else{
      digitalWrite(led1,LOW);
  digitalWrite(led2,LOW);
  digitalWrite(led3,LOW);
  myservo.write(0);
    myservo1.write(75);
     
    
  
    
    
    }
    if(buttonState4==1){
      counter1=0;
      counter2=0;
      counter3=0;
      
      
      

      }
    

Serial.println("buttonState4");
Serial.println(buttonState4);
delay(50);

}




    

Credits

Aayush Sharma
2 projects • 10 followers
My name is Aayush Sharma ..I love to work with Electronics and make cool and awesome gadgets. i create random project tutorial videos.
Contact

Comments

Please log in or sign up to comment.