Page 117 - TCS ICT Book 8
P. 117
The City School 2021-2022
We will use the Pi Shield on the top of the GPIO pins of Pi as a stack and connect the
Servo motor on the Pi shield. And this time we will also power the Pi via power adapter
or battery outlet available on the Pi Shield. Colour codes are marked on the Pi Shield
(B for brown, R for Red, and Y for Yellow). Make sure to connect the correct wire on the
header.
Equipment needed
Following componentes are required for this project:
• Servo Motor
• Pi Shield
• Raspberry Pi Programming Robots & Single-Board Computers
• Power Adapter / Battery
• Keyboard, Mouse & LCD
1.1. Interfacing code:
import RPi.GPIO as GPIO
import time as t
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.setup(13,GPIO.OUT)
p=GPIO.PWM(13,250)
p.start(24)
while True:
t.sleep(1)
p.ChangeDutyCycle(37)
t.sleep(1)
p.ChangeDutyCycle(75)
t.sleep(1)
p.ChangeDutyCycle(24)
Servo motors are controlled by PWM (Pulse Width Modulation). PWM works like On-
time and Off-time of a signal. On-time represents the active time of the signal required
to power the servo motor whereas the Off-time is for the inactive time of a signal.
117

