Add Pressure Sensitivity to Switches

Series: alt.ctrl activities; builds on Button arrays

Many modern buttons use conductive rubber instead of sprung metal to close their contacts. Conductive rubber is piezoresistive.

Materials

ItemAmazonAdafruitMouser
The silicone 4×4 keypad lit blue on a Trellis board, a finger pressing one key.
Photo: lady ada, Adafruit (source), the keypad on a Trellis board, CC BY-SA 3.0
Silicone elastomer 4×4 button keypad, for 3 mm LEDs
1611485-1611
A microcontroller (MCU) with analog inputs
Pull-up resistors

Tools

  • Scissors
  • Soldering iron
  • An MCU IDE

Skills

  • Reading an MCU's analog inputs

Instructions

  1. Switch the role of the MCU inputs the buttons are wired to from digital input to analog-to-digital conversion.
  2. Add a pull-up resistor to each analog input (most microcontrollers cannot enable a built-in pull-up on an analog input; first-generation Arduinos could).

Variations

  • Add appropriately shaped (annular?) pieces of Eeonyx piezoresistive fabric to the switch.
A hand peels a white silicone 4×4 button keypad back from a green circuit board. Dark rings sit under the keys, and grey pads surround the LEDs on the board.
Circular Eeonyx fabric disks under a silicone 4×4 keypad, from Pressure Sensing Illuminated Button Array.

Related resources

Coding Prompt Build Block

A prompt to give a coding assistant, to start the code for this activity. Copy the box, answer its questions about your board and pins, and test what comes back on the bench before you rely on it.

I am building "Add Pressure Sensitivity to Switches", the activity at https://adrianfreed.com/add-pressure-sensitivity-switches.html.

Write a program for a microcontroller that reads how hard each key of a 4×4 conductive-rubber keypad is pressed. Conductive rubber is piezoresistive, so read each key on an analog input instead of a digital one, with an external pull-up resistor (most microcontrollers cannot enable a built-in pull-up on an analog input); the reading falls as the key is pressed harder.

If the keys are wired as a matrix rather than one to each input, scan it a row at a time, and explain how you keep keys pressed in other rows from disturbing the reading.

Calibrate each key, at rest and pressed hard, and scale it to a pressure from 0 to 1, with a threshold for a touch. Send each touch as a note whose velocity comes from the pressure, and the pressure that follows as polyphonic aftertouch over MIDI, or send all of it as OSC messages.

Libraries to explore:

Before writing anything, ask me what I am using: the board and its pins, or the software (such as Max, Pd or Python), and check its documentation for what this needs. Put the pin numbers, ranges and other settings in one block at the top, each with a comment. Say which of the libraries above you use, and why. Start with a test that shows the raw readings, so that I can check the wiring and the ranges before the rest.

This activity by Adrian Freed is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0): you may share and adapt it with attribution, for non-commercial purposes such as personal projects and teaching, and you must share adaptations under the same licence. Product names and links belong to their suppliers.

Design strategies: