I'm trying to wire up a silly little keyboard using hall effect sensors and magnets in a glove. The idea being only I can use the keyboard since I'll have the glove.

The sensors are 3 pin, (vcc, gnd, and an output that sends 5v out when a magnetic field is present. I don't have anywhere near enough pins on the teensy for all the sensors. Could I just use several port expanders? Are there issues with using 4 or 5 at once? How many keys could be pressed at a time?

Is there a better option than all those expanders?

Also I know that this keyboard will be ugly and completely impractible to use regularly, but I thought it would fun to show off.

  • I just asked a similar question. It sound like if you used a matrix with output legs in a line tied to a shared Arduino pin, any triggered sensor in the line will drop the whole thing LOW so you could scan rows/cols to figure out what's pressed. Instead of powering rows one by one and paying the 150ms penalty mentioned by @Jot below, you route all rows/columns to digital input with INPUT_PULLUP and read them that way. Hope that helps!
    – Hendy
    Feb 12, 2020 at 3:31
  • Hmm that sounds way better than my current workaround. I would assume I could just use diodes to avoid ghosting? Also in this configuration there needs only be one pin per cop and one per row right?
    – Oe-
    Mar 2, 2020 at 20:57
  • Also, is the input_pullup really needed if the pins are already pulled up by the resistor?
    – Oe-
    Mar 2, 2020 at 21:21
  • I don't think so, as long as they are pulled up. My understanding is that INPUT_PULLUP is just a convenience (not requiring extra components). Now that you ask, I think I ran across a post/comment somewhere suggesting physical resistors vs. INPUT_PULLUP, but I don't recall the reasoning at the moment.
    – Hendy
    Mar 18, 2020 at 5:18

1 Answer 1


[Completely rewritten answer]
That seems fun. But why 65 keys ? with 64 keys it is easier.

You have to test the sensitivity of the hall switches with the magnets to know how far apart the keys must be. Perhaps they only work with strong magnets or perhaps a number of them are activated when the glove is near.

With hall switches, there are 65 digital signals from the sensors.
The most common way to create more digital inputs is to use shift registers. For example with the 74HC165. Nick Gammon has the best tutorial of the 74HC165 with daisy-chain. There is also an example is with the CD4021 and the ShiftIn function, but the 74HC165 is mostly used.
The shift registers can be daisy-chained, they are made for that.

Your AH1807 has a open-drain output. That means you need 65 pullup resistors.
It is not possible to connect all the outputs and turn them on one by one, since it requires 150ms to wake up.

Another option is using multiplexers. It can be used for analog and for digital signals. For example with four 16-to-1 multiplexers you can create 64 inputs going to 4 pins. The best multiplexer tutorial is once again written by Nick Gammon.

With four analog multiplexers of 16-to-1 you would require only 4 pullup resistors after the multiplexer. I think it is better to use a resistor per hall sensor (65 pullup resistors).

When using reed switches (those tiny glass tubes, used in house alarms), they can be set in a matrix/grid with rows and columns and the Keypad library. For example 10*7 requires 17 pins. The Keypad library allows that multiple keys are pressed at the same time.

  • I've seen that tutorial and read a little bit on using a matrix for keyboards. If I'm not mistaken, with a physical switch, it pulls the columns to low and rows to high and has 2 connectors one for rows and one for columns. The sensor I have only has one output leg so all my columns and rows would be connected to the same output leg right?
    – Oe-
    Jul 2, 2017 at 8:37
  • Oops, I might have made a big mistake. I was thinking about reed switches. Can you tell the type of the hall switches ? Perhaps I will remove my answer.
    – Jot
    Jul 2, 2017 at 8:39
  • This is the sensor in question. digikey.com/product-detail/en/diodes-incorporated/AH1807-P-B/…
    – Oe-
    Jul 2, 2017 at 8:56
  • Wow, thanks for the detailed response. It doesn't have to be 65, I can get it to 64 I'm sure. I'll read both of those tutorials and see which one works best. I'll see if I can find some Reed switches to play with too, that way I could use some of the existing firmware for keyboards.
    – Oe-
    Jul 2, 2017 at 11:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.