Program not running

Hi all, I am using the nano board to operate a SG90 micro servo. I am using a 5v supply at 2 amps. I have plugged the 5v line directly into the 5v pin. Power to the servo is separate and not from the board.
I have a program on the nano to run the servo. Nothing was happening. The servo was not moving. When I plugged in the nano to the usb port on my computer the servo started moving according to the programmed instructions. When disconnected from the usb the servo continued to work as programmed.
What would be the explanation for this? I am thinking that when I plugged in the usb the program ran through set up. In the void loop the set up instructions were being ignored for some reason?

But you have to connect GND between the power-supplies.

It might be that using the USB-cable made a GND connection on this path

protective-wire in the main-socket1----your Computers-protective-wire-----------USB-Shielding-------Arduino-nano----GND------------------------------------------------------------------------------------.......

.......------------------------ Protective-wire in the main-socket2---your power-supply-protection-wire--------GND-of-power-supply

I am not powering the servo from the 5v output of the nano board. My connections are exactly as shown in your schematic. The ground connection to the power supply and board are the same.
So this still doesn't explain why the servo was not working and program running until I plugged in the computer usb port to the board. I plugged in and then removed the connection and the program was running as designed to run.
Then I still don't understand why this was necessary.

Please post the sketch that you are running

What happens if you use the external power supply and reset the Nano ?

Seams there is a blocking point quite at the beginning, when the USB connection is not given. This is quite often connected to the starting of a serial connection and a loop, which tries to check and reconnct until the connection is established.

Which nano?
There are several versions

not sure what you mean. I can be a little more specific here. The program does not run until I actually read the serial monitor and the data that I have said to print out.
After that I can disconnect the usb connection on my computer to the board and the progam starts working again.
But I don't want to have to do this to make my program work. It should be working without first having to have the computer connection.
I see that in the past somebody else was having this problem. The fix seemed to be something to do with serial monitor and baud rate etc. I didn't understand it.

Hi, @petercl14

We need to see your code.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

Do you have a line like..

while(!Serial) delay(10);

Or something similar?

-jim lee

1 Like

I am not sure either :slight_smile:
Thats because I don´t have any source code to look at.
If you would publish it here, many people will help to look into it.
@JimLee pointed it out with an example, what I suspect and what probably perfectly well fits to your description. Somehing like this could be the problem.

Yes I do. Here it is;
while(a1<0){
val=0;
a1;
myservo.write(val);
}
this provides a delay at the moment of 10 hours.
Why would this be the problem? I may have to use the reset pin, coding, at the end of the 10 hours. I have suspected this but can't see why it would stop the program from running.

That code snippet makes no sense and I can't see how it would provide the delay that you say it does

Please post your complete sketch, using code tags when you do

see my reply to JimLee. can you explain why it would cause the program not to work? A reset gets the program working again as for example in connecting the nano to the usb port of my laptop. Also a coding reset should also work then to avoid having to use a computer attachment. You want the nano board to stand alone.

If it ever gets into this while loop, it will never come out. If a1 IS less than zero. Nothing in that loop will change it. Hence it goes forever.

-jim lee

it is the elevation of the sun Bob. at the moment at my latitude the sun sets at 7pm and rises at 5am. when the sun sets its elevation becomes less than zero and remains less than zero until sunrise. thus the delay of 10 hours.
sorry for not showing the whole sketch. it is very complicated and to explain it would increase the postings here to infinity.

What is the elevation of the Sun ?

What is it in your sketch that changes the value of a1 and what is this line of code intended to do ?

a1;

Why do you continually write 0 to the servo when doing it once would be good enough ?

the program provides updates to a1. it doesn't remain at a1<0. thus it gets out of the while loop. as I explained the complete sketch is very complex. a1 is a global variable.

The more people know (by following the full sketch) the more they answer their own questions.

The more you answer questions about your own code, the more likely you are to "find" your own mistakes.

That is learned by general human interaction.

What is on pins 0 and 1? WiFi? HC-05?

Hi, @petercl14

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

To add code please click this link;

What is your project?
What has it to do with the sun?

Have you written your code in stages?
If so you should have code that JUST controls the servo.

Load that code and see if the problem still occurs.

Can you post some images of your project?
So we can see your component layout.

Tom.... :smiley: :+1: :coffee: :australia:

Make an mcve.