23 April, 2020

Arduino tree menu for 4X4 matrix keypad

By Mauricio Hidalgo

Sometimes we need to create a menu for our Arduino projects and do not know how to implement the code for that menu has different possibilities without losing details of programming.

I want to share a method that allows to create code cleaner and can display in a better way our program in order, to find errors or more easily and make modifications exactly over part of the code we want.

I programing a 4X4 matrix keypad and present a menu using a 20X4 LCD, here I test 4 sensors,  temperature, light, sound and a potentiometer.

I have taken the sensor signal through the analog inputs of the Arduino UNO without modify the data, that means that the value that give us the sensors have not modified to display it, just read the value in volts that give us each sensor and show on the LCD 20X4, so each of you can modify the unit of measurement depending on which you want to show on values of each sensor.

How to create an Arduino  tree menu?

Most important in this Arduino project it is to show that it is possible to work a program divided into several pages and these can be linked together, which facilitate the understanding of the code and how we can analyze any code without complicate us looking for an error in a sheet with thousands of instructions.

This type of menu can be very useful if you need to perform a specific function in different parts of the code without having to repeat an instruction or set of instructions on the same sheet.

For example you need to run a cycle “IF” several times with the same action, simply insert a function and within that function  repeat cycle that you need and simply calling the function, the cycle is executed. The following image show function in a different sheet called from the main program.

Captura 3

At right side the main program is where does the calling function and left side the second page where the function is built.

In the tree menu for Arduino, you must create several cycles and this makes the code on a single sheet is very difficult to manage, it is why I recommend to handle functions on multiple sheets.

Structure your code right from the beginning, allows us to create more robust code and manage beter our projects, make an LED turn on and off may not require this type of structure, but if your idea is to advance and create much more elaborate programs, I recommend you this type of structure.


You can create a function to control motors, another function to capture information from sensors, one for controlling a communication, it really is a very simple way to order our code and get good results.

I have created a video where the operation of the menu is shown and I have posted it on my YouTube channel, here I leave it to show you of what here I told you, well I leave the schematic by if you needed.

Also I leave the wiring diagram of the components so that you can implement it.

I hope this is important to continue to build ever more elaborate and fun projects, thanks for visit this page and if you like this information please share.