Saturday, March 15, 2014

The Remote Project - The Buttons

So obviously I need buttons... Around 25 of the buggers... Try finding an Arduino with that many inputs. I suppose I could use a shift in register.... but it's not really needed.

While looking up information on building my own keyboard (it's one of those things I'd probably have a go at if I had a 3D printer), I found information on button matrixes. I'm going to give you my abridge version here....

Suppose I want 9 buttons. I only need 6 pins on the Arduino. I only need two bits of information - an X and Y as it were. Using the diagram below, if I put a charge on A and then measure 1, 2 and 3, I can tell if any of the buttons in the A column have been pressed. Repeat for B and C. Simple!
Fig 1.

There are some (really quite odd) cases where things can go a little wrong... like someone is pressing lots of buttons... Using the example in the first image in Fig 2. When checking B, it appears that B1 and B2 are pressed. To fix this, use diodes which are basically a one way valve. The other two images show what happens when you add diodes in.

Fig 2

This is where I started getting obsessive. I wanted to throw together something that would be nice and compact. And I wanted to do it using vero strip board.... What is vero strip board? It's basically a fibreglass board with copper rails running down it (and holes pre-drilled).

Roughly like that.... You can then use a drill bit to break the tracks. After obsessing over it, I finally came up with a design. Unfortunately, the design I landed on requires surface mount components (when I'd already brought non-smc so ended up buying the diodes twice). They'll come in handy.... They better.... I've got 1,000 of them.

So the design I landed on:

is something like this. Expand it out to be 5 buttons by 5 buttons.... I've just about finished this bit except that I've had a delay due to having to buy new diodes.


  1. I don't think this is going to work. In your fig 2 you have switches B2 and C2 pressed. Suppose there is a positive charge on B and C rails, the diodes are not stopping anything so is B2 pressed or C2 pressed, it cannot be verified.
    Suppose the positive charge is instead on line 2, the diodes will block a circuit to B and C so nothing will be detected.
    Also a shift register wont really do anything as it takes a serial input. without a BCD and a serial decoder you wont know which button is pushed.
    I would recommend logic gates and you can quickly create a truth table, use some Boolean algebra and come up with a circuit that is both elegant, cheap and works.
    There is no need for SMD's, the vero boards are not SMD boards and soldering them on is a *blip* on those.
    Good luck!

    1. That assumes there's ever a scenario there's a positive charge on both B and C - which isn't how a matrix works... You put a positive charge on B, measure 1 and 2 (and 3 etc.), turn off B, put a charge on C - rinse and repeat. To my way of thinking, logic gates are a bit over kill for this particular application....

    2. Yeah my bad, I didn't read that properly. I missed the Arduino part of your post. I thought you were trying to devise one for some other application that does not use a decoder. Your circuit should work, it takes care of ghosting.
      I also after my reply(oops!) read further down and see what you are building. A replacement remote powered by Arduino. Ordinarily I'd say don't bother, the universals from Logitech are much better but quite dear, however it's not fun! Building your own in Arduino is so much more fun.
      I do have some suggestions though. Why not rip apart a computer keyboard's circuit and construct a membrane? Everything's done for you and all you need to do is make a membrane keyboard. You get quite a few buttons, it will make your project a lot easier!
      Also you should get a breadboard to prototype on before doing your final on a vero.
      I notice you are using mechanical switches? They bounce and will cause problems. You should program the Arduino with a small delay after an initial detection to ensure multiple keystrokes are not detected.
      Have fun :)

    3. I've already done the really hard bits - the soldering is UGLY! but then... sod it... it seems to be working thus far. I've got a couple of small bits to do but yeah... the SMC are a complete itch to do (as expected) but at least let me keep the spacing between buttons to a minimum.

      The reason I didn't bother with the universals was that I really wanted to control the raspberry pi (xbmc) with it as well - in which case I was already going to have to play with a Leonardo to take in IR and feed keyboard signals in which case, given cost and a DIY attitude (I'm trying harder to do the DIY stuff as I think since helping found Tangleball I've done VERY few projects) this seemed like a much more interesting route.