servo programm stops

Hello,

I’m new here and wrote my first program on a Arduino One. I want to move a Servo from point 0 to 90 and back. But my program stops after some minutes and sometimes it seems like the Servo goes from 90 to 0 then fast backward and starts new.

#include <Servo.h>

Servo servo;
void setup()
{   
  servo.attach(6);
  servo.write(0);
  delay(5000);
}
  
void loop()
{
  servo.write(90);
  delay(500);
  servo.write(0);
  delay(500);
}

It’s a very simple code, so i don’t understand what’s wrong.

Thanks for help
Kanubelkarl

What sort of servo? How are you powering it? What makes you think that the actual program has stopped? Is it just that the servo stops moving?

Steve

Hello,

thats an MG90S
The Programm is sometimes hanging and sometimes the programm is restarting. I wrote some lines with a output in the cmd and so I saw that the programm starts new.

Thanks
Kanubelkarl

Are you powering the servo from the Aruino 5V pin? If so, the current the servo needs is too high for that, so you need an external supply for the servo.

That sounds very much like a power supply problem. You did not say how the servo is powered.

If you're certain that the Arduino resets and so runs setup() again (there's nothing in your code that would show you that), then it is a problem with power or wiring. The code is fine.

If you answer my earlier question about how you are powering the system and include a wiring diagram it will be easier to help. Meanwhile if you have the MG90S connected to the Arduino 5V pin move it over to 4 x NiMH rechargeable batteries and see if that helps.

Steve

move it over to 4 x NiMH rechargeable batteries

and don't forget to connect a common GND between the batteries and the Arduino

UKHeliBob:
and don't forget to connect a common GND between the batteries and the Arduino

Thanks for that. I often forget to say it because it's so ingrained in my brain that I automatically connect grounds without any real thought involved!

Steve

One of the main problems I find when answering questions here is determining the level of knowledge of the poster. On one hand you don't want to insult anyone by assuming that they know nothing but on the other hand how much can you assume that they know ? Difficult !