Keyboard Matrix 74HC138

Hello Everyone,

I stripped a used piano for its keyboard unit to eventually use it with an Arduino as a MIDI controller.

I found the schematics of the keyboard and it has a matrix of [4 x 8] using 2 parallel 74HC138 Encoders/Decoders (3 to 8 or 8 to 3). You would scan the rows for the first IC then pull up E3 on the second IC to enable it and scan then loop. I am trying to figure out whether this circuit is [8 Input x 4 Output] or [8 Output x 4 Input].

According to the schematics, the diodes placed right before the key switches make me think that the current flows only from the diode through the key switch into the 74HC138 hence it is used as a De-multiplexer [8 Output x 4 Input].

I tried using 8 pins in the Arduino as Output and 4 as Input but failed to pull down the 74HC138 output pins and digital read the encoded value.

Any idea on how to connect this matrix with Arduino?

Appreciate your help!

To me it looks like 8 outputs (KD0-KD7), which need pull-ups, and 5 inputs (KA0-KA4).

You need 13 digital pins. On most Arduino, analog pins can also be used as digital pins

What type of Arduino do you plan to use?

I am doing tests with an ESP32-DevkitC which has its internal pullups.

How would I analog read from KD0-KD7? The voltage is always 0 on those pins even when key switches are pressed.

You would not need analogRead. All the pins are digital only.
I can't be entirely sure, but looking at the picture, you would drive one of the KD pins high, and use the KA pins to select one of the decoders and read which of the pins is high.

ESP32 is a 3.3V device. Your keyboard uses 74hc chips, so may work ok at 3.3V even though the schematic shows 5V supply. You can try it. Connect 3.3V to the keyboard connector's 5V input.

You would use digitalRead(), not analogRead(). When I mentioned analog pins before, I thought you might be using perhaps an Uno, in which case you would need to use some analog pins as extra digital pins.

When the key switches are not pressed, those outputs will be floating and could read any voltage. You need to attach pull-up resistors to stop the outputs floating, if you are testing with a multimeter. If testing using an Arduino, then you can use the internal pull-ups.

Once the outputs are pulled up, they will read 3.3V until a key is pressed and the decoders are set to select the set of keys containing the pressed key. Then the output should read 0V.

Perfect, it worked!

The trick was to pull up the floating pins with a 10k ohm resistor.