Integrate a keypad into your arduino project.

Systems that allow users to input their own data or in a way allow the users to control them by keypads or buttons are weirdly unique, yeah! They give the user some kind of feeling that makes the user feel like, “oh wow am in control”.  The few who were with us a couple of years back when we were using the Nokia 3310 and co would appreciate this tutorial more, hahaa.
So in this pretty short tutorial we are going to learn how to integrate a keybpad with our microcontroller and perhaps build something fun at the end.

The keyboard I will be using in this tutorial is a 4X4 matrix keyboard and i will explain why 4×4 soon. But of course the tutorial will generally let you understand how to use any keypad, whethere 4×3 or any custom keypad you may find yourself using. The Basis are the same!

why 4x4 and 4x3 and etc...?

If you have used excel or any spread sheet before you’d realize that the best way to identify individual cells in a grid is to use the rows and columns approach.
So in a grid with 16 boxes inside of it like this one, you will identify the highlighted box or cell with what row and column it is located in. It is the same with key pads too.
The individual buttons are arranged in rows and columns. So every keypad is named by its maximum dimensions. The max number of rows here is 4 and the max columns are also 4 so it is a 4×4 matrix keypad. 
Note that the rows are the numbers and the columns are the letters. in this one.

The electronic rows and columns behind the keypad.

So yes, behind the keypad there are wires that run through. In the case of the 4×4 keypads there are a total of 8 different wires that run through it. 4 for each row and the next 4 for each column. 
Whenever a particular button is pressed, it means a prticular row and a particular column have come in contact. It is the job of the microcontroller to figure out “which row and which column have come in contact?” and hence, “which button has been pressed?”.

There is a unique way the microcontroller identifies this but I dont want to get you bored in this particular piece. Maybe I’ll dedicate that for another day. There is a simple library called “Keypad.h” we will use in the arduino program that will take care of all the booring technicalities and make it easy for you to use any keypad. But wait lets build the circuit!

A simple password protected System

This is a fritzing layout view of the simple circuit to be built. The purple jumpers go t

So in this simple but interesiting project I want you to imaging something, I want you to imagine a great posibility. Let say you have a big project or system that has to function only if the main user is in charge. Just like how you sometimes put passwords on your mobile phone to prevent others from accessing it. So in this proect the 4 beautiful LEDs you see there represent something precious you have built, but then, these 4 LEDs are going to display their beauty to the user only after the right password has been entered. It’s crazy, I know right!
Watch this video to see the sample in operation!

Components involved

  • Bread board
  • Arduino UNO board
  • 4 LEDs(Red, yellow, green, blue)
  • 4×4 keypad matrix
  • Piezoelectric buzzer
  • A few jumper wires

What the codes will do to the circuit

And yes the codes below are what will be uploaded to your Arduino microcontroller in other for it to run sensibly. The codes have been commented well enough to explain things incase you are not comfortable with some of them.
What this program does is this. 

On the Serial monitor, the program will begin by requesting the user to input the password.
If the password is wrong, the buzzer will make that annoying sound to prompt you.
But if the password is right, the LEDs will show you the beautiful dance they have you.
It’s that simple.


This is what defines the lenght of the master password. The value here should always be 1 more that the actual lenght since all strings have an invisible null character at their end. 
So if your password is 10 characters, this value should be 11.

This fuction is only responsible for deleting the previous data the user put in after every cycle.

The danceLED(); function is the main function tht holds whatever project protected behind the password so feel free to change the code in it to suit your needs.

Alright genius! This is it for today too. Go be you! and yeah dont forget to leave a question, suggestion, or anything in the big comment section below. Do well to also post pictures of your projects in the community.

Related Articles

Addressing the Newbie Passions!

Since the days the worlds were formed by the Great I Am, humanity has never stopped expressing the creative power that was embeded in us since day 1! From before the agricultural age through the 1st industrial revolution to the 4th revolution on whose gates I stand and write today, there has always been the need to invent new things or make a way of life better than a previous.


Your email address will not be published. Required fields are marked *