A little curiosity. A whole lot of making.Robotics, CNC & connected ideas
robodatech.
Arduino sample library

Servo Sweep 36

Drive hobby servos for grippers, pan-tilt heads, and small robot joints.

Open in compiler →
/*
  Roboda verified Arduino sample 0881
  Feature: Servo Sweep
  Generated for online build, classroom practice, and hardware upload testing.
*/

#include <Servo.h>

Servo joint;
const byte servoPin = 11;
int angle = 0;
int delta = 4;

void setup() {
  joint.attach(servoPin);
}

void loop() {
  joint.write(angle);
  angle += delta;
  if (angle <= 0 || angle >= 180) {
    delta = -delta;
  }
  delay(15);
}

How it works

Move a hobby servo smoothly across its angle range.

  1. Connect servo signal to servoPin.
  2. Power the servo from a suitable supply and share GND.
  3. Attach the Servo object to the pin.
  4. Write a new angle every loop.

Connections

PinConnect toNote
D11Servo signal wirePower the servo from a suitable 5V supply and share GND with Arduino.

Good ideas start here.

Robotics lessons, build notes and useful updates. Subscribe by entering your email.