Friday, May 1, 2015

How to make keypad , to programming with arduino to control servo with password

Post by

Click to see more project

In this project you can se how to make keypad using simple button
you will need :
1. Button
you can buy from here

2. prototybe board

3. some wire

Its simple project juct you need to connect button.
to see how to connect button see the photo .
1.connect pin 1 of  button 1 to pin1 of buton 3 . (one pin on keypad).
2.connect pin 1 of button 2 to pin 1 of button 4. (two pin on keypad).
3.connect pin 2 of button 1 to pin 1 of button 3. (three pin on keypad).

4.connect pin 2 of button 2 to pin 2 of button 4. (two pin on keypad).

2.How to make password keypad with arduino
3.How to control servo with keypad password and arduino

To make a password for servo with arduino its to easy just you need for simple code
#include // use password library
#include// //tells to use keypad library
#include //tells to use servo library

Servo myservo;                          //declares servo
Password password = Password( "12" );        //password to unlock box, can be change example "12121212"

const byte ROWS = 4; // Four rows
const byte COLS = 4; // columns
// Define the Keymap
char keys[ROWS][COLS] =

// Connect keypad ROW0, ROW1, ROW2 and ROW3 to these Arduino pins.
byte rowPins[ROWS] = {3, 2 };// Connect keypad COL0, COL1 and COL2 to these Arduino pins.
byte colPins[COLS] = {7, 6 };

// Create the Keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
pinMode(11, OUTPUT); //green light
pinMode(12, OUTPUT); //red light
myservo.attach(12); //servo on digital pin 9 //servo
keypad.addEventListener(keypadEvent); //add an event listener for this keypad

void loop(){
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){

Serial.print("Enter: ");


switch (eKey){
case '3': checkPassword();


case '4': password.reset();


default: password.append(eKey);

void checkPassword(){

if (password.evaluate())

 //if password is right open box

//Add code to run if it works
myservo.write(100);      //  servo will write 100 deg
digitalWrite(11, HIGH);//turn on
digitalWrite(11, LOW);// turn off


Serial.println("Denied");                    //if passwords wrong keep box locked

                                                             //add code to run if it did not work
myservo.write(0);                                // 0 deg
digitalWrite(12, HIGH);                     //turn on the led
delay(500);                                         //wait 5 seconds
digitalWrite(12, LOW);                      //turn off the led


The button four reset the password . When you write the password press button three its like "enter".
If the password Accepted servo will write 100 deg and green led will be hight for some second and will be low.
If passwords wrong red led will be hight for some second and will be low.

No comments:

Post a Comment