Raspberry Pi + servo

Greetings! We have figured out the concept PWM and tried to connect our servo to Arduino, so in theory we will not dwell.

Connecting to Raspberry Pi

From the servo cable goes from three wires:

Red – Power – connected to a contact 5V (pin 2) or directly to the power supply;

brown or black – ground GND (pin 6 Raspberry Pi);

yellow or white – signal; Connect to pin 7.

Specifications of our servo
Model: TowerPro SG90
Operating Voltage: 4.8 DC
Speed: 60 degrees on 0.1 s
Torque: 1.6 kg cm
Weight: 9 g
The range of pulse width: 0.5 ms – 2.5 ms


This servo can not rotate 360 degrees. It has a neutral position (Neutral) and limits of zero and 180 degrees. To install the servo in the neutral position, you must submit a high signal duration of 1.5 ms at 0 degrees – 0.5 ms to 180 degrees – 2.5 ms.

кут серво

Consider the following program:

import RPi.GPIO as GPIO
import time



p = GPIO.PWM(7,50)

        while True:

except KeyboardInterrupt:


In this program we set seventh pin for pulse-width modulation frequency of 50 Hertz: GPIO.PWM(7,50)

Now giving the servo pulses of different lengths, we can change its position
цикл серво
The work of this program:

It was very useful video

Добавить комментарий

Этот сайт использует Akismet для борьбы со спамом. Узнайте как обрабатываются ваши данные комментариев.

Закрыть меню