Servo Motor Control Using Raspberry Pi

In this wiki section you will find the sample code and the hardware interfacing for controlling a servo motor using Raspberry Pi 2. Raspberry Pi is a hot topic and also you might have seen many wiki posts on Raspberry Pi 2!!..But whats so much fascinating about controlling a servo??. It is fascinating for many reasons, but it will be more than that for you, if you are entranced in robotics. Robotics is a very popular field of research right now with many ideas on what will be the next big advancement. Over the years robotics have branched off into many different specialisation streams; Humanoid robotics, Biomimetics, Telerobotics, Adaptive robotics are the most popular of them. Advances in robotics are happening at a truly amazing rate. The capabilities that we have now compared to 10 years ago are staggering and the trend of increasing capabilities will extend into the future.

As quoted by someone in the past, “Anyone who is interested in robotics has to learn from the basics of servo motors”. Time has gone far by, but the quote stands true for all. Servo Motor is nothing but a simple device which uses error-sensing feedback signals to determine and control the position of a motor shaft. In section below you will find the hardware interfacing for controlling a servo using the Raspberry Pi 2, a sample sode is also given below which you can modify and suit yourself!

Hardware Interfacing

The hardware modules used in this tutorial are mentioned below:

  1. 5V, 1A Power Supply
  2. Raspberry Pi 2
  3. Analog Servo Motor
  4. Connecting Wires

Servo motor has got three connection pins, Vcc, ground and signal. It requires a 5V 1A power, which is provided from a suitable supply source. On the Raspberry Pi board, GPIO pin number 22 is selected as the signal pin. The GND pin of the power supply is connected to the ground pin of the servo and also to the 6th pin on the Raspberry Pi. After providing suitable connections open the python editor and program the Raspberry Pi. A sample code is given below, which you can use as it is or you can modify it to suit yourself.

Sample Code

 As per the above program the servo rotates 180 degrees. The length of the pulse will determine the position of the servo. Equivalent  duty cycle is calculated for an angle and the RPi will generate a pulse for the calculated duty cylce, which will be send to the servos signal pin every 10 milliseconds. When executed the servo will rotate in a to and fro motion as shown in the illustration above.

Raspberry Pi kit along with servo is a great package for developing real time robotic projects as the RPi supports both image and audio processing units. The servo can be controlled on the basis of the output obtained from image processing operations, which would aid realizing innovative robotic ideas.

Related Topics

Shop With Us

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">