Certain pins on my Arduino Mega stay HIGH

Hello

I have a problem with my Arduino Mega.
Some digitalRead pins stay HIGH in the following situation:
I have a 12V power supply that goes to a button and than to a voltage divider with a resistor of 15KOhm and one of 10KOhm. When the button is pushed, a voltage of 4,8V is applied to an Arduino pin, the pin is HIGH. When the button is not pushed, the pin needs to be LOW, but this doesn't happen to some of the pins. I figured this out with this piece of code:

void setup() {
for(int i=0;i<=69;i++){
pinMode(i, INPUT);
}
Serial.begin(9600);
}

void loop() {
for(int j=0;j<=69;j++){
String tekst = String(j) + "=" + String(digitalRead(j));
Serial.println(tekst);
}
Serial.println("----------");

delay(10000);
}

I thought that my solder work wasn't done well, but when I make one pin an analog input and read out the voltage divider, the pin gives a result of 0 when the button is not pushed. The pin is also pulled down properly.
The digital pin (Pin 20) connected to this voltage divider still returns HIGH.

The really strange thing however is that when I connect Pin 20 to the GND pin of my Arduino Mega, the pin becomes LOW.

What is my mistake?
How can I solve this?

Kind regards

Jorn Naessens from Belgium

Post a schematic of the project.

Post photos of the wiring.

How is this an Installation and Troubleshooting question?
It is stated at the top of the page:

The section is for problems with Arduino itself, NOT your project

Which pins does the Mega use for Serial?
Why 70 pins?

I agree with your statement but if I were a newbie I would consider "troubleshooting" a valid category (especially since English appears to not be the OPs primary language.

Hello

That was indeed my thinking.
@groundFungus, I don't explain my project because it is much more complex than that. I think that a pin that returns HIGH when it is pulled down, is a problem with the Arduino itself...

Kind regards
Jorn

@ TheMemberFormerlyKnownAsAWOL
I did this because I wanted to see witch pins have this "problem"
This is the case for pin 0, pin 20 and some other pins

1 Like

If it's so complex, how are we supposed to troubleshoot it without any information? Like that, it's easier for you to fix.

Hallo

Here a schematic of the wiring.
A photo won't help much I think

Schermafbeelding 2021-11-01 om 19.53.31

Since you insist, I'll explain my project anyway. (Later don't say it's irrelevant, I know)
I am building a control panel for a model train track. There are buttons for each signal: red, yellow and green. When that button is pressed, the lamp on the control panel should light up, move the track exchange and the signal should switch. So I need to be able to tell my arduino "the button has been pressed". But pin 20 remains high, even when the button is not pressed (I checked, that's really the problem), so I can't switch my signal. I use the Arduino because there has to be logic in the train track. When one is green, the other must be red and so on.

I hope this makes it clearer.

The core problem, however, remains that that a pin remains high even when it is pulled-down. The only time the pin goes low is when it is connected to the GND of the arduino itself.

Kind regards
Jorn

Hello,
pin 20 of arduino mega is connected to SDA and a onboard pullup resistor of 10K connected to 5V.
So with your 10K pull down resistor you should have 2.5V on Pin 20.
This voltage can be read as a "high state"
You should experiment the same proble on pin 21.

Pin 0 is used for the USB communication with the PC.

Not behind a PC at the moment to check schematics.

You will have to provide the full list.

If you disconnect all external circuitry do the pins operate as expected?

Is the 12V- (black wire in your "schematic") connected somewhere to the Arduino ground?

Hello

The 12V power supply for the button is the same power supply as I am using for my Arduino
It is not connected to a GND-pin, if that is what you mean.

Today I will test all my pins to provide a full list.
I will test my voltage divider with smaller resistors, maybe that can help when I see the remark of @Leptro
And I will try to make a photo of the wiring on a breadboard (I will try to build my circuit again on a breadboard)

Thanks for the help in advance

Kind regards
Jorn

Please don't provide a list. Descriptions of electronic circuits are nearly useless. Instead, update the schematic. In the circuit that you've shown so far, a connection to Arduino pin 20 is shown, but there is no ground return to the Arduino. That would never work. With beginners, we never know whether something is really wrong or whether it's not described properly. If you can provide good photos also, it would be immensely useful.

Hand drawn schematics are perfectly acceptable here, so long as they are readable and accurate.

Your voltage divider resistor values are not too big. I think it's not worth changing them at this point.

Is is really necessary to power your "buttons" from 12V? Why can't you just connect one end to ground, the other to the Arduino input directly, and use the INPUT_PULLUP option of the pinMode() function to enable the internal pull up resistors? Then your troublesome voltage conversion circuit would go away.

Actually, since pin 20 has an on board pull up resistor for SDA as mentioned above, configuring the switch in this way would allow you to continue to use pin 20 for the switch with no problems. Same thing with pin 21.

Hello

Thank you for the help.
On the photo you will find the circuit built on a breadboard


But I think you are right and I should use the input_pullup function.
I was afraid the Arduino couldn't deliver enough current to make it work, but that was stupid thinking of me, because I don't need a current, voltage is enough.

Thank you for the help.
I will let you know whether it works or not.

Kind regards
Jorn

Hello

I have installed all the wiring as you said and used the command INPUT_PULLUP.
It all works perfectly now.

Thank you all very much for helping me!

Kind regards
Jorn

1 Like

See reply #13. It would be better not to depend on the ground connection that is made via the barrel connector.

You don't really have the right circuit for INPUT_PULLUP. I suggested not using the 12V with that, but you still are....

With INPUT_PULLUP, there is no connection to any power supply. Just ground.

No
Indeed, you are right
But I changed the complete circuit. I use now the ground connection and INPUT_PULLUP and I removed the voltage divider.

The circuit now is GND->button->Input pin

It works perfectly.
Thanks for the help

John, I'm a railroad modeller myself. I'm aware that 12V signalling is used in many cases. There are some situations where you would need to read those signals, so it's worth knowing for those cases. Usually, those signals are configured as open collector or switch loads connected to ground, with pull up resistors to +12V somewhere, usually on the input. For those, you can also use the voltage divider to convert to TTL levels, but you have to consider the difference that the pull up resistor becomes in series with the upper leg of the divider...