Difference between USB connection and separate power supply?

For the first time ever I have today been using my Arduino Uno connected to an external 12 V DC power supply instead of as connected to the USB port. To my surprise, instead of executing the loaded sketch, only the pin 13 LED was rapidly flashing. I connected the Uno back to the USB port instead of the external power supply and everything was working fine again.

Any idea what is going on here? In the loaded sketch, I do use the USB interface for transmitting data. This is however only happening in a part of the sketch, while other parts of the sketch do not do any communication (those parts which should have run when I connected to the external power supply). I do however always initialize the serial port at the very beginning of the sketch, independently of which sketch parts will actually be executed. Is it possible that the initialization with unconnected USB port is the reason for this behaviour? And if so, how can I automatically determine in the sketch whether the USB port is connected or not (in order to avoid any initialization or communication attempt when the USB port is not connected)?

Any help is greatly appreciated. Thank you very much.

Are you sure that the power supply is producing clean DC? Are you connecting to the power port or the Vin pin?

If you have three AA or AAA cells you can wire them in series and connect the (roughly) 4.5v to the 5V pin and the negative side to ground. If you sketch runs properly on battery power I would suspect a problem with your 12V supply.

I ASSUME that the power supply produces clean DC (but I don't really know nor can verify it). It's a standard power supply in plug form as they come with many devices. I am connecting it to the power supply plug on the Uno, not to the Vin pin.

As soon as I can procure AA cells I will try your suggestion.

Can anyone exclude that it is an issue with initializing/accessing the USB port from the sketch while there is no USB port attached?

Thank you, Johnwasser, and all others who might still answer!

I have successfully run various sketches that do Serial I/O on a Diecimila and UNO when not connected to a USB cable. This worked with a 9V 'wall wart" transformer, a 9V 'transistor' battery, a 6-cell (9v) AA battery-pack (all connected through the power jack) and a 4.5V battery pack connected to the 5V pin.

I ASSUME that the power supply produces clean DC (but I don't really know nor can verify it).

Measure the voltage with a multimeter or oscilloscope, while connected to your Arduino. (e.g. measure VIN or right on the barrel jack.)

Can anyone exclude that it is an issue with initializing/accessing the USB port from the sketch while there is no USB port attached?

It is very unlikely this is the issue. Many of my projects send stuff to the serial port even when nothing is connected to it.

The behavior you describe sounds like the board is resetting. What is the total current are you drawing off of the 5V pin? Keep in mind that if the on-board regulator starts to over heat it will shut down (which can cause a reset.)

Hello again. I still have the same problem and need to resolve it now. By now I know that it has nothing to do with trying serial communications without the USB port being connected. I also know that the reason is not the 12 V DC power supply itself (i.e. it produces clean 12 V DC)

Regarding JamesC45's comment: All I/O ports are used, but I don't think that I am drawing too much current off of the 5 V pin. The 12 V power supply can provide up to 1 A, which I do not need. If there were not sufficient current available, would it not be more likely to have this situation with the USB port only?

The symptons are still the same: When I only connect the 12 V DC power supply (WITHOUT the USB port) the pin 13 LCD flashes rapidly, nothing else happens. Unfortunately, as the USB port is not connected in this case, I can not check into the sketch what is happening. When the is connected via USB or via (USB AND 12 V DC power supply), the program executes correctly.

Is there maybe a difference between the different GND pins? I would assume GND is GND and it should not matter which of the different GND pins I use?

Thank you very much for any help.

I've got almost the same issue with my nano.
Your problem is little bit different you say that LED at pin 13 starts to blink rapidly. That could mean that your board ist reseting. So my question is do you have original UNO or some chinese fake one ? and try to use different auxiliary power probably 9V battery because 12V and 1A its near the maximum of what onboard regulator can handle. Also chceck if its not heating itself

edit :

oh and I found this maybe it can help

Why doesn't my sketch start when I'm powering the board with an external power supply? (Arduino Diecimila or earlier)
Because the RX pin is unconnected, the bootloader on the board may be seeing garbage data coming in, meaning that it never times out and starts your sketch. Try tying the RX pin to ground with a 10K resistor (or connecting RX directly to the TX pin).

Thanks very much for your answer. Not sure whether I understand correctly. What could make the board reset? Insufficient power? Or too much power? If it is too little, am I wrong thinking that the separate power supply provides more power than the USB port?

What do you mean by "12V and 1A is near the maximum of what onboard regulator can handle". Is it too much or too little?

My Uno is an original one (should be at least, but I am quite sure that it is).

I mean it could be too much
onboard regulator on UNO is MC33269D or something like that here's datasheet : MC33269D-5.0 pdf, MC33269D-5.0 Description, MC33269D-5.0 Datasheet, MC33269D-5.0 view ::: ALLDATASHEET :::
maximal Input voltage is 20V so that's fine, but max. current output is 0,8A and your adapter is providing 1A. So maybe this causes reseting, if it's original UNO that's confusing. When your adaptor is plugged in is arduino hot ? and try 9V battery or something less than 12V.