← Back to search

How To Control A Standard Servo With Raspberry Pi

Core Electronics 7:40

118,191 views · 2,066 likes Watch on YouTube ↗

Demonstrated here is the fast way to control either small 9-gram servos or a much more powerful 15KG servo using a GPIO Pin on a Raspberry Pi.
Article with Code - https://core-electronics.com.au/tutorials/control-servo-raspberry-pi.html

Related Information
16 Servo Adafruit HAT for Raspberry Pi - https://core-electronics.com.au/tutorials/servo-hat-raspberry-pi.html
Controlling a Servo Motor with an Arduino - https://core-electronics.com.au/tutorials/servo-control-with-arduino.html
Control Your Raspberry Pi Remotely Using Your Phone (RaspController Guide) - https://core-electronics.com.au/tutorials/raspcontrol-raspberry-pi.html
Dual Monitors with Raspberry Pi (Excellent Beginner Guide to Connecting Everything Up) - https://core-electronics.com.au/tutorials/dual-monitors-raspberry-pi-4.html

Servos are an immensely useful way to turn electrical energy into a rotational or linear motion with high efficiency and with great precision. The ones in this guide are all Standard Rotary Actuator Servos that can rotate 180 degrees or 270 degrees. Precise control over the narrow range (degrees of movement) is achieved through position. Information on the desired position is sent through via a PWM (pulse-width modulation) signal. Each servo has unique specifications which you can find in the datasheet and often at the bottom of our product pages. The code wants the values in seconds and datasheets usually provide data in microseconds so you will need to divide those numbers by 100000. Bigger servos need more current than a GPIO Pin can send out so I demonstrate how to power it if that situation arises. Shown here are servos commonly seen by makers but there are exotic types of servos that can rotated 300 degrees and even have internal clutches built in. The code used here allows you to control the angle at which a servo will orientate too maximising your control over the system.

If you have any questions about this content or want to share a project you're working on head over to our maker forum, we are full time makers and here to help - http://coreelec.io/forum

Core Electronics is located in the heart of Newcastle, Australia. We're powered by makers, for makers. Drop by if you are looking for:

DFRobot Metal Geared 15Kg Standard Servo 270° (used here): https://core-electronics.com.au/catalog/product/view/sku/SER0038

Makeblock 9g Micro Servo Pack (used here): https://core-electronics.com.au/catalog/product/view/sku/MB95026

Raspberry Pi 4 Model B (4GB) Ultimate Kit Bundle (AVALIABLE!) - https://core-electronics.com.au/raspberry-pi-4-4gb-ultimate-kit.html

Raspberry Pi 4 Model B 2GB: https://core-electronics.com.au/catalog/product/view/sku/CE06424

Raspberry Pi 16 Channel Servo HAT: https://core-electronics.com.au/catalog/product/view/sku/ADA2327

2Kg 300° Clutch Servo: https://core-electronics.com.au/catalog/product/view/sku/SER0056

Primoroni Picade Pan-Tilt HAT: https://core-electronics.com.au/catalog/product/view/sku/CE04655

5V DC 4A Fixed 2.1mm Plugpack: https://core-electronics.com.au/catalog/product/view/sku/AM8911B

0:00 Intro and Schematic
0:10 Overview
1:20 Small Servo What You Will Need
1:47 Schematic and Build
2:23 Coding the Raspberry Pi
2:42 Its Working!
2:47 Explaining the Code
3:05 Pulse Width Modulation Explained
3:45 *Data Shown is for Large Servo*
3:50 End Explaining code
4:15 Large Servo What You Will Need
4:50 Schematic and Build 2
5:40 Coding the Raspberry Pi 2
5:58 Large Servo is Working!
6:10 Explaining the Code 2
6:47 How to use only one Power Supply
7:08 Outro

Category (YouTube): Education

Playback is via YouTube's official embedded player. Data from YouTube; Exumo is not affiliated with YouTube.