I have a question about keyboard diode placement. (Pardon my ignorance if this is simple question I have no electrical engineering background.)

The diagram below shows how a keyboard schematic is laid out (obtained from https://www.youtube.com/watch?v=vLGklanzQIc&t=721s):

Figure 1

From my understanding, column (0,1,2,3,4) provides 5 voltage supply (Vdd) and row (0, 1, 2, 3, 4) detects current flows. The voltage supply is essentially used to scan for input sequentially 1 clock cycle in microcontroller for each column, so to finish full scan it takes e.g. 5 cycles

The diode here is used when two simultaneous keys are pressed E.g. when row, column (0,0) and (0,1) are pressed then if the controller currently scans at column 0 but not column 1, the current in key (0, 1) will create reverse current on column 1 damaging the microcontroller so a diode is used to prevent this.

The video then goes on to say it is normal to have diode on each key.

enter image description here

Now my question is why place a diode on each key when you can save cost by putting it early on the column rail as in the first diagram?

I have also read about keyboard ghosting but I find it hard to articulate why the need to place diode on each key when the sole purpose of the diode is to block reverse current damaging the microcontroller?


2 Answers 2


The system does not work exatcly as you may have understood it.

Technically the column outputs don't even need any diodes, if they can be switched between 5V and off, such as between 5V output and input which does not output 5V or 0V. If the video does not mention this, it makes assumptions about used MCU or software, or it just is not very thorough.

You only need diodes on column outputs, if the columns are always outputs, outputing either 5V or 0V. In this case, when you push two column buttons simultaneously on same row, the diode prevents a short circuit between a 5V and 0V column outputs.

You need diodes on all buttons if you intend to be able to reliably detect any number of simultaneous button pushes.

Otherwise, you can detect reliably only any two buttons. If you press a third button, so that two are on same column, and two are on same row, it will look like four buttons are pushed simultaneously, as the pins of the fourth unpushed button are shorted together via the three already pushed buttons.


I don't know where you got this thought of reverse voltage, look again. You may have source and sink become swapped, but the voltage is still driven at the same level, it doesn't become negative or "reverse".

Also, rows detect voltage not current. There should be very little current flowing in a keypad, just enough to drown out interference.

The reason for the diode on each key is to prevent ghosting.

No one would use a per-column diode even in a keyboard without anti-ghosting. Rather, the column drivers are designed with only one transistor, so they switch between one strong logic level and floating, not between strong high and strong low. You'll usually hear "open drain" or "open collector", although the example circuits here need to toggle between "strong high" (1) and floating (Z) and those more common cases toggle between "strong low" (0) and Z.

  • \$\begingroup\$ Sorry I meant reverse voltage/current is when the microcontroller is not providing voltage to detect key press but is detected due to another key being pressed in the same column, a diode is used to prevent this. So you are saying e.g. keyboard detect voltage not discrete (5V or 0V) but continuous? \$\endgroup\$
    – Gabriel
    Commented Jul 1, 2022 at 19:30
  • \$\begingroup\$ @Gabriel: The circuit is designed to switch between discrete voltages. My point is that a PNP or PMOS driver is not damaged by the appearance of a logic high at its output that it did not create. Current flowing the "wrong" (i.e. unexpected) way through one of the key switches does not force any current into the column driver. \$\endgroup\$
    – Ben Voigt
    Commented Jul 1, 2022 at 19:41
  • \$\begingroup\$ (Again, real keypad circuits use NPN or NMOS for the column drivers, they either drive low or float. But that doesn't effect the overall circuit layout, or the need for anti-ghosting diodes, just causes their polarity to be reversed.) \$\endgroup\$
    – Ben Voigt
    Commented Jul 1, 2022 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.