Make a servo sweepTinkerPieCircuit tutorial 12 of 24 · Beginner · 10 minutes
Connect a servo motor to power and a signal pin and sweep it from 0 to 180 degrees.
Open this circuit in TinkerPieCircuit (free, runs in your browser)
What you will learn
- Servo wiring: ground, power and signal
- servoWrite(pin, angle)
- for loops
Parts
Steps
Add the servo
Click Servo motor. It has three wires: G (brown), V (red) and SIG (orange).
Wire the power
Wire G to
GNDand V to5V. Servos need more power than a pin can give.Wire the signal
Wire SIG to
S1. The signal tells the servo which angle to go to.Sweep with a loop
A
forloop counts from 0 to 180 in steps of 10 and callsservoWrite(S1, a)each time.Press Start
The horn of the servo turns and the label shows the angle. If the label says no power, check the V and G wires.
The code
function loop() {
for (let a = 0; a <= 180; a += 10) {
servoWrite(S1, a);
delay(40);
}
for (let a = 180; a >= 0; a -= 10) {
servoWrite(S1, a);
delay(40);
}
}
Copy this into the Code tab. It is Arduino-style JavaScript. The real board uses the same pin names (S1, P10…) in TinkerPie Studio.
How it works
The signal pin sends short pulses. The length of each pulse tells the servo the angle. TinkerPie handles the pulses for you.
← Build a night light · All 24 circuit tutorials · Play a melody with a buzzer →