Skip to main content

Bodac — Multiple Buttons on One Analog Pin

The Bodac module lets you connect up to 5 buttons using a single analog input pin. Unlike a traditional button matrix (without diodes) or "traditionnal" resistors ladders, Bodac supports simultaneous button presses — any combination of buttons can be pressed at the same time.

How It Works​

Bodac uses a resistor ladder with precision resistors (1% tolerance). Each button has a resistor wired in parallel. When buttons are pressed, they change the total resistance of the circuit, which shifts the voltage read on the analog pin. By using carefully chosen resistor values that are powers of two (50, 100, 200, 400, 800 ohms), each button press produces a unique analog reading — even when multiple buttons are pressed simultaneously.

The module reads the analog voltage, applies a debouncing algorithm, and decodes which buttons are currently pressed.

Bodac wiring with 5 buttons

A pull-up resistor between the input and Vcc is required, but it is already present on most ElectroSeed boards. The Bodac pins appear in khaki in the wiring diagram (as opposed to green for normal analog inputs).

Hardware​

You can purchase the precision resistor pack on the ElectroSeed store. An optional cable integrates the common resistor at the connector, reducing wiring to just 2 wires per button.

Module Properties​

PropertyDescription
PinThe analog input pin to use
Nb ButtonsNumber of buttons (2 to 5)
ResolutionADC resolution in bits
AverageNumber of samples to average for noise reduction
ARefAnalog reference voltage
DebounceDebounce time in milliseconds (0–255)
K0–K4Calibration values for each button threshold (set automatically during calibration)

Inputs and Outputs​

Inputs:

  • Input — Analog input (connected automatically to the pin)
  • Cal — Push button to start/stop calibration

Outputs:

  • Button 1 to Button N — One output per button (high when pressed). These auto-connect to BitPacker modules.
  • Msg — Calibration messages (connect to a USBSerial module to see calibration instructions)

Example: 5-Button HID Controller​

Open the built-in example: Examples > 02-Digital > BodacHid

Bodac HID example flow

This example shows a complete Bodac setup with 5 buttons connected to a USB HID game controller:

  1. Bodac reads the analog pin and decodes 5 button states
  2. Each button output is wired to a BitPacker input
  3. BitPacker packs the button bits into bytes and sends them to a Serializer
  4. Serializer formats the data for the HID module
  5. HID sends the button states to the computer as a USB game controller

The USBSerial module is connected to the Bodac's Msg output to display calibration messages in the serial console.

tip

You can use Auto Connect to quickly wire the Bodac to a BitPacker. Select both modules and press A — the button outputs will automatically connect to the BitPacker inputs.

Calibration​

The Bodac module comes with default calibration values based on the standard resistor pack. If your wiring or resistors differ, you can recalibrate:

  1. Connect the Msg output to a USBSerial module
  2. Upload the firmware to your board
  3. Open the serial console (Ctrl M)
  4. Click the Cal button on the Bodac module (in Node Blue, not a physical button)
  5. Follow the on-screen instructions in the serial console — you will be asked to press each button individually
  6. The calibration values (K0–K4) are saved automatically

The calibration adjusts the threshold values so the module can reliably distinguish between all button combinations even with component tolerances.

info

You can also enable the Debug option (admin only) to see raw analog readings in the serial console, which helps diagnose wiring issues.

Tips​

  • Number of buttons depends on ADC resolution — higher resolution allows more buttons to be reliably distinguished. 12-bit resolution supports up to 5 buttons comfortably.
  • Averaging (4+ samples) reduces noise and improves reliability, especially with longer wires.
  • Debounce of 10ms works well for most mechanical buttons. Increase it if you experience false triggers.
  • The resistor values follow a power-of-two pattern (50, 100, 200, 400, 800 ohms), which ensures each button combination produces a unique analog reading.