Wednesday 17 October 2012

Arduino + SSC 32 + Servo


Hello everyone,

In this post I want to show how to use the SSC32 controller with Arduino for moving few servos and compare it with a direct connexion of servos to Arduino without using a servo controller.

I will start with the later...

We need:
  • Arduino
  • Servos
  • Breadboard
  • Wires
  • Power cable for Arduino
I've made the connections layout below using fritzing

Arduino receives power and data from USB. Arduino is powerful enough to give power to 3 servos so we can connect red and black wire from 5v and ground in Arduino to breadboard. Servos will take power from the breadboard lines set by Arduino. We also need to connect yellow wire to a PWM input pin. I select pins 2, 3 and 4. If we want to connect more servos probably we will need to add an external battery to power them.

Code:
#include <Servo.h>
Servo servoMain1;                                // Define our 1st Servo
Servo servoMain2;                                // Define our 2nd Servo
Servo servoMain3;                                // Define our 3rd Servo
void setup()
{
   servoMain1.attach(2);                        // servo1 on digital pin 2
   servoMain2.attach(3);                        // servo2 on digital pin 3
   servoMain3.attach(4);                        // servo3 on digital pin 4
}
void loop()
{
   servoMain1.write(0);                          // Turn Servo1 to 0 degrees
   servoMain2.write(90);                        // Turn Servo2 to center position (90 degrees)
   servoMain3.write(180);                      // Turn Servo3 180 degrees
   delay(1000);                                        // Wait 1 second
   servoMain1.write(180);                      // Turn Servo1 to 180 degrees
   servoMain2.write(135);                      // Turn Servo2 135 degrees
   servoMain3.write(90);                        // Turn Servo3 to center position (90 degrees)
   delay(1000);                                       // Wait 1 second
}
Using SSC32
  • Arduino
  • Controller SSC32
  • Servos
  • Wires
  • External battery
  • Power cable for Arduino and SSC32
We need to connect the SSC32 controller to Arduino like below:

See also how to connect the 3 wires of each servo and where to connect an external power supply (5v) for the servos. The picture below shows the controller being powered by USB cable to the computer.


Also it is important to set the baud rate the same as in the code ("serial.begin" parameter)


Code
void setup() {
Serial.begin(115200);                              //Start serial communication at 115200 baud rate
}
void loop() {
 
  Serial.println("#0 P750 #4 P750 #11 P750 T500");         //Moves 3 servos at same time
  delay(1000);                                                                     //Wait 1 second
  Serial.println("#0 P2200 #4 P1500 #11 P2200 T500");
  delay(1000);
}

Using the SSC 32 controller the connexions are simpler and neater. Also is really powerful to be able to move many servos at same time using the multi-servo command (the one used in the code above). Notice in the video that the servo with yellow target starts and finish movement at the same time as the others even though rotates smaller angle, so movement is slower than the other 2.
 

1 comment: