What do you think of this schematic for my Arduino keypad? Are the diodes pointing the right way?

I will make col1 "high" and then check pins row1, row2, row3 and row4 and see if current is flowing through. Then make col2 and col3 "high" and again check if current is flowing through the row pins.

My Schematic:


Ok so I´ll change the direction of the diodes. In my code I will declare my rows as inputs and my columns as outputs. Then I will set all columns to "HIGH". To check which keys are pressed I will set col1 to low. There should be current flowing if any key in that column is pressed. I will then check my rows if their state has changed to "LOW". I will repeat the process for col2 and col3. The anti-ghosting diodes should still work. This way it could work right?

  • \$\begingroup\$ Consider using Schottky diodes instead of 1N4148, for better margins. Then your inputs will be at ~4.8V instead of ~4.3V. This in turn gives better tolerance for temperature variations, inaccurate supply voltage etc. \$\endgroup\$
    – Lundin
    Commented Jul 6, 2020 at 10:30

2 Answers 2


If the diodes are that way, then columns should be inputs with pull-ups enabled, and rows should be outputs, the scanned row being low, and the other rows high.

If you want columns to be outputs, and rows as inputs, then the diodes are the wrong way around.

  • \$\begingroup\$ Ok thank you. So do diodes show the way of "real" current/electrons flowing? \$\endgroup\$ Commented Jul 4, 2020 at 16:19
  • \$\begingroup\$ no, diodes show the way of conventional current. \$\endgroup\$
    – whitespace
    Commented Jul 4, 2020 at 16:22
  • \$\begingroup\$ But then my schematic should be fine, right? As far as I know putting a pin to high makes it +5V. So the conventional current will flow from col1 through the diodes and into the rows... I would use internal pulldown resistors on my row pins. \$\endgroup\$ Commented Jul 4, 2020 at 16:28
  • \$\begingroup\$ with some reservation about speed of operation, this looks ok. \$\endgroup\$
    – whitespace
    Commented Jul 4, 2020 at 16:40
  • \$\begingroup\$ ok. But if i use pull-up resistors on my rows. Then I would need to have my columns on "high" and then put them to "low" if I want to check if the key is pressed right? I wouldhave to change the directions of the diodes then I think. \$\endgroup\$ Commented Jul 4, 2020 at 16:57

you can replace diodes for each switch with one diode on the main row end rowN. Otherwise it looks ok to me with the way you have described.

  • \$\begingroup\$ Ok thanks. But I want to use those diodes for anti-ghosting so I think there should be one diode for every pin. \$\endgroup\$ Commented Jul 4, 2020 at 16:24
  • 1
    \$\begingroup\$ That is right, each button needs a diode of it's own to prevent ghosting. \$\endgroup\$
    – Justme
    Commented Jul 4, 2020 at 17:03

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.