Servo Baby

I made a creepy baby. You can control his arms and head with potentiometers and turn his eyes red with a button.

one of the arms and one of the eyes stopped working when i tried to squeeze everything into the enclosure….

 

allowfullscreen></iframe>

here is my code:

#include <Servo.h>

 

// analog in
#define HEAD_IN 0
#define L_ARM_IN 1
#define R_ARM_IN 2
#define L_LEG_IN 3
#define R_LEG_IN 4

// digital out
#define HEAD_OUT 3
#define L_ARM_OUT 4
#define R_ARM_OUT 5
#define L_LEG_OUT 6
#define R_LEG_OUT 7

Servo head,
leftArm,
rightArm,
leftLeg,
rightLeg;

void setup()
{
#if DEBUG == 1
Serial.begin(9600);
#endif
head.attach(HEAD_OUT);
leftArm.attach(L_ARM_OUT);
rightArm.attach(R_ARM_OUT);
leftLeg.attach(L_LEG_OUT);
rightLeg.attach(R_LEG_OUT);
}

void move(int inPin, Servo servo, int lowerLimit, int upperLimit)
{
int pos = map(analogRead(inPin), 0, 1023, lowerLimit, upperLimit);
servo.write(pos);

#if DEBUG == 1
char pinName[10];
switch(inPin){
case HEAD_IN:
strcpy(pinName, “Head”);
break;
case L_ARM_IN:
strcpy(pinName, “L Arm”);
break;
case R_ARM_IN:
strcpy(pinName, “R Arm”);
break;
case L_LEG_IN:
strcpy(pinName, “L Leg”);
break;
case R_LEG_IN:
strcpy(pinName, “R Leg”);
break;
}
Serial.print(pinName); Serial.print(“: “);
Serial.println(pos, DEC);
delay(100);
#endif
}

void loop()
{
move(HEAD_IN, head, 10, 179);
move(L_ARM_IN, leftArm, 35, 160);
move(R_ARM_IN, rightArm, 35, 160);
move(L_LEG_IN, leftLeg, 0, 179);
move(R_LEG_IN, rightLeg, 0, 179);
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *