Pin 2 does not work for input but 3 to 13 do

I am trying to use pin 2 as input with a push button providing the input. The code and schematic are a bit complex as I am using 2 thru 12 as input and output. For that reason I will simplify a bit

On pin 2 I get no response. No signal nothing. When I do nothing but change the wire from pin 2 to pin 13 it works fine. This happens on 2 Arduino Uno clones that are Ruggeduino SE

#define headUpSignal 2 
#define headDnSignal 3

void setup()
{
     digitalWrite(headUpSignal, LOW);
     pinMode(headUpSignal, INPUT); 
     digitalWrite(headDnSignal, LOW);
     pinMode(headDnSignal, INPUT);
}

void loop() 
{
      HeadUpSwitch = digitalRead(headUpSignal);
      HeadDnSwitch = digitalRead(headDnSignal);      

     ..... do stuff.
   
}

HeadUpSwitch is always zero even if button is pressed. HeadDnSwitch changes as expected as button is pressed and released

redefining headDnSignal to pin 13 and changing that 1 lead fixes the issue.

Any ideas would be appreciated. Thank you .

As a second item if this circuit should be different please let me know. The resistor shown is 10k

I am not allowed to upload so I pasted a picture.

image

Your picture is not readable on my system. Post a schematic, not a frizzy picture it makes things a lot easier for all. More code would help.

image

Use this instead

void setup()
{
     pinMode(headUpSignal, INPUT); 
     pinMode(headDnSignal, INPUT);
}

Writing to an input pin effects the pull up state of and input. With your wiring you don't want an input pull up because you are using a pull down resistor. This puts you in conflict and on the limit for working. This is probably why it works on the other pins despite your error in software.

You are missing the GND connection to the pulldown resistor on your image. Therefore, your button would connect 5V to the pin when pressed, and go high impedance (open circuit) when released. Therefore, nothing will happen on most of your pins set as input.

Makes sense ... you don't need the pulldown here because there's probably already a weak pulldown for pin 13 on the PCB:

D13 LED Isolated
The LED connected to D13 is isolated by a transistor circuit rather than being driven directly from the ATmega328P pin. This isolation draws much less current from the ATmega328P pin allowing it to be used for other purposes.

Therefore, the circuit for D13 (including your pushbutton) is probably something like this:

Hi dloyd, thanks for the reply. Can you tell me what software you used to make your schematic please. Thanks.

I normally use KiCad, but this is just a touched up image from the web using Microsoft Paint 3D.

Hi Paul, thanks for the reply and the picture. Can you tell me where this drawing originated?

Thanks Colin

I was not allowed to upload anything as a new user. My only option was a picture.

OP is writing a LOW so no internal pull-up.

Hello colinb1960
The picture was made by user LarryD.

Have a nice day and enjoy coding in C++.
Дайте миру шанс!

Thank you everyone for the help. Seems I have burned out pin 2 but the arduino is still usable as is.

Cheers,
Colin

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.