PWM output being triggered during upload, opening serial monitor

Hi,

I have a mega2560, where the digital output 13 (PWM) is hooked through a resistor to a NPN transistor to control the ground arm of a DC fan.

For some reason, during uploading of code to the arduino or opening the serial monitor there's some output on this pin that causes the fan to start momentarily if I have the DC power to it on.
During normal serial comms, this doesn't happen, but I'm only sending single char messages so they might be too short.

I checked and it seems that pin 13 isn't related to any TX/RX function on the mega.
The sketch is working as I expect and I can control the fan speed normally.

Do I need a pull-down resistor on the output to prevent this? Or do all the PWM outputs just go nuts during an upload?

When you upload code or open the serial monitor, the arduino will go into reset, which puts pin 13 into input mode until your sketch starts and sets it back to output. This is apparently causing your transistor to momentarily turn on. If you can post a schematic someone will be able to suggest a way to prevent this.

(deleted)

spycatcher2k:
Pin 13 will flash to indicate that the bootloader has started! Use a different pin!

Thanks! I saw in the schematic this pin was hooked to an LED but I couldn't find any evidence of dual use there.