Simple Math Calculator and PassCode Relay Switch using Resistive 4×4 Keypad Module



In this tutorial we are going to Test the 4×4 Resistive Keypad Module using this to make a Simple Math Calculator and Passcode Relay Switch, dont worry because this is an easy project and beginner friendly and I explained this as a very simple and detailed way.


Hardware Used

  • 2 – Arduino Uno
  • 1 – 5v Relay
  • 1- 4×4 Resistive Keypad Module
  • 1 – 16×2 LCD module
  • 1 – Potentiometer

You can buy all this Hardware at Createlabz.

Software Used:

  • Arduino IDE

Library Used:

Application Description:

The first activity that we are going to do is to do a simple math calculator using the keypad buttons.


1.) Finding the analog value of each buttons

As you can see in this picture, the analog values were already given but because it is so sensitive you must check if it is really the analog value for each button by uploading this program into your arduino.

Upload ang pressed each buttons. You will see the values of every button you press.

2.) If you have find the values for each buttons and it does not read the same values with mine then just edit my the code “Simple Math Caculator”.

For the 2nd activity, Code lock using 5v relay switch.

1.) Just upload the program and do the wiring stuff.

Problems Encountered:

As i said earlier that this module is so sensitive. So this is my solution to the problem.

As you can see I used an electrical tape so that it wont touch my skin and for a constant value of the analogRead of the module.

Another problem that I encountered that the keypad module should be powered to another arduino. Which means you should isolate the VCC and Ground of the keypad module to another Arduino.

Set-up the Hardware:

Output = A0 of the Arduino for LCD

VCC = VCC of Arduino

Gnd = Gnd of the Arduino

NOTE!! You should connect the VCC and Gnd to the other arduino!


For Simple Math Calculator:

For Code Lock Relay:

Code Breakdown:

For the first activity:

declaring that the values for a and be is an integer and the op is a character.

Initiating the Serial Monitor.

and the LCD.

In this line the Serial Monitor will ask you the first number you want to operate. If you have pressed the button and if the analogRead(A0) will be grater than 100 then it will go to the next loop.

The Serial Monitor will ask you the operation depending on what you would like. Again if the AnalogRead(A0) will be grater than 100 and if you pressed a button in the keypad it will go to the next loop of the code.

This code will ask you the second number to be operated. If you pressed the button and analogRead(A0) will be grater than 100 then it will go to the next loop.

This are the function of each buttons. As we did the first activity to find the analog values for each button this is the ouput of that. For example in fourth line of the function if the analogRead(A0) which we assigned as a variable pinValue will be less than or equal to 1020 it will function as “7”.

For the Code Relay Switch:

Declaring password[] array and tempPassword[] array as an integer.

This will initiate all the process in the program. It will as you to choose between 2 modes. If you pressed the button 1 then it will go to the function storePassword(); and if you pressed the button 2 it will go the function verifyPassword and if verifyPassword is achieve the Serial Monitor will print “Password Match” and Switch the relay on for 2 seconds and off after 2 seconds, if not will print “Wrong Password!”.

This is the function storePassword(), as you can see it has an increment. The process will be the Serial monitor will ask to Pressed the button for times because of increment from 0 to 3. Starting from 0,1,2,3 and if goes to four it will stop because of the less than 4.

Next if you have pressed the button 4 times, what ever you have pressed will be store in the password array because of the line

and will print in the Serial Monitor “Password has been saved!”

The function verifyPassword(), its process is the same with the function storePassword but on this time it will check if the password[i] array is equal to tempPassword[i] array.


This project was a bit challenging for me because I did not see similar projects with this in the internet. I gave my extra time and extra effort to finish my project and because of that I was able to learned new things. I learned and understand deeply how array works. I’m hoping also that you have learned something from this tutorial. I know that this tutorial is a bit easy but you can use this as a reference to the complicated projects.




Tags : 4x44x4 keypadanaloganalog keypadarduinobuttoncalculatorkeypadlcdrelayresistive keypad

Leave a Response