Hackster is hosting Hackster Holidays, Ep. 4: Livestream & Giveaway Drawing. Start streaming on Wednesday!Stream Hackster Holidays, Ep. 4 on Wednesday!
Jithin Sanal
Published © GPL3+

Build A Tripod Using Arduino and Servo Motors

In this post, I will show you how to build a three legged robot (a tripod) using Arduino and servo motors.

IntermediateFull instructions provided24 hours6,957
Build A Tripod Using Arduino and Servo Motors

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Servos (Tower Pro MG996R)
×9
Lithium Polymer
×1
PCA9685 16 Channel 12 Bit Servo motor driver
×1

Story

Read more

Code

Sample Sketch

Arduino
#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  
uint8_t servonum = 0;  
void setup()
  {
   Serial.begin(9600);
   Serial.println("16 channel Servo test!");
   pwm.begin();
   pwm.setPWMFreq(FREQUENCY);
   pwm.setPWM(0, 0, pulseWidth(100));
   delay(500);
   pwm.setPWM(4, 0, pulseWidth(60));
   delay(500);
   pwm.setPWM(12, 0, pulseWidth(60));
   delay(500);
   pwm.setPWM(1, 0, pulseWidth(10));
   delay(500);
   pwm.setPWM(5, 0, pulseWidth(170));
   delay(500);
   pwm.setPWM(13, 0, pulseWidth(170));
   delay(500);
   pwm.setPWM(2, 0, pulseWidth(120));
   delay(500);
   pwm.setPWM(6,0 , pulseWidth(85));
   delay(500);
   pwm.setPWM(14, 0, pulseWidth(110));
   delay(500);
  } 
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);
   Serial.println(analog_value);
   return analog_value;
 }  
void loop()
 {
   pwm.setPWM(0, 0, pulseWidth(150));
   delay(1000);
   pwm.setPWM(4, 0, pulseWidth(10));
   delay(1000);
   pwm.setPWM(13, 0, pulseWidth(180));
   delay(500);
   pwm.setPWM(14, 0, pulseWidth(180));
   delay(500);
   pwm.setPWM(1, 0, pulseWidth(0));
   delay(500);
   pwm.setPWM(5, 0, pulseWidth(180));
   delay(500);
   pwm.setPWM(2, 0, pulseWidth(120));
   delay(50);
   pwm.setPWM(6,0 , pulseWidth(85));
   delay(50);
   pwm.setPWM(2, 0, pulseWidth(180));
   delay(50);
   pwm.setPWM(6,0 , pulseWidth(45));
   delay(50);
   pwm.setPWM(2, 0, pulseWidth(120));
   delay(50);
   pwm.setPWM(6,0 , pulseWidth(85));
   delay(50);
   pwm.setPWM(2, 0, pulseWidth(180));
   delay(50);
   pwm.setPWM(6,0 , pulseWidth(45));
   delay(50);
   pwm.setPWM(2, 0, pulseWidth(120));
   delay(50);
   pwm.setPWM(6,0 , pulseWidth(85));
   delay(50);
   pwm.setPWM(2, 0, pulseWidth(180));
   delay(50);
   pwm.setPWM(6,0 , pulseWidth(45));
   delay(50);
   pwm.setPWM(2, 0, pulseWidth(120));
   delay(50);
   pwm.setPWM(6,0 , pulseWidth(85));
   delay(50);
   pwm.setPWM(2, 0, pulseWidth(180));
   delay(50);
   pwm.setPWM(6,0 , pulseWidth(45));
   delay(50);
   pwm.setPWM(2, 0, pulseWidth(120));
   delay(50);
   pwm.setPWM(6,0 , pulseWidth(85));
   delay(50);
   pwm.setPWM(2, 0, pulseWidth(180));
   delay(50);
   pwm.setPWM(6,0 , pulseWidth(45));
   delay(50);
   pwm.setPWM(14, 0, pulseWidth(110));
   delay(1000);
   pwm.setPWM(0, 0, pulseWidth(50));
   delay(1000);
   pwm.setPWM(4, 0, pulseWidth(120));
   delay(1000);
   pwm.setPWM(1, 0, pulseWidth(20));
   delay(500);
   pwm.setPWM(5, 0, pulseWidth(160));
   delay(500);
   pwm.setPWM(0, 0, pulseWidth(100));
   delay(500);
   pwm.setPWM(4,0, pulseWidth(60));
   delay(500);
 }  

Credits

Jithin Sanal

Jithin Sanal

83 projects • 316 followers
I am Interested in Arduino, Raspberry Pi, Ethical Hacking, Bash Scripting and Python programming.
Thanks to Green Terminal.

Comments