Introduction: Using a Servo

Picture of Using a Servo

The two servos supplied in the kit are 180 degree servos. This means they can only turn half a rotation. You may use them to steer your robot or to pick up the ping pong balls.

To power them, you can connect them directly to the arduino because they don't draw too much current.

The servos each come with a few different servo horns so choose a horn that will be best suited for your application and push it firmly onto the white head of the servo. I would recommend putting the screw in at a later stage as you may have to adjust the position of the servo horn.

Step 1: Wiring the Servo

Picture of Wiring the Servo

As you can see, the servo has three connectors, one goes to ground, one to +5V and one to signal. The colour of the wire indicates where it will be connected. (Brown wire goes to ground, red wire goes to 5V, and orange wire goes to signal)

Wire the servo using three male connectors. Connect the brown wire to the ground rail on the beadboard and the red wire to the 5V rail on the breadboard. Lastly connect the orange wire to a PWM pin on the Arduino Nano. (Digital pin 3,5,6,9,10, or 11)

Step 2: Programming the Servo

Below is an example code that may be used to control the servo. You may open this on the Arduino IDE but you need to know what each part of the code does in order to integrate it into the coding of the rest of your robot. Comments are included in the code to explain what the function of each part of the code is.

#include <Servo.h> //Use the servo control library 
Servo myservo; //Create a variable to control the servo (you can name it whatever you want)
const int val = 90; //This value stays constant throughout the sketch and can be altered to produce the desire effect void setup() //This is the part of the code that will run once on startup { myservo.attach(11); //Attach the servo to digital pin 11. If you connected //the servo to pin 7, for example, then say pin 7 here. } void loop()//This part of the code will run repeatedly until the arduino is switched off { myservo.write(val);//Write the value of "val" to the servo. This will be the degree to which the servo turns delay(1000); //wait for 1000ms or 1s myservo.write(val-90); //turn the servo to a degree of "val-90" delay(1000); //wait for 1s }


About This Instructable




More by Robotics Competition:Use of the L298 H-Bridge With ArduinoUsing a HC-06 Bluetooth Module to Get Inputs From an Android PhoneIf, For, While, Map, and Switch Cases
Add instructable to: