Friday, May 1, 2015

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

Post by http://arduinoo.tk/

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
code:
#include //http://playground.arduino.cc/uploads/Code/Password.zip use password library
#include//http://www.arduino.cc/playground/uploads/Code/Keypad.zip //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] =

{
{'1','2'},
{'3','4'},
};
// 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(){
Serial.begin(9600);
Serial.write(254);
Serial.write(0x01);
delay(200);
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(){
keypad.getKey();
myservo.write(0);
}
//take care of some special events
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){
case PRESSED:

Serial.print("Enter: ");
Serial.println(eKey);
delay(10);

Serial.write(254);

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

delay(1);
 break;

case '4': password.reset();

 delay(1);
 break;

default: password.append(eKey);

 delay(1);
}
}
}
void checkPassword(){

if (password.evaluate())

{
 //if password is right open box

Serial.println("Accepted");
Serial.write(254);delay(100);
//Add code to run if it works
myservo.write(100);      //  servo will write 100 deg
delay(700);
digitalWrite(11, HIGH);//turn on
digitalWrite(11, LOW);// turn off


}

else
{
Serial.println("Denied");                    //if passwords wrong keep box locked
Serial.write(254);

delay(10);
                                                             //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