Introduction: Interfacing Keypad With Arduino. [Unique Method]
Hello, and welcome to my first instructable ! :)
In this instructables I would like to share an awesome library for interfacing keyboard with arduino - 'Password library' including 'Keypad Library' . This library includes the best features that we will be discussing in the further steps. this library would be best suited for those who want to set some keypad based passwords for enter and exit doors, lockers, or even for experimental purpose also. Using this Library we can even count the ('key press and hold state' and even modify the duration!). isn't that cool.. I know you are exited... Lets dive-in.
This is a unique method because: this saves a lot of code lines, hence reducing complexity. Both setting password and reading keypad's input will become very easy by using this method, etc. In one word: Its Unique.
I hope this project will open the doors for many of creative personnel including you.
Don't worry if you are just a beginner or have no knowledge on Arduino. I have a solution for you- at the end.
Step 1: Parts Required
Components and Modules:
- Arduino UNO.
- 4*4 matrix Keypad.
- RGB LED.
- two 330 ohm resistor
- Jumper wires.
- Bread board.
- USB cable (A-B)type.
- Arduino IDE.
- Password & Keypad library for Arduino.
(you can download the software in step-3.)
I would suggest you to buy at www.banggood.com | the prices are comparatively very less here.
Step 2: Detailed Theory and Acronyms Used
It is a micro-controller based open source platform offered by Arduino.CC. It has ATMEGA328 micro-controller as its CPU, 32kB flash, 1kB EEPROM & 2kB SRAM,14 digital and 6 analog I/O. Arduino has to be programmed in its own IDE made by Arduino.cc. Programs are very simple and easy, this makes other sensors and output devices easy to interface. It is very popular platform to the modern automated world. find more information about Arduino from here: https://www.arduino.cc/en/Guide/Introduction
In this project arduino is used to control the RGB LED to glow when the password entered is true (Green light), if the password entred is false then the RGB LED would glow red(Red light). So the arduino is even Reading the input keys from the keyboard to get the password.
4x4 Matrix keypad:
Matrix Keypad is one of the most popular device that used to enter numeric or alpha-numeric keys. The term matrix came because the keypad's internal switches is connected to each other in a matrix of 'Rows and Columns'. 4x4 indicates the number of Rows and Columns in a keypad. Here keypad is a Input device that is directly connected to the arduino. This handles the key pressed. Helps to enter the info to the micro-controller. Here we are using 4x4 rows and columns keypad that contains 16 keys respectively.
RGB stands for(Red, Green, Blue). It is a 4-pin output device. RGB LED is just like a normal LED, but the color can be varied based on our requirement. It has 4-pins, each one for Red, Green & Blue, the other one becomes a common for these three colors. There are two types: Common anode and common cathode. Here we are using common anode display, So the common pin would go to the positive supply or 3.3-5V input from Arduino board. We are going to use two colors(Red and Green), so the RED and GREEN pin are connected to Arduino via a current limiting resistor, except BLUE pin.
Resistor is a two pin passive component used to limit the flow of electric current. The unit of Resistor is Resistance and it is measured in (ohms). In this project two 330ohm resistor is used across Green an Red pin of a RGB LED form arduino D10 & D11 respectively. The reason that I have used a resistor because to protect the LED from high current. sometimes connecting the LED without current limiting resistor would heat up the LED or even burn if it is sensitive.
Multi meter used to measure the electrical parameters of the components like- resistors, capacitors, inductors, diode, frequency, duty cycle, etc. I have used this device every time i do the projects. i have DMM(Digital Multi Meter) both are same. This device is having another good feature named 'Continuity mode' in this mode we can test the wire's continuity, test short circuits, etc.. (this instrument is not critically mandatory in this project, I just informed you guys about Multi meter.)
- LED - Light Emitting Diode.
- RGB - Red Green Blue LED.
- USB - Universal Serial Bus.
- IDE - Integrated Development Environment,
- CPU - Central Processing Unit.
- EEPROM - Electrically Erasable Programmable Read-only Memory.
- SRAM - Static Random Access Memory.
- I/O - Input and Output.
- DMM - Digital Multi-Meter.
- VCC - the source voltage of your board. eg: VCC=5V .
- GND - Ground or negetive.
- LCD - Liquid Crystal Display.
Step 3: Install Arduino IDE and Add 'Keypad' Library
Note:Skip this step if you have already installed Arduino IDE and added the 'Password Library' &'Keypad library' in your computer.
If you don't have Arduino software, Password library and Keypad library, then you can download it in this step. I have made the things easier for you. To download just click on the Hyper-linked word "HERE" . Download the Arduino IDE based on your system requirements.
- You can Download the Latest Arduino IDE from HERE.
- You can Download the 'Keypad' Library form HERE.
- You can Download the 'Password' Library form HERE.
Steps to add the 'Keypad' library:
Open arduino IDE >> in the menu bar click on 'Sketch' >> Include Library >> add .zip library >> now select the file 'keypad.zip' that you have previously downloaded >> Then click on 'open'.
Congratulations! you just added the library into your Arduino IDE.
- If you still have problems then feel free to send an e-mail, you can mail me directly from HERE.
If you are done with all these steps then lets move further.....
Step 4: Connecting Modules & Getting Hardware Things Ready
Let's start building the circuit...
TIP: Use different color code for wires to reduce confusions. Check the continuity of the wire that you use, this makes the troubleshooting easier. You can check the continuity by using Multi meter. :)
In this circuit, the connections are as follows;
LED and ARDUINO
- Red LED's pin------->> D11 via 330ohm resistor.
- Green LED's pin---->> D10 via 330ohm resistor.
- LED's +Ve------------>> 3.3v.
KEYPAD and ARDUINO
- 1st Row pin --------->> D2.
- 2nd Row pin--------->> D3.
- 3rd Row pin---------->> D4.
- 4th Row pin---------->> D5.
- 1st Column pin------>> D6.
- 2nd Column pin----->> D7.
- 3rd Column pin------>> D8.
- 4th Column pin------>> D9.
See the circuit carefully and connect the circuit as per the circuit diagram.
TIP: Before connecting your circuit to the power source, check the continuity between the VCC/+V and GND in your circuit. If the beep sound is heard from multi meter then there is a short in your circuit (risk). If there is no beep sound then there is no short circuit. :)
After building the circuit then, we have everything ready for programming. Before going to the programming part, If you want a snack or coffee break then go ahead..., then let's enter the programming part with a fresh mind.
Step 5: Programming Arduino and Testing
Lets begin to Program the arduino.
Note: To understand the program better, I have braked the code into small chunks and described its function. I have attached the program file in this step. You can download it and directly open the code in your computer.
this code is having a four different important parts,
- Setup loop: to declare Inputs, outputs and others like Serial.begin, etc.. (important)
- Void loop: for the tasks that has to run/execute forever. (important)
- Keypad event: for reading the pressed keys and store the pressed key for further validation purpose.
- Check password() event: This is the tunnel of the password for validating purpose. Code will further display if the password entered is true or false.
I have used an LED to display weather the password entered is true or false. Green Light comes when password is true else red LED will raise up to say password is wrong. You can even use relay or motor in the place of LED. So that you can control door or any appliance with password.
that is all about the program of arduino...
upload the code.
Step 6: Fun Time
Yepiee... we did it.. Congratulations!
Let's enjoy this project, enter the wrong password knowingly, use some other output device than LED. Explore the library that we have downloaded previously, there are lots of interesting concepts in those libraries, interface them to get some new thoughts and enjoy re-making it. It is really fun in doing all those things and saying EUREKA!!. Bombastic......
I am going to interface a LCD as my up-gradation for this project and of-course share with you guys again.
um.. Tell me, what to add with the LCD for the next version of this project. You can comment below.
And yeah, if you guys encountered any basic problems then dive-in to next step also.
I have included Troubleshooting steps, and as i said in the beginning, There is a way for beginners also....
Thank you all..... :D
Step 7: Troubleshooting and Guide
Please don't hesitate to ask me doubts of guide for troubleshooting. You can mail me directly HERE. You can even comment below, me along with instructables will try to solve your troubleshooting problems.
- Compiling error: reload the window, and try again. If continues then the code may be error.
- Uploading error: check for the boards availability from menu bar Tools >> boards. & Ports.
- Port not detecting: again this might be the same issue check for boards and ports, try restarting system.
- board not found: check for the boards availability from menu bar Tools >> boards. & Ports. again.
if program successfully uploaded to the arduino then;
- Showing Wrong key pressed in Serial monitor: Check for the keyboard wiring and loose connection, then check the code right in the display matrix weather you have entered a wrong pin numbers.
Guide for Beginners:
Guys, before 3 years i was same as you now, don't know what is resistor, arduino IDE, library etc. But the thing is i was studying about arduino, started from downloading PDFs, and studying from those. Now I am a Mechatronics Engineer. As well as self learnt about arduino. I can understand the problems that beginners have...
I have attached a PDF for you to read. You can start from that book also. I made this project easy to understand for you also, including program. comment below if you have any doubts.
Make this project. Best of Luck.
Thank You again...
Have a nice day... :D
Participated in the
First Time Author Contest