Multi Servo Control Up To 16 with Arduino




In this tutorial we will learn how to control multiple servo with the Arduino. For this we will use "16 Channel Servo Expansion Board For the Arduino Uno R3".You can also control 2 DC motors and 1 stepper motor with this motor shield.

--------------------

Required Hardware:

Arduino Uno R3 - https://goo.gl/Rqc5w2
16 Channel Servo Shield - https://goo.gl/6tP0t2
SG90 Mini Servo - https://goo.gl/jQJZlG
Power Adapter - https://goo.gl/60Wwrw
Recommended Site - https://goo.gl/V9nYtx

--------------------

Hot Deals & Coupons

15% Professional Tools - https://goo.gl/Hi96pw (coupon: hot130)
16% Electronic Sale - https://goo.gl/wwTL2B
53% Tools&Electronics - https://goo.gl/9IQ1Fv

--------------------

Adafruit 16 Channel Servo Shield Library

--------------------

How to Install Library (Tutorial)

--------------------

Get More Info About Adafruit Library

--------------------

Get the Code :
#include <Wire.h>
#include <Adafruit_PWMServoDriver.h>

Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();

#define MIN_PULSE_WIDTH       650
#define MAX_PULSE_WIDTH       2350
#define DEFAULT_PULSE_WIDTH   1500
#define FREQUENCY             50

void setup() {
  pwm.begin();
  pwm.setPWMFreq(FREQUENCY);
}

void loop() {
  pwm.setPWM(0, 0, pulseWidth(0));
  delay(1000);
  pwm.setPWM(0, 0, pulseWidth(180));
  delay(1000);
}

int pulseWidth(int angle)
{
  int pulse_wide, analog_value;
  pulse_wide   = map(angle, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH);
  analog_value = int(float(pulse_wide) / 1000000 * FREQUENCY * 4096);
  return analog_value;
}