element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Raspberry Pi
  • Products
  • More
Raspberry Pi
Blog Controlling a servo motor with the Raspberry Pi
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Raspberry Pi to participate - click to join for free!
Featured Articles
Announcing Pi
Technical Specifications
Raspberry Pi FAQs
Win a Pi
GPIO Pinout
Raspberry Pi Wishlist
Comparison Chart
Quiz
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: fustini
  • Date Created: 8 Feb 2013 1:12 AM Date Created
  • Views 1268 views
  • Likes 0 likes
  • Comments 0 comments
Related
Recommended
  • rpibeginner
  • pwm
  • motors
  • raspberry_pi
  • servo
  • rpi
  • adafruit

Controlling a servo motor with the Raspberry Pi

fustini
fustini
8 Feb 2013
imageWant to build this project?
View Parts

 

image

During the last embedded systems meetup at my hackerspace in Chicago, The specified item was not found., we did hands-on activity where we went through a couple of Adafruit's wonderful tutorials.  First, we learned how to read a photoresistor without an ADC using Adafruit's Basic Resistor Sensor Reading on Raspberry Pi.  Next, we hooked up typical 5V hobby servo motor to the Pi per Adafruit's Raspberry Pi Lesson 8. Using a Servo Motor (written by element14 member simon.monk!):

image

The red board atop the Pi is the Pi Crust breakout board by Pumping Station: One member, Joe Walnes.  It's a compact and low-profile way to interface with the GPIO header.  Alternatively, the Pi Cobbler breakout board is shown in the Adafruit tutorial.  Note: the current Raspbian image doesn't have the Adafruit's PWM kernel module, so it is necessary to run Adafruit's Occidentalis image for the servo tutorial to work.

 

Fellow hackerspace member, Jay Hopkins, had the great idea to wheel over the oscilloscope to demonstrate how the pulse width of the signal on the Pi's PWM pin corresponds to the degree to which the servo rotates:

image

(The spining red board on top of the servo motor is just a spare Pi Crust.  It's only function was to make it easier to see the servo was moving.)

 

The Adafruit servo tutorial has a great explanation of how the position of a servo motor is controlled:

The position of the servo motor is set by the length of a pulse. The servo expects to receive a pulse roughly every 20 milliseconds. If that pulse is high for 1 millisecond, then the servo angle will be zero, if it is 1.5 milliseconds, then it will be at its centre position and if it is 2 milliseconds it will be at 180 degrees.

 

http://learn.adafruit.com/system/assets/assets/000/003/496/medium640/servos.png?1357725423

(source: Adafruit)

 

 

Here's a short clip showing the signal on the scope while the servo rotates:

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

Here's a longer clip where I explain the setup in further depth:

 

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

 

 

Cheers,

Drew

http://twitter.com/pdp7

 

 

Product Name*DescriptionSupplier
Raspberry Pi Model B Raspberry Pi model BRaspberry Pi
Buy Now
Optical mouse Basic USB optical mouseIONE / Pro Signal
Buy Now
Raspberry Pi power supply 120-240v to 5V power supply with micro USB connectorRaspberry Pi
Buy Now
Keyboard Basic USB keyboardGear Head / A4 Tech
Buy Now
Pre-programmed 4GB SD card 4GB Class 4 SD card preloaded with Debian 6 LinuxSamsung
Buy Now
Adafruit Pi Cobbler GPIO breakout kit for Raspberry PiAdafruit
Buy Now
Breadboard Basic breadboard with 830 connection pointsTwin Industries
Buy Now
Jumper wire bundle Jumper wires for use on breadboardBud Industries
Buy Now
5V Servo Motor Basic hobby servo motor, 5VAdafruit
Buy Now

 

*Products and resources listed are listed to help members build their own Pi Projects. They are suggestions and listed for educational purposes. For substitutions of any parts, please post a question asking the original author.

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube