Repowering Arduino while connected to PC

I have a PC connected to the USB port on my Mega 2560 Arduino-based still controller. Everything is fine when the Arduino controller is turned on and then the PC is turned on. However, when you shut down the Arduino controller and then restart it, the Arduino controller goes amuk. Here are some important facts. If I disconnect the USB connection to the PC before shutting down the Arduino controller, the Arduino controller restarts just fine. Then, when I reconnect the USB port, everything works fine. The Arduino controller has its own 9 vdc power supply plugged into Arduino and it, of course, shuts down when the controller is shut down. Do I have to instruct the user to disconnect the USB port if he is going to power down the controller and then power back up or is there something that can be done in software to make it work without disconnecting the PC? I suspect the problem has something to do with the reset that is done (or not done) when powering back up. When the controller powers down, the 9 vdc supply turns off, but if the PC is still connected, I think power is still supplied to the Arduino through the USB. This does not seem to work. On the other hand, if the PC is disconnected, all power is removed and when the controller is powered back up, the Arduino goes through the normal power up sequence, which works fine.

I've read many of the "reset" posts, but have not found anything relative to this issue



I had a similar problem when trying to reset the DS1307 RTC. It appeared to me that any Serial commands across the USB port that remained acitive in the program caused the Arduino to do a reset if it saw a Serial statement in the code. My solution was to surround the Serial commands with a:

#define DEBUG
// Code...

void setup()
#ifdef DEBUG

and surrounding all of the Serial commands with the #ifdef preprocessor directive. If I commented out the #define, everything with the RTC worked fine. In my case, it apeared that the Arduino does a reset when it sees the Serial.begin(), which threw off the DS1307. Give it a try and see what happens.

I find your use of the phrase "arduino controller" confusing. Do you just mean the Arduino Mega or is there another device controlling the Mega?

If you just mean the Mega I don't understand

The Arduino controller has its own 9 vdc power supply plugged into Arduino and it, of course, shuts down when the controller is shut down.

How is the controller (whatever that means?) shut down? and how does the power supply know to shut down at the same time?


Robin2, The Arduino is the only controlling device. It is in a cabinet with a 9 vdc and 5 vdc power supply. The 9 vdc connects to the Arduino power plug and the 5 vdc connects to all the I/O interface circuitry in the cabinet (switches, temperature sensors, lights, SSRs and 7-segment displays via I2C bus). When the ESTOP button is depressed, all power to this cabinet turns off, meaning that the power supply stops producing 9 and 5 volts. However, even though all controller power is removed, I think Arduino still gets power through the USB port from the attached PC and that is where the problem is created. I simply don't know how the Mega handles the transition from an external supply to a PC-via-USB supply and then back to the external supply. It may be as simple as the Mega doesn't reset when switched back to the external 9vdc from the PC-via-USB power so my declarations and set-up code are not executed.

econjack, I'm not sure we have the same issue. My program is around 25,000 bytes in length and I'm afraid I will get into more trouble than its worth to experiment with your approach.

You haven't said if the PC is always connected to the Mega or whether there are times when the Mega is expected to work without the PC connected.

If the PC is always connected then why bother to power the Mega independently?

If the PC is only connected occasionally it might make sense to get an FTDI cable and only connect the Tx and Rx pins and Gnd so that the PC doesn't cause a reset. (Tx to Rx etc).

Another line of investigation is why can't your code cope with an unexpected reset? And if it can't then the FTDI cable may be the only approach.


Robin2, The still must operate independently of the PC. Also, I need a big power supply anyway to power all the other stuff. The PC is used to upload programs to the Arduino and it can be used to log data using MakerPlot. My code might be changed to cope with the situation if I knew what was going on. I am only speculating at this point.

I was hoping someone on this forum might have run into the same issue and have an easy answer. If there is no easy answer, we will simply require disconnecting the USB port when the unlikely need to power down and then re-power the Arduino happens.

When you say

the Arduino controller goes amuk

what exactly do you mean?

Normally if you open a serial connection to an Arduino using the USB cable it will cause to Arduino to reset. It’s the opening of the connection that causes a reset, not plugging in the cable.

I have a veroboard 328 which is running my fridge - conceptually similar to your still, but much simpler. I can upload programs using the FTDI cable for which I have a 6-pin connector on the veroboard. I also have a second connector that doesn’t have a pin for the RTS signal so that it will NOT cause a reset. I use that if I want to read accumulated data about the fridge performance.

In your case you could also omit a connection to the 5v line so that your Mega is never powered from the PC. As the Mega has 4 USARTs you could do your communication with the PC and an FTDI cable using one of the extra USARTs.

FTDI cables are not very expensive and may find lots of other uses.