Arduino pins read HIGH if close pin is high

Hello,

I’m currently building a MIDI keyboard with an Arduino Mega.
I salvaged an old organ keyboard, removed all electronic components and rebuild the contacts (each octave has an aluminum plate below the keys, which get in contact with it when pressed).
Each key is shorted with every other key (so I have 12 inputs, all C will put the same pin HIGH), and each plate is connected to an output pin, so I can “turn on” just one plate at a time and detect which key in which octave was pressed.
This is a simplified schematic (just 9 buttons in 3 groups), I just did it with 48 keys in groups of 12. Values are accurate.
EDIT : Pin 1, 2, 3 are outputs and only one can be HIGH at any time. Pin 4, 5, 6 are inputs and are used to read the buttons.
I have a 18k pulldown resistor (10k would not work, all pins would always read LOW) and some diodes to prevent interference coming back from the common ground.
My code is on my GitHub (it’s kinda long, sorry for the external link).

When one key is pressed, close pins read HIGH and LOW in what seems a pattern (LEDs associated with them turn on dimly, as if I was PWMing them, and do not just blink as if it was noise). Some keys work and do not affect close pins, others instead when pressed turn HIGH even 5 pins.
I tried reading multiple times and ANDing the results, with no effect : the pins next to the one of the key I pressed still behave badly.

I connected just one octave to 5v output (of the arduino, to have a stable reading) and measured voltage on pins : the one which has its key pressed reads 5v, other pins all read 10mV. I redid the same test with the thing working normally and I read 900mV on the closed buttons (due to the pin turning HIGH and then LOW too quickly for my multimeter) and 1mV on the open ones.

I checked continuity and I don’t have shorts across the plates, across the pins or across the contacts.

I fear I may have some internal damage on my arduino at this point, I really have no more ideas to try. Did I miss something?

Thanks for your time!

(deleted)

Your code does not enable the input pins as INPUT_PULLUP so, according to the schematic, when the key is not pressed, that input is floating which is bad. Digital pins need to be either HIGH or LOW. Try enabling pullups:

for (int cNote = 0; cNote < 12; cNote++) {
		pinMode(note[cNote], INPUT_PULLUP);
	}

spycatcher2k:
Do you have pull up or pull down resistors fitted?

I have just one 18k pulldown resistor fitted. Pins are never floating.

blh64:
Your code does not enable the input pins as INPUT_PULLUP so, according to the schematic, when the key is not pressed, that input is floating which is bad. Digital pins need to be either HIGH or LOW. Try enabling pullups:

for (int cNote = 0; cNote < 12; cNote++) {

pinMode(note[cNote], INPUT_PULLUP);
}

I didn’t enable the pins as pullup because I’m using them in pulldown configuration (so I can switch on and off the 5v side). I have a 18k pulldown resistor.

Apart from the useful input above - you may have already realised - your keyboard is organised as a matrix...
Partitioned as octaves.
You only need to scna the octaves - then identify which key/s are pressed within each as it is scanned. Then process as desired.

Alunduyn:
I have just one 18k pulldown resistor fitted.

That’s not right. You need at least as many pulldowns as you have independent keys. 12 pulldowns would probably be enough.

Pins are never floating.
I didn’t enable the pins as pullup because I’m using them in pulldown configuration (so I can switch on and off the 5v side). I have a 18k pulldown resistor.

EDIT: OK, I finally clicked on the schematic in the first post.

Yes, you need 3 pulldowns in that schematic. The diodes are unnecessary.

Alunduyn:
I have just one 18k pulldown resistor fitted. Pins are never floating.

According the schematic link you provided, the arduino input pins are on the other side of the switch from the 18K resistor. That does not make it a pull-down resistor. Your pins are totally disconnected when open.

Or is the schematic wrong?

It isn’t totally clear in the schematic but I think pins 1-2-3 are the matrix “columns” energised by the Arduino and pins 4-5-6 are the inputs.

MorganS:
That's not right. You need at least as many pulldowns as you have independent keys. 12 pulldowns would probably be enough.

EDIT: OK, I finally clicked on the schematic in the first post.

Yes, you need 3 pulldowns in that schematic. The diodes are unnecessary.

Thank you, I went with diodes to test out many values for the pulldown without replacing them all, didn't think using just one could mess it up. Will replace diodes with pulldowns and update.

MorganS:
It isn't totally clear in the schematic but I think pins 1-2-3 are the matrix "columns" energised by the Arduino and pins 4-5-6 are the inputs.

Exactly, I'm sorry it wasn't clear.

blh64:
According the schematic link you provided, the arduino input pins are on the other side of the switch from the 18K resistor. That does not make it a pull-down resistor. Your pins are totally disconnected when open.

Or is the schematic wrong?

My input pins are disconnected from the output pins when the switch is open, but they are always connected to the ground through diodes and a pulldown resistor (see above to the right).

lastchancename:
Apart from the useful input above - you may have already realised - your keyboard is organised as a matrix...
Partitioned as octaves.
You only need to scna the octaves - then identify which key/s are pressed within each as it is scanned. Then process as desired.

I know, it's by design a matrix and I'm doing exactly that to adress each key individually

So did it work with more resistors and no diodes?

MorganS:
So did it work with more resistors and no diodes?

Hell yeah it did!
Thank you so much, I was so sure I did fine!