Drive hobby servos for grippers, pan-tilt heads, and small robot joints.
Open in compiler →/*
Roboda verified Arduino sample 0731
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 = 2;
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.
- Connect servo signal to servoPin.
- Power the servo from a suitable supply and share GND.
- Attach the Servo object to the pin.
- Write a new angle every loop.
Connections
| Pin | Connect to | Note |
|---|---|---|
| D11 | Servo signal wire | Power the servo from a suitable 5V supply and share GND with Arduino. |