I've got an Arduino mega compatible board, called Ethermega, from Freetronics (ATmega2560).

Schematic here.

In setup, I've written this code:


  pinMode(4, INPUT_PULLUP);
  digitalWrite(4, HIGH); // Optional, I tried with and without
  while (1)
    if (digitalRead(4) == HIGH)

(Don't worry about the fact I'm not using loop)

When I connect input 4 with 5V, I see "Up!". Rest of the time, I see nothing.

Considering I have enabled the internal pull-up, I'm expecting it should be up/high by default, and I would have to connect it to GND to get it low...

Another thing that puzzles me is I can find heaps of examples that use a tactile switch and no pullup/pulldown at all...

So what am I missing or doing wrong? Seems like whatever I do, I've got some kind of pulldown enabled...

  • 3
    pin 4 is CS pin for SD card an it has a voltage divider in the schematics
    – Juraj
    Commented Mar 7, 2021 at 8:47
  • Generally you should not use digitalWrite on an input pin, it might not do what you think it does. If I remember correctly, the register that is used to set high/low in output mode us the same that sets the pullups in input mode. I don't know how the arduino core handles this, though. Just FYI...
    – Sim Son
    Commented Mar 7, 2021 at 9:09
  • @SimSon On AVR: pinMode(x, INPUT); digitalWrite(x, HIGH); is the same as pinMode(x, INPUT_PULLUP);. In general most cores will emulate that for you (I know chipKIT does) but you're right, it's best not to rely on it.
    – Majenko
    Commented Mar 7, 2021 at 10:47
  • @SimSon Yes, I much prefer INPUT_PULLUP or writing the register, it was mostly out of desperation... Commented Mar 7, 2021 at 12:02

1 Answer 1


As @Juraj mentions, pin 4 is the CS pin for the SD card. That pin has a volage divider of 1kΩ + 2.2kΩ on it (a total of 3.2kΩ) to ground. So yes, you do have a pulldown on that pin. 3.2kΩ is about 1/10th of the value of the typical pullup resistor internal to the chip, so pulls the output low enough to be seen as LOW unless you manually override it.

You can't use that pin as an active low input on that board - choose another, or use it as active high.

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.