Controlling servos with Nano

Hello, I'm trying to use my Arduino nana to control a Servo with the Servo.h library. Even when I'm just attaching the Servo (S1.attach(3)) and from there on it starts to make random movements. I tried a lot but nothing seems to solve my simple Problem.

#include <Servo.h>

Servo myservo;  // create servo object to control a servo
// twelve servo objects can be created on most boards

int pos = 0;    // variable to store the servo position

void setup() {
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop() {
  for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
    // in steps of 1 degree
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
  for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
    myservo.write(pos);              // tell servo to go to position in variable 'pos'
    delay(15);                       // waits 15 ms for the servo to reach the position
  }
}

Welcome to the forum

Can I suggest that you change the title of the topic to English in order to get more users to read it

Alternatively you could change the body of your post to German and it can be moved to the German section of the forum

Most servo problems come from a supply that can't deliver the stall current.
That could be 650mA for a tiny SG-90 or 2.5Amp for a MG996.

  1. don't power a servo from/through the Arduino.
  2. don't forget to also connect servo ground to Arduino ground
  3. use an external supply that can deliver the stall current for all connected servos.

Leo..

How to connect external servo power supply.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.