What We're DoingSpinning a motor is good fun but when it comes to projects where motion control is required they tend to leave us wanting more. The answer? Hobby servos. They are mass produced, widely available and cost anything from a couple of dollars to hundreds. Inside is a small gearbox (to make the movement more powerful) and some electronics (to make it easier to control). A standard servo is position-able from 0 to 180 degrees. Positioning is controlled through a timed pulse, between 1.25 milliseconds (0 degrees) and 1.75 milliseconds (180 degrees) (1.5 milliseconds for 90 degrees). Timing varies between manufacturer. If the pulse is sent every 25-50 milliseconds the servo will run smoothly. To achieve this on the Netduino we will use its PWM function.

namespace NCIR04 /// Define the namespace we are in ///
{
public class Program /// Define any variables used in the program and subrout //ines after Main()///
{
public static void Main() /// The Main loop (run at power up) ///
{
/// Setup Portion of Program, runs once at startup ///
PWM servo = new PWM(Pins.GPIO_PIN_D9); //creates a new PWM object the servo is //connected to

servo.SetPulse(20000, (uint)pulse); //pulsing the pin for the desired amount of //time
}
} /// Close the Program Loop ///
} /// Close the Namespace Loop ///

Not Working?(3 things to try)

Servo Not Twisting? Even with colored wires it is still shockingly easy to plug a servo in backwards. This might be the case.

Still Not WorkingA mistake we made a time or two was simply forgetting to connect the power (red and brown wires) to +5 volts and ground.

Fits and StartsIf the servo begins moving then twitches, and there's a flashing light on your Netduino board, the power supply you are using is not quite up to the challenge. Using a fresh battery instead of USB should solve this problem.

Making it Better?

Changing the Sweep Speed:Not happy with the speed the servo is moving? You can change this by altering the code. Simply change:

# = degrees per step. Send to a Specific Angle: To get the servo to go to a specific angle rather than sweep, change the code after while (true) to:

setServo(servo, ###);

### = angle between 0 & 180 degrees

Mixing and Matching:

Each circuit in this guide is rather basic. The real fun comes when you start using multiple components and real world items to make something neat. The controlled movement of a servo is very helpful in this, so get thinking and creating.