How to use the 16-channel PWM servo motor driver with Raspberry Pi board

How to use the 16-channel PWM servo motor driver with Raspberry Pi board

Hello and welcome back. In this tutorial, we will learn how to use the 16-channel PWM servo motor driver with a Raspberry Pi board. For that, I have used the Raspberry Pi 2 Model B board. But you can use it on any other Raspberry Pi board. With this setup, you can control up to 16 servo motors using just two pins(SDA and SCL). These pins talk to each other using something called I2C communication. If you want to control even more servo motors, you can connect more driver boards. This knowledge is super handy for projects involving moving parts, like robot arms, spider robots, robot dogs, etc. In this tutorial, I’ll show you how to use three SG90 servo motors and one MG995 servo motor.

PCA9685 16 channel PWM servo motor driver

How to use the 16-channel PWM servo motor driver with Raspberry Pi board

This board is built around the PCA9685 chip and allows us to connect up to 16 servo motors. We can control it using the I2C communication pins on the Raspberry Pi. If you need to control more than 16 servos, you can keep connecting additional driver boards in a chain. You can connect up to 62 driver boards to a single I2C bus this way. It’s important to provide an external 5VDC voltage to power the driver. Remember, never power this driver directly from the Raspberry Pi board, as it could damage your Raspberry Pi.

PIN structure of this PWM driver board

How to use the 16-channel PWM servo motor driver with Raspberry Pi board
  • If you want to do it with Arduino, please use this link — Click on me

OK, let’s learn how to connect this driver to the Raspberry Pi board. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect the servo driver board to the Raspberry Pi board. For that, use the circuit diagram below.

How to use the 16-channel PWM servo motor driver with Raspberry Pi board

Step 3

Thirdly, connect the servo motors to the driver. I have used four motors.

Step 4

Next, insert the SD card into the Raspberry Pi board. If you want to install Raspbian OS, please visit this tutorial. Then, connect the monitor, keyboard, mouse, and network cable to the Raspberry Pi board.

Step 5

Now, connect the 5VDC power cable and turn On your Raspberry Pi computer. Then, install the servo-kit library file. For that, follow the instructions below.

  • First, open your terminal and run the code below. (In this case, you need to enable internet)
  • sudo pip3 install adafruit-circuitpython-servokit
  • When the installation is successful, close the terminal.

Step 6

Next, copy and paste the following script on the Thonny IDE. After, connect the external 5VDC power supply to the servo motor driver. Finally, run this script.

from adafruit_servokit import ServoKit
from time import sleep
kit = ServoKit(channels=16)


def servo1():
    for a in range(0,180):
        kit.servo[0].angle = a
        sleep(0.008)
        
    for a in range(179,1,-1):
        kit.servo[0].angle = a
        sleep(0.008)
        
def servo2():
    for a in range(0,180):
        kit.servo[1].angle = a
        sleep(0.008)
        
    for a in range(179,1,-1):
        kit.servo[1].angle = a
        sleep(0.008)
        
def servo3():
    for a in range(0,180):
        kit.servo[2].angle = a
        sleep(0.008)
        
    for a in range(179,1,-1):
        kit.servo[2].angle = a
        sleep(0.008)
        
def servo4():
    for a in range(0,180):
        kit.servo[3].angle = a
        sleep(0.008)
        
    for a in range(179,1,-1):
        kit.servo[3].angle = a
        sleep(0.008)
        
        
while True:
    servo1()
    servo2()
    servo3()
    servo4()


Now, you can see the servo motor working. Also, change the servo motor values and gain good knowledge about this tutorial. The full video guide is below. So, we hope to see you in the next project. Have a good day.

How to use the 16-channel PWM servo motor driver with Raspberry Pi board

How to use the 16-channel PWM servo motor driver with Raspberry Pi board

Similar Posts

Leave a Reply

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