Arduino Mega 2560 + RAMPS voltage on GPIO pin I am using an Arduino Mega 2560 and RAMSP 1.4 shield with Marlin firmware to control my machine (not exactly a 3D printer). Marlin has G-code:


M42 P20 S255&nbsp;==> Turn on pin 20 of the microprocessor 
M42 P20 S0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;==> Turn off pin 20 of the microprocessor


I am using this command to turn ON a MOSFET switch connected to pin 20.

When I have not put the RAMPS shield on top of AtMega,  this works. Pin goes high only when I send code to turn it ON.

But when I place the shield on top of the Mega 2560 (No 12&nbsp;V power is given to RAMPS, only 5&nbsp;V from USB), when I first connect USB to it, I find around 2&nbsp;V on Pin 20 even without sending the ON command. when sending M42 P20 S0 this goes away (0&nbsp;V) and get 5&nbsp;V for M42 P20 S255. Without shield there's no voltage when connecting USB to Mega 2560; with shield there's 2&nbsp;V on the pin and this causes the MOSFET switch to turn on. 

Where does this voltage comes from? 

First I thought this must be some noise, so added a 10K pull down resistor (since that is the common value I have seen in many circuits), but it didn't work. But placing a 100&nbsp;Ohm works. Is this safe?
Connecting a 100&nbsp;Ohm resistor is definitely not safe. This load is far too high for an AtMega2560 output pin. 100&nbsp;Ohms at 5&nbsp;V (when the pin is high) is 50&nbsp;mA, whereas the recommended maximum for an AtMega2560 pin is 20&nbsp;mA (and it would be better to stay well below this maximum). You should use a higher value pull-down resistor (at least 250&nbsp;Ohms, more would be better) or find out where the stray voltage is coming from (it could be an internal pull up on the AtMega, since pin 20 is also the SDA pin which Marlin might enable).