Learn how to use Sparki's Servo


Lessons You Should Know

Sparki has a servo motor that moves its head around.

Top - Servo

How It Works

Servo motors are special types of motors that can go to the exact position that you tell them to. They can do this because in addition to the motor, it has a sensor that measures the position of the motor, and a chip that uses the position information from the sensor to control the motor.

Servo Diagram
When the chip detects from the position sensor that the position is not where it is supposed to be, it tells the motor to move towards the correct position until it reaches it. You can tell the chip what position it is supposed to be by sending it a special signal.Don’t worry, Sparki’s servo code below already takes care of sending this special signal. All you have to tell it is what angle! 50 times a second (or every 20 milliseconds), this signal sends a on-off pulse. The length of this on-off pulse tells the servo what position it should be in. If it is 1 ms, then it should be 90 left. If it is 1.5 milliseconds, then the servo should be centered. If it is 2.5 ms, then it should be 90 degrees right:

Servo Timing Diagram

For Sparki, the angles are these:

Servo Angles

Using the Part

With the basic Sparki code in place, you can tell the servo to move using these commands: You can use any number from -90 to 90 in place of degree. This is equivalent to looking left and looking right. You can also use these keywords (in all caps): SparkiDuino already has code examples for you to use: File > Examples > Servo