Circuits guide series


What is the purpose of the diodes in a keypad circuit?

A diode is a semiconducting device that allows the flow of electricity towards only one direction. Diodes are commonly used in applications where we want to prevent back-currents. One such application is in a keypad or keyboard circuit.

The 4x4 membrane keypad

When you wire a 4x4 (or similar) membrane keypad to your Arduino using a single analog data wire, like in the schematic below, most people readily understand the purpose of the resistors.

The resistors are used to create a voltage ladder, a circuit that produces multiple voltage reference points that can be measured by the Arduino. The sketch that is running in the Arduino can figure out which key was pressed by measuring the voltage on the sampling pin.

But what about the diodes? What is their purpose?

Diodes in the 4x4 keypad circuit

If you can somehow ensure that only one key can be pressed at any given time (perhaps through mechanical means), the diodes are not needed. Try it out, and you should see that the keyboard works fine.

But if you happen to press multiple keys on a matrix keypad (like when you hold down Shift-Cmd-S in a computer keyboard), an effect called "ghosting" comes into play.

When ghosting occurs, then usually a key that wasn't pressed is read by the host (the Arduino, in our case).

In many keyboard designs, diodes are added to deal with ghosting. 

If you are curious to know more about this, I have found two useful resources:

"Circuits" series

The Tech Explorations Subscription program

Subscribe and access all of our video courses immediately.

With a catalog of 25+ premium video courses (and growing), this subscription gives you an amazing resource to boost your learning.

New to the Arduino?

Arduino Step by Step Getting Started is our most popular course for beginners.

This course is packed with high-quality video, mini-projects, and everything you need to learn Arduino from the ground up. We'll help you get started and at every step with top-notch instruction and our super-helpful course discussion space.

Tech Explorations Arduino intermediate level

Done with the basics? Looking for more advanced topics?

Arduino Step by Step Getting Serious is our comprehensive Arduino course for people ready to go to the next level.

Learn about Wifi, BLE and radio, motors (servo, DC and stepper motors with various controllers), LCD, OLED and TFT screens with buttons and touch interfaces, control large loads like relays and lights, and much much MUCH more.