Adding lots of buttons with an input shift register - MobiFlight/MobiFlight-Connector GitHub Wiki

As you continue to build panels you may encounter situations where you have more buttons for input than there are pins available on your Arduino. The solution is to use an input shift register like the 74HC165. These allow you to read input from eight buttons while only using three pins on the Arduino. By daisy chaining 74HC165s you can add up to 32 buttons while still only using three Arduino pins.

What you'll need

  1. A 74HC165 chip
  2. Eight buttons
  3. Eight 10kΩ resistors
  4. A 0.1uF capacitor

The chip is available anywhere you buy electronics, including Amazon, eBay, AliExpress, Tayda Electronics and many other parts suppliers.

Making the connections

Connect the 74HC165 to your Arduino and the buttons as follows:

While the wiring diagram shows an 8-position DIP switch you can use 8 individual tactile buttons instead.

Device configuration - input shift register

Configure a new device for your Arduino in MobiFlight as follows:

If you choose to use pins other than 2, 3 and 4 here is how you should map the dropdowns in MobiFlight to the pins on the 74HC165:

MobiFlight Setting 74HC165 input 74HC165 pin
Latch SH/~LD 1
Clock CLK 2
Data QH 9

MobiFlight configuration - button input

For each input you want to connect to a button configure the input as follows:

The dropdown next to the device name selects which pin on the 74HC165 is mapped to the input configuration. The mapping is as follows, assuming the chip is wired as illustrated earlier in this tutorial:

MobiFlight Pin 74HC165 input 74HC165 pin
0 A 11
1 B 12
2 C 13
3 D 14
4 E 3
5 F 4
6 G 5
7 H 6

Connecting multiple chips in series

MobiFlight supports up to four 74HC165 chips connected in parallel. When wiring the chips, it is important to wire them so the right most chip in the series is the one connected to the Arduino's data input line. The clock and latch pins are shared across all chips.

(Buttons and pull-up resistors omitted for clarity)

After wiring the chips in series change the module configuration for the input to specify the number of chips connected in series. The resulting pin numbers in the input configuration dialog are determined by the order the chips are daisy chained together: Pins 0-7 are for the rightmost chip that is directly connected to the Arduino in the above schematic, 8-15 for the second from the right as that is the second in the chain, etc.. Using the debug log feature in Mobiflight will let you also see which number any given switch connected to the shift register is.