How can you drive servo motors with a Seeeduino Nano (Arduino compatible) ?
To drive several servo motors with any Arduino you can use the popular PCA9685 16 Channel PWM Servo Motor Driver I2C Module. By using a Seeeduino Nano you can do it more easily using it’s built in I2C Grove connector.
This project can also work with a regular Arduino Nano. I will cover that as well.
The first thing that you need to do is gather the parts.
Step 1. Parts list
Here is a list of the parts that you will need for this project:
You can either use a Seeeduino Nano or an Arduino Nano.
- Seeeduino Nano (Seeed Studio)
The Seeeduino doesn’t come with a cable. It requires a USB-C connector.
Select one based on whether or not your laptop has a USB-C or USB-A connector.
- AmazonBasics USB Type-C to USB Type-C 2.0 Charger Cable - 6 Feet (1.8 Meters) - Black (Amazon)
- AmazonBasics USB Type-C to USB-A 2.0 Male Charger Cable - 6 Feet (1.8 Meters) - Black (Renewed) (Amazon)
Note that this package comes with a cable for each board:
- LAFVIN Nano V3.0, Nano Board ATmega328P 5V 16M Micro-Controller Board Compatible with Arduino IDE (Nano x 3 with USB Cable) (Amazon)
- Grove Shield for Arduino Nano - required if you are using a standard Arduino Nano (Seeed Studio)
- Onyehn 16 Channel PWM Servo Motor Driver PCA9685 IIC Module 12-Bit for Arduino Robot or Raspberry pi (Pack of 3pcs) (Amazon)
- 16 Channel 12-bit PWM/Servo Driver-I2C interface-PCA9685 for Arduino or Raspberry Pi shield module servo shield (AliExpress)
- Miuzei 10 pcs SG90 9G Servo Motor Kit for RC Robot Arm Helicopter Airplane Remote Control (Amazon)
- Classic servos 9g SG90 MG90S For RC Planes Fixed wing Aircraft model telecontrol aircraft Parts Toy motors (AliExpress)
- 5/10pcs 9G Micro Mini Servos Horns better than Servo SG90 for RC 250 450 Helicoper Airplane Car ship Boat Robot All Categories (AliExpress)
Grove Conversion Cables
In case the Amazon link is out of stock, I’ve also included links to AliExpress and Seeed Studio.
- 5PCS/lot Grove - 4 pin Female Jumper to Grove 4 pin Conversion Cable free shipping (AliExpress)
- Grove - 4 pin Female Jumper to Grove 4 pin Conversion Cable (5 PCs per Pack) (Seeed Studio)
- ZIYUN Grove - 4 Pin Female Jumper to Grove 4 Pin Conversion Cable (5 Pcs Per Pack) (Amazon)
External Power Supply
You will also need an external power supply. You can power the servo board directly from the Seeeduino. But for the motors you should use an external power supply.
You have at least these three options:
- Option 1: Battery pack producing 4.8 to 5v
- Option 2: DC adapter that produces 4.8 to 5v (check with a multimeter!)
- Option 3: Variable power supply that can produce between 4.8 to 5v
I use this power supply: Dr.Meter PS-305DM 30V/5A Single-Output DC Power Supply 110V/220V Switchable, Alligator clip included, US 3-prong Cable (Amazon)
Step 2. Setup the Nano
This project works with either a Seeeduino Nano or an Arduino Nano
If you have never used the Seeeduino Nano with the the Arduino IDE before, see my setup guide:
- Seeeduino Nano Grove Setup (desertbot.io)
If you are using a Seeeduino Nano, skip to the next section.
These instructions are for regular Arduino Nano hooked up to a Mac. Adapt for Windows:
In the Arduino IDE, select the following:
- Tools > Port > /dev/cu.usbserial-1410
- Tools > Board > Arduino Nano
Step 3. Unplug everything
In the next few steps you will be wiring things up. To make sure you don’t accidentally short anything out, unplug all components from power supplies, etc.
Step 4. Wire the Grove Cable to the PCA9685
The Seeeduino Nano can communicate with the PCA9685 over I2C. It has a built in Grove (Molex-like) connector on top wired for I2C communication. The PCA9685 just has a series of header pins on the side. So you need to use a Grove 4 Pin Conversion Cable to create a connection.
Connect the following from the Grove conversion cable to the PCA9685:
- Black Wire - GND
- Yellow Wire - SCL
- White Wire - SDA
- Red Wired - VCC
Plug the other end of the conversion cable into the I2C port on top of the Seeeduino Nano.
Plug the other end of the conversion cable into the I2C port on the Grove Shield (you can use that port instead for a Seeeduino Nano too).
Step 5. Plug in the servos
If you are using standard SG90 servos and the board I recommended, the color codes of the servo wires should match the color of the pin connectors on the board.
- Plug the servos in, matching the colors of the connectors to the colors of the wires
- Put the first servo in the plug labeled 0, then 1, etc.
Step 6. Wire 5V DC power cables to the PCA9685
On the board that I recommended, there is a green power block.
You will need a small or eyeglass screwdriver to turn the screws.
- Put a red wire in the green connector labeled Power / V+
- Put a black wire in the green connector labeled GND
- If you are using a power supply turn it off
- If you are using a battery pack with no switch, remove the batteries
- Wire the red (+) and black (-/Ground) wires to your power supply
Step 7. Connect the Nano to your PC or Mac
You need a connection with your computer to push code to either Nano.
- Plug the cable recommended in the parts list into the Seeeduino Nano and your Mac or PC
- Plug the cable that came with the board I recommended in the Arduino Nano and your Mac or PC.
Step 8. Turn on the power supply
- Don’t be alarmed if the servos jump
- Make sure the servo “horns” are clear of hitting anything, especially wires
- Turn on your power supply or put the batteries in their holder
Step 9. Setup the IDE
Install the library and examples
- Launch the Arduino IDE
- Select Tools > Manage Libraries …
- Search the libraries for “Adafruit pwm”
- Install the Adafruit PWM Servo Driver Library
Run the Servo example
- Select File > Examples > Adafruit PWM Servo Driver Library > servo
- Upload the example to the Seeeduino Nano
The motors should go through a sequence proving that it works!
Cleaning up the example
You can clean up the example by changing the count in this line:
if (servonum > 7) servonum = 0; // Testing the first 8 servo channels
If you have only two servos, wired to the first two ports (0 and 1) on the PCA9685, change the 7 above to 1. That will cause the code to loop through only your available servos faster.
The rule is that if you have X number of servos, change the 7 above to whatever X - 1 equals.
In this article I showed you how to drive a series of servo motors with an Arduino compatible board and an actual board. The example uses the popular PCA9685 servo driver board. Because the servo board communicates using I2C, it works with many single board computers. This list includes Arduino, Seeeduino, ESP32, Raspberry Pi and Jetson Nano.
To simplify the wiring, I showed you how to put together a project using an Arduino Nano clone that has a built in I2C Grove connector. I also showed you how to use a Grove Shield to work with a regular Arduino Nano.
With one board you can drive up to 16 servos. You could use it to drive your next robot or robotic component. For example a laser cut robot arm or a hexapod (spider like robot). The only limit is your imagination.
- Seeeduino Nano Grove Setup (Arduino Compatible)
- How to Control a Servo Array with NodeJS
- How to Control an Arduino Uno with NodeJS
- Arduino Resource Guide
About the Author
Mitch Allen works for a robotics company in New England.