Hello Friends,
This project is for password/PIN protected Parking gate. This is very interesting project. I hope you like it.
Material:
Arduino UNO - 1 No.
Servo Motor - 1 No.
IR Sensor - 1 No.
4x4 Keypad - 1 No.
9V Battery - 1 No.
Toy Car - As per your wish.
10 Kohm Resistor - 1 No.
Sketch:
// This code is for password/PIN protected Parking Gate.
#include <Keypad.h>
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int exitSensor= 10; // pin 10 is connected to out sensor, when vehicle is passed after toll crossing
//******************************************************** keypad initialisation ************************************
char* password = "1245"; // if this is changed then modification is needed in loop section validating the keys
const byte ROWS = 4; //four rows
const byte COLS = 4; //three columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
int position = 0;
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
//******************************************************** Setup ************************************
void setup(){
Serial.begin(9600); // communication is initialised
pinMode(13, OUTPUT); // Sets the digital pin as output, if used, optional.
pinMode(exitSensor,INPUT); // exitSensor is set a Input, extra resistor are required, it can be used as high or low.
myservo.attach(12); // servo is attached this pin 12
}
//******************************************************** Loop ************************************
void loop(){
int exitStatus = digitalRead(exitSensor); // it senses the exit sensor after crossing the toll gate
char key = keypad.getKey();
if(key == '*' || key == '0' || key == '3' || key == '6' || key == '7' || key == '8' || key == '9' || key == 'A' || key == 'B' || key == 'C' || key == 'D' || key == '#' || exitStatus == 1) // if these keys are pressed and exitStatus goes low then it will close the gate
{
position = 0; //if wrong key is pressed then position (variable will be zero and password count will start again
myservo.write(175); // if wrong key is pressed then gate will close
}
if(key == password[position])
{
position ++; // if correct key is pressed then position is increased
}
if(position == 4) // when position is equal to 4 means, correct digits are pressed then next command is executed
{
myservo.write(90); // when position is equal to 4 means, then motor moves to the angle 90, however it can be changed
}
delay(10);
}
// ****************** end of the sketch **********************
Comments
Post a Comment