Arduino Mega Pins staying high

Hello all,

I have an Arduino Mega and several of the pins (19-21) are registering as 5 volts on my multimeter when I have them set to LOW "digitalWrite(19, LOW)" in the code.

Is there something I am doing wrongly?

TIA

Did you declare them as outputs in void setup() ?
pinMode(19, OUTPUT);
for example.

I have them declared as INPUTs since I intend to hook them up to IR light gates.

Inside void setup():

#define PINsensor1 19
pinMode(PINsensor1, INPUT);

Well there you go then.

If they are Inputs and you set them Low, I believe the code disconnects the internal pullup resistors.
You need to declare them as Outputs for digitalWrite to actually drive them high or low.

Thank you, CrossRoads, that does make sense.

I was worried perhaps the pins were damaged. :sweat_smile: