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
==> Turn on pin 20 of the microprocessorM42 P20 S0
==> 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 V power is given to RAMPS, only 5 V from USB), when I first connect USB to it, I find around 2 V on Pin 20 even without sending the ON command. when sending M42 P20 S0
this goes away (0 V) and get 5 V for M42 P20 S255
. Without shield there's no voltage when connecting USB to Mega 2560; with shield there's 2 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 Ohm works. Is this safe?