Powered by TinkerSpace
Join free
TinkerPy Projects lessons
๐Ÿฆพ
Lesson 7 of 10 ยท Explorer ยท 12 min

Move a servo

Turn a servo motor to any angle from 0ยฐ to 180ยฐ.

๐Ÿ”Œ Wiring

Connect a servo motor to output o1.

Add from servo import * at the top to use servo functions. servo_write_angle(o1, 90) points the servo to 90ยฐ โ€” straight up.

TinkerPy
from tinkerpy_mega import *

from servo import *

def setup():
    set_function(o1, SERVO)
    servo_write_angle(o1, 90)
    wait(1000)

def loop():
    servo_oscillate(o1, 90, 0, 180, 5, 20)
Starts in the middle, then sweeps from 0ยฐ to 180ยฐ and back.
๐Ÿ’ก Tip

The last two numbers of servo_oscillate are the step size and the delay. Smaller step or bigger delay = slower, smoother sweep.

๐Ÿš€ Your turn

Make a waving hand: sweep only between 60ยฐ and 120ยฐ.

Chat with TinkerPy ๐Ÿ‘‹