Arduino Nano - 5V input vs USB

I have a Arduino Nano project that works well when connected to the computer using USB: I can see the messages correctly on the Visual Studio code monitor, the leds are working well, and also a servo motor is working well.
When I connect external power to the USB input, all is working well too.

But, here is the strange thing: if I connect the same external power to the +5V signal, the Nano starts running correctly, and then hangs. As if it finished the first LOOP cycle, without restarting it.
Any idea what can cause such a thing?

Without seeing the whole code what chance do we have of being able to spot your error?

I think that since code works well when connected to the computer, or when power is applied through the Nano's USB, it shows the code is not the issue.
Is that a wrong assumption?

The problem is when the power is applied to the 5V & GND pins, which I was sure is exactly the same as connecting it to the USB port.

How are you delivering power to the 5v pin? Spliced USB cable?

Are you sure about the board? Maybe it's a 3.3v only board but has a 5v pin because the PCB is reused?

The power is provided using a USB cable with wires at the other end - I use the red &black wires. If this is what you call " spliced" -then yes.

I am not sure I understand the "reused pcb" comment: I am using the good old Nano. They all have 5V pin for regulated 5V input, and Vin for 7-12V (which I don't use)

There are some boards that are 3.3 or 5v variants but if you know for sure it's a Nano then you should be fine.

Do you know how much current is being drawn by the project? Using just the red and black wires may not deliver the necessary amperage.

Giving that we have little else to go on yes I think it is a wrong assumption.
When supplying power to the USB you can also supply power to the USB to TTL converter as well, depending on the exact circuit of the board.
is it a clone or a genuine Arduino board?

You are not driving a motor or relay are you?
Also are you trying to use the touch sense library?

A look of the code would tell us all that.

What is connected to the Nano? ie. LEDs, screens, modules, sensors...

I had something like this with a Uno. Whenever it overdrew milliamps through the board the code would hang. I was not powering through USB, rather a LM7805.

What model did you have LM78L05(100ma output) or LM7805(1A output)?
I find it hard to believe that your board would draw more then 1A without activating internal chip protection.

I would say your power source didn't have enough "juice".

I could run my Raspberry Pi 4 of a LM7805 with a good power source.

I had some heavy running modules attached, that was my point.

That drew more then an 1A?
Didn't the regulator feel a little warm or did you have passive/active cooling?

Some answers to your questions:

  • The motor is SG90 small servo motor. The power to the servo is the same 5V that goes to the Nano, so the servo is not consuming power from the Nano.
  • The Servo is PWM operated through the Nano IO. No relay.
  • I think it is a clone, I don't know what is the difference. I am using it for many projects. I also switched between few Nano's to make sure it is not a specific Nano issue.
  • I am not using the touch lib. The only lib I am using is the servo. The LEDs are operated with 220Ohm resistor.
  • The Voltage is staying stable on 5.1V, while the current is changing between 20mA to 40mA (the larger is when the the servo is working).

I was sure that the 5V input pin (unlike the Vin) , is connected directly to the USB 5V pin.

3 LEDs and one SG90 small servo motor are attached.

Try without motor.

After some more testing, the problem is surely related to the Servo motor. Without the servo, all is good.
With the servo - it depends on the power source:
With a wide short USB cable connected to power -no problem.
With a spliced USB cable (thin wires) connected to the 5V pin - the Nano is getting reset.
With 18650 battery - reset.

I don't think the PWM signal is sourcing too much current from the Nano, to make it reset.
Perhaps the servo drawing so much current that makes the Nano input 5V unstable??

I cannot answer that without usable information.

Precisely, there is a lack of usable information from @yigalb .

However, be aware that all motors generate interference, which is capable of resetting an Arduino, particularly when there is a poor layout or lack of decoupling components.

What is the chance, do you think, of getting a schematic and good quality photograph, from this member who is not cooperating with us?

Problem solved: A soldering was missing on one connector pin. There was a connection "most of the time", yet with a small movement it caused the reset. Thank you all for the help.