Soft keypad.h emulation

I’m hacking into an old vending machine to make it run with a particle.
Rather than get deep into the low level controls, I decided to simply build a particle powered number pad to replace the existing one.

To get started, I bought a replacement number pad to see how it works. It turns out it’s the same as all the ones in the Keypad.h library. Got it up and running, and I can now read key presses. Pretty easy. HOWEVER, now I want to emulate button presses for the machine. There is no function to press a button in the library. How would I do this via particle?

Hey Avidan,
Great to hear you’re working on yet another Particle powered project!

Just to confirm, it’s this library you’re using, right?

When you say you want to emulate button presses, do you want the library to think a button is pressed, or do you want the device to fake a physical press, thus ‘hitting’ the button hardware-wise?

What is the end-goal (of simulating these buttons), so we can chime in with ideas :innocent:?

1 Like


id like the do the latter. i am trying to simulate a button press (hitting the button hardware wise)
below is the existing keypad. id like to make a particle keypad, but keep the same internals to the rest of the machine. potentially, id like to “man in the middle” here. so people can still use this keypad, but i can also press buttons via software. make sense?

1 Like

and the end goal is that i can select a beverage via voice activation! or via facial recognition…or random soda selection.

1 Like

Oh, that’s a fun one. Since this is a key matrix, a 6x3 matrix switch would be needed to “shadow” the existing keyboard. This could be done with three 8:1 analog multiplexers (CD4051) or a single 8:4 multiplexer (possibly MAX14724). Not simple but doable.


and what if we dont shadow, but just fully replace the keypad with a photon?

@avidan, the existing hardware is scanning that keypad with a specific response expectation. It may be possible to have a Photon/Mesh device emulate the keypad by “listening” for the scan signals and responding accordingly. Most likely doable.

1 Like

If you look at the back-side of that keypad, it looks like when a button is pressed, it’s making contact between 1 of the 3 “column” traces and 1 of the 6 “row” traces. You could probably put together a few components to emulate that switching. You could put in 18 digital bus switches… I think I would use something like this Quad FET Bus Switch. You could use 6 of them, one for each “row” (ignoring 1 circuit on each IC because they don’t make Tripple FET switches). Then you need 18 GPIO pins or some sort of priority decoder IC… or you could use 3, 8-bit latching shift registers to drive the bus switches. This would take the guess work out of how the vending machine is sensing the connections because you are putting in a drop-in replacement for the buttons.


If you wanted to get fancy, you could hook the keypad up to the Photon so that you could have both manual control as well as IoT control. It would just all run through the photon. Or add some sort of cable connector to your custom PCB so that the manual control would be in conjunction with IoT control. I can imaging about 4 ways to hook all that up but it comes down to how you envision the pad working with the Photon.

1 Like

ok. using the Quad FET Bus Switch feels like overkill. Is there no way to simply remove the pad entirely and plug the 9 connections to the photon and somehow emulate button presses?

Can you take some measurements before and during a button press to figure out what level the different lines sit at? Does a button press pull the lines low or high? Too many questions about how the pad is read by the vending machine to make a better suggestion. The bus FET switches would have acted just like the buttons, like a simple contact closure. There’s no way to emulate a contact closure without a transistor of some sort. Without external hardware, then you have to drive the 9 lines high or low using GPIO… but which way will take some testing. Or find a schematic or wiring diagram for the vending machine which may answer the question.

1 Like

ive plugged the number pad directly into the particle, and im getting successful reads. see code below. what measurements should i be taking?

// This #include statement was automatically added by the Particle IDE.
#include <Keypad.h>

const byte ROWS = 6; //four rows
const byte COLS = 3; //four columns
char keys[ROWS][COLS] = {
  {'A', '1','2'},
int pressButton(String letter);

byte rowPins[ROWS] = {5, 3, 2, 1, 0, 9}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){

void loop(){
 char key = keypad.getKey();
  if (key){ 
     String keyString(key);      //convert char array to string here.

Can you plug the keypad into the vending machine and then take a multi-meter voltage reading on each of the pins between the pin and ground? This will determine which keypad pins, if any, are high before a key press. That would be where I start. If none are high, then that’s an issue… like @peekay123 said, the controller might scan the keypad instead of just doing a simple pull-up/pull-down on the lines.

I tried searching for a schematic but the vending machine manuals are so generic. I couldn’t find any good photos of the controller board to trace out the PCB regarding the keypad connections.

It seems there has been progress :slight_smile:

very much! now we have to decide if the vending machine will be Alexa or Google Voice powered…and maybe some computer vision