This website uses 'cookies' to give you the best, most relevant experience. Using this website means you're happy with this. read more Accept & Close
Start Games
Do It Yourself
DIY & Home Improvement

1 pin & 6 buttons - Analog Keyboard

1 pin & 6 buttons - Analog Keyboard
1 pin & 6 buttons - Analog Keyboard
How to connect six keys with one pin to the microcontroller. It often happens that our circuit is missing free pins. The method to solve this problem is many, for example:

Step 1: Components

Components I used in this example.

Step 2: Schematic

Connection of analog keyboard to Arduino.
Connection of analog keyboard to Arduino.

Step 3: Software

The method to read the key is very simple. Each key gives different output voltage so
using the analog-digital converter recognize which key was pressed. Because reading
from the analog input may be slightly different, it is safe to check whether the value is in the range.
#define CHECK_KEY( __v0__, __v1__) __v0__ >= (__v1__ - 10) && __v0__ < (__v1__ + 10)
byte GetKeyNumber(int key){ byte num = 255; //0, 90, 170, 236, 293, 340 if( key < 10 ){ num = 0; }else if( CHECK_KEY(key, 90) ){ num = 1; }else if( CHECK_KEY(key, 170) ){ num = 2; }else if( CHECK_KEY(key, 236) ){ num = 3; }else if( CHECK_KEY(key, 293) ){ num = 4; }else if( CHECK_KEY(key, 340) ){ num = 5; } return num; }
Download source code: AnalogKeyboard.ino

Step 4: Testing the keyboard