Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Michael Guerero
Published © GPL3+

Quadruped Pumpkin

Don't just have a Jack-o-Lantern sit motionless on the porch! Give it some life and limbs!

IntermediateShowcase (no instructions)4,849
Quadruped Pumpkin

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Adafruit 16-Channel 12-bit PWM/Servo Driver - I2C interface - PCA9685
×1
MG 996R High Torque Servo Motor
×8
9" Orange Craft Pumpkin
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Bearings
×8

Hand tools and fabrication machines

6V Power Supply
3D Printer (generic)
3D Printer (generic)
X-Acto Knife
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Code

Quadruped Pumpkin Code

Arduino
The values in lines 16-19 will vary depending on the exact setup to determine what angle is closed and open
#include <Adafruit_PWMServoDriver.h>
#include <Wire.h>

Adafruit_PWMServoDriver servos = Adafruit_PWMServoDriver();
const int potPin = 0;

void setup() {
  Serial.begin(9600);
  servos.begin();
  servos.setPWMFreq(60);
  delay(10);
}

void loop() {
  int potVal = analogRead(potPin);
  moveLeg(potVal, 0, 4, 96, 54, 180, 120);   // Leg 1
  moveLeg(potVal, 1, 5, 83, 34, 180, 120);   // Leg 2
  moveLeg(potVal, 2, 6, 83, 37, 180, 120);   // Leg 3
  moveLeg(potVal, 3, 7, 95, 27, 180, 115);   // Leg 4
  Serial.println(potVal);
  delay(20);
}

//----------------------------------------------------------------------------------------//
int angle2pulse(int angle){
  int pulseLength = map(angle, 0, 180, 150, 600);
  pulseLength = constrain(pulseLength, 150, 600);
  return pulseLength;
}

void moveLeg(int potVal, uint8_t hip, uint8_t knee, int closedHipAngle, int closedKneeAngle,int expandedHipAngle,int expandedKneeAngle){
  int angle_H = map(potVal, 0, 1024, closedHipAngle, expandedHipAngle);
  int angle_K = map(potVal, 0, 1024, closedKneeAngle, expandedKneeAngle);
  servos.setPWM(hip, 0, angle2pulse(angle_H));
  servos.setPWM(knee, 0, angle2pulse(angle_K));
}

Credits

Michael Guerero

Michael Guerero

3 projects • 44 followers
Earned my BS in Mechanical Engineering from Cal Poly Pomona in 2018. Currently working for the California Air Resources Board.

Comments