Panel Cookies
Arduino keyboard serial output

Help me by sharing this post


I've used "keypads" for Arduino in the past, but only numerical and with maybe 9 or 16 buttons, nothing more. In this tutorial I'll show you how I've made this PCB, how it works to detect all of the 40 buttons and how it will be the serial output. Once we have the keyboard we will be able to send to any microcontroller any character in lowcase, upercase, numbers and special characters such as question mark, exclamation, etc. I hope you will like this project and maybe it will be usefull for your projects where you need a full alphabet keybaord.

See manual of the PCB here on this LINK.

PART 1 - What we need

The list is very short. See full list here on this link. All we need is the PCB, that in my case I've made using the services from JLCPCB, and then the ATmega328 microcontroller, the 16Mhz crystal, some capacitors and resistors and an LED. Finally we need 41 of those silicone soft push buttons. I'm using these buttons because are easier to push and they make no "click." The output from the PCB will be a serial output, and for taht we only need some thin wires. To program the board use the FTDI programmer. See al parts below.

We need:
Arduino matrix keypad keyboard parts

PART 2 - Schematic

The scheamtic of the PCB is more than simple. All the buttons are in a matrix formation with 10 columns and 4 rows and we will see why later. We also have an extra button connected for the send input. The ATmega328p chip needs its basic configuration with the 16MHz crystal, pullup resistor and the DTR capacitor of 100nF. We need a few more resistors and capacitors, the LED connected to a digital pin and all the pads for the UART and i2c ports.

Arduino schematic matrix keypad keyboard characters

PART 3 - How it works

See the animation below. First, on step "1" we connect all the columns and rows to the buttons. To one side of the buttons we connect the columns and to the other the rows, in our case 10 columns and 4 rows. The microcontroller, on step "2" will constantly apply high pulses to the rows in a sequence and will do that very fast. Now, the magic will be on step "3". If I push any button, there will be a close circuit between the row and column, in thisc ase between row 2 and column 7. So as you can see on step "4", when the high pulse gets on row 2, that high pulse will now pass to column 7 and by that the microcontroller could detect it. The microcontroller also knows which row was high in that moment and now it knows whick column is high as well, and with these two informations, we could detect which button was pressed. Easy...

Arduino keypad matrix how it works circuit

PART 4 - Mount the PCB

Soldering the PCB is very easy. Get the board and first we solder the ATMega328 chip with the basic configuration: the 16MHz crystal, resistors and the DTR capacitor. That capacitor must be 100nF. Add a few more resistors and capacitors, the LED and the electronics are ready. Then we need to add 41 push buttons. The buttons have exactly the size of the holes on the PCB. So just insert all buttons and then solder each pad. The keyboard is ready.

Arduino keypad matrix how it works circuit

Now solder 5 wires to the bottom UART port for 5V and GND and also for RX, TX and the DTR pin. Connect the FTDI module to those wires and now we could upload our code. So, go below and download the Keyboard code and upload it to the board. The board will work at 115200 bauds per seconds.

PART 5 - Code

First we need to uplaod the code to the KEYBOARD and then we will have some other small test codes for the other Arduino. Download the code from below and upload it to the Arduino. Make sure you install the Adafruit_Keypad.h as well so on the link below you will be able to download that as well and install it.

const byte ROWS = 4;  // rows
const byte COLS = 10; // columns
//define the symbols on the buttons of the keypads
char keys[ROWS][COLS] = {
  {'*','-','z','x','c','v','b','n','m',','}   //SHIFT = * // OK = - // RETURN = ! // SPACE = ,
byte rowPins[ROWS] = {12, 13, A0, A1};                  //connect to the row pinouts of the keypad
byte colPins[COLS] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11};  //connect to the column pinouts of the keypad

//initialize an instance of class NewKeypad
Adafruit_Keypad customKeypad = Adafruit_Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS);

In the code we need to define the amount of rows and columns, in this case 4 and 10. Then we define the configuration of our keyboard, where will be each cahracter related with which button. Finally we define the pins for the columns and for the rows and that's it. The resi is done by the keypad library interruption.

PART 6 - Test code

6.1 One character receive

Now that the keypad has the code uploaded, it will send a character each time we press any button. For that we need to make a test. I'll use an LCD with i2c port to print the received values but you could also use the serial monitor. For the LCD you will need the i2c liquid crystal library as well so from the link below, download that as well and install it to the Arduino IDE. Upload the test code to the Arduino and then connect the keyboard to the Rx and Tx pins. Don't connect the keyboard while uplaoding the code, oterwhise the code won't be uploaded since the FTDI chip is uing the Tx and Rx pins as well. Press butons and see the received character on the screen.

if(Serial.available() > 0)
    char RECEIVED =;   

6.2 Full text receive

The schematic is the same. But now in the code we store up to 32 characters adn print those to the LCD screen and wen we press the send button, we reset the LCD and print "SENT" on the screen. This is another simple example just to test the PCB for upercase, special cahracters, etc...

if(Serial.available() > 0)
    char RECEIVED =;

    if(RECEIVED == '{')

PART 7 - Tutorial VIDEO

See the video for more information and see what options you have with this PCB. I might place this on my future online store. What do you think ? Comment below and help the community. Consider supporting me on PATREON.

Help me by sharing this post


Arduino keyboard
page 1/1


PCBWAY PCB service

Curso Arduino Online nivel Intermedio