Sparkfun’s 4×4 Button & LED Matrix – Part 2 – Connecting to an Arduino Mega

I described, in a previous post, how to assemble a 4×4 Sparkun’s button and led matrix. Let see how to connect it.

Because of the (quite) large number of leds and button, I will be using an Arduino MEGA. That will allow to drive RGB leds and button without any additionnal  component. Well… almost : we’ll still need

  • 12 150Ω resistor for the RGB leds
  • a few jumper wires
  • 3 small breadboards
  • an Arduino MEGA of course

RGB led and Arduino

RGB LED detailsAn RGB led is actually… 3 leds : 1 Red, 1 Green and 1 Blue (thus RGB). They all share a common cathode and have 3 anodes, 1 per color.

Choosing the voltage applied to each color allows to choose the brightness of each color, allowing, in turn, to display a broad range of colors.

An Arduino does not have analog outputs. Only digital ones. So we’ll use digital output to “simulate”  analog ones using a technique called PWM. For more details on PWM see here.

Wiring the button & led matrix

Without the matrix, we would need 3×16=48 PWM pins… that’s a lot. With the matrix, we only have 4 rows, each row being connected to 4 leds. This implies some limitations but we now only need 3×4=12 PWM pins and Arduino MEGA 2560 has… 15 of it. Phew…

In addition of connecting the anodes to PWM pins, we also need to connect the cathodes to  simples digital pins. We only need 4 of them because we have 4 columns, each column being populated with 4 leds sharing the GND.

And then, we’ll need 4 digital pins for button GND (cols) and 4 more for signal (rows)

button pad connection

You’ll find an interresting article about about keyboard matrix here.

And put it in a box !

I used the box in which my netatmo thermostat was provided : a nice cube with the perfect size ! I’ve done a bit of cut in the box and the spacers and here is the final result :

In the box closedIn the box opened

 A simple test program

We’we wired evrything up, we can start programming the gizmo and see what it can do. You will find a test program here.


As you see, it is quite simple : at startup, it senquentially lights up all leds then, on each button press, it light up the corresponding led, changing color each time.

It is just for testing. I’ll work on some more interresting programs and post them !

Sparkfun’s 4×4 Button & LED Matrix – Part 1 – Soldering


There are quite a few project out there using Sparkfun’s Button Pad 4×4 – LED Compatible and associated Button Pad 4×4 – Breakout PCB. But most of the time there are either using monochrome leds and a shift register to drive the leds or just using a 2×2 matrix. So I decided to write my own build guide with RGB leds and an Arduino MEGA.

This is the first part of this building guide. In this part, I’ll list parts I used and show how I soldered everything together. In next part, I will describe connection of the pad to an Arduino MEGA and all necessary code to test it and make some fun things.

The parts

You’ll need :

That’ll be it for the soldering. But in the next parts, I will also be using

  • 1 Arduino Mega
  • 12 150Ω resistors
  • a few jumper wires
  • one big breadboard (or 3 small ones)

I bought my parts mainly from 2 french retaillers in or near Paris : Lextronic as they are a Sparkfun’s reseller and Saint-Quentin Radio for basic electronic pars (such as resistors, diodes, cable…) But you can find almost everything at Sparkfun’s or your prefered shop !

The soldering

Lets have a look at the PCB first. On the “bottom” side, we will solder the 1N4148 diodes and the BERG connectors. On the “top” side, where the botton pad will rest, we will solder the RGB leds.

4x4 Button Pad Breakout PCB Bottom

Bottom side : where diodes and connectors go

4x4 Button Pad Breakout PCB Top

Top side : where RGB leds and rubber buttons pad (below) goes4x4 Button pad

1N4148 diodes : the easy part

Not much to say really… Just bend the legs, insert the 16 diodes required in the proper holes and solder. Just one thing to take care of : the orientation on the diode !


Then, solder the diodes on the top side, taking care of not putting to much solder as you will need to trim the legs as close as possible from the PCB (I used a specific plier / cutter like this one) so it won’t get in the way of the rubber buttons pad.

RGB leds

Not much more complex. But leds I used have legs a bit closer from one another that the holes are. So you need to bend the legs before trying to insert them. If you don’t, you won’t be able to push them enough.


Then solder the legs of the leds !

The BERG connectors

Again, one tricky part is that you need to keep soldering on the top side as “flat” as possible, else, rubber pad won’t lay down properly on the PCB.

What I did is “trim” the BERG connector BEFORE soldering so it flush with the PCB. Doing it after is much more difficult and you may (will) damage the solder joint.  Whan soldering, make sure you heat the BERG pins with the iron so that you build a solid solder joint.

        BERG trimmed

BERG soldered flat


Ok, now we need some wires to connect the PCB to an arduino. I used a 4 wire ribbon cable. On one side, I just tin-plated the wires so that they can be easily used with a solderless breadboard. On the other side, I used the female BERG connectors.

berg femake berg female and cap berg female and wire

Connecteur BERG et Cable

 And in the end…

… we get a fully assembled button pad !

button pad assembled connector sidebutton pad assembled led side