Robots With a Beat

by rohanmenon in Circuits > Arduino

1620 Views, 6 Favorites, 0 Comments

Robots With a Beat

WIN_20140125_193055.JPG
I watched a Ted Talk on robots with a sense of feeling. Guy Hoffman shows his newest product, a robot that would "feel the beat of the music" from a docked iPod.I decided that I would make my own. I made a rudimentary version of his robot with a simple little toy horse doll.

Get the Materials

52e46353ec8d83416b000123.jpg
52e463ebec8d838f2d000009.jpg
52e464bbec8d839f2b000007.jpg
52e51d7fec8d83fa3700001f.jpg
52e521c7ec8d83fa37000025.jpg
52e52273ec8d83cfa1000049.jpg
52e587ebc6ba5d82f7000039.jpg
52e5886dc6ba5d25dc000059.jpg
You will need the following materials to complete this project:
(If you have any questions on alternative materials ask in the comments below)
  • One flexible toy doll (with limbs what can move)
  • One Arduino (Uno, Mega or similar)
  • Lots of jumper wire
  • One rbg led (optional)
  • One or two servos preferably mini
  • Some string or metal picture frame hanging wire
  • One hot glue gun and sticks or double sided foam tape
  • One Xacto Knife
  • 9v Battery or other Arduino power source
  • One small box to hold the servos
  • 3.3 mm audio jack.(headphone jack)

Wiring and Placement

Untitled Sketch 3_bb.jpg
Untitled Sketch 3_schem.jpg
Start by following the schematic or breadboard layout on to a pcb or breadboard. Once you are done with wiring you will have to think about where you are going to put your arduino and the circuit. In my robot I had the motor box (discussed next step) on top of a bigger box with all the components and the arduino. I put my multicolored led in the nose of my doll.

The Servos

52e5266dec8d83acca00003b.jpg
52e58afac6ba5dc1ed000059.jpg
52e58d76c6ba5d32ed0000db.jpg
Now it is time to add the servos. With my doll I placed them so that one servo (with the servo horn sticking out of the box) could pull a string to make the head go up and down with the doll on top of the box. I put the other one inside the box with a metal wire connected to the horn to push and pull the leg to make it tap the beat of the song.

Upload the Code

52e59157c6ba5d32ed0000de.jpg
One the last things to do is to upload the code. Based on your number of servos that you have or other specifications to your project you will probably have to play with the code.
#define GREEN 3
#define BLUE 5
#define RED 6
#define delayTime 20

#include <Servo.h> <servo.h>

Servo myservo;
Servo myservo1;
int jackpin = 0;
int val;

void setup()
{
pinMode(GREEN, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(RED, OUTPUT);
digitalWrite(GREEN, HIGH);
digitalWrite(BLUE, HIGH);
digitalWrite(RED, HIGH);

myservo.attach(9);
myservo1.attach(6);
}


int redVal;
int blueVal;
int greenVal;


void loop()
{
int redVal = 255;
int blueVal = 0;
int greenVal = 0;
for( int i = 0 ; i < 255 ; i += 1 ){
greenVal += 1;
redVal -= 1;
analogWrite( GREEN, 255 - greenVal );
analogWrite( RED, 255 - redVal );
delay( delayTime );
}
redVal = 0;
blueVal = 0;
greenVal = 255;
for( int i = 0 ; i < 255 ; i += 1 ){
blueVal += 1;
greenVal -= 1;
analogWrite( BLUE, 255 - blueVal );
analogWrite( GREEN, 255 - greenVal );


delay( delayTime );
}

redVal = 0;
blueVal = 255;
greenVal = 0;
for( int i = 0 ; i < 255 ; i += 1 ){
redVal += 1;
blueVal -= 1;
analogWrite( RED, 255 - redVal );
analogWrite( BLUE, 255 - blueVal );


delay( delayTime );
}
if(analogRead(jackpin)>8){
val = analogRead(potpin)*20;
val = map(val, 1023, 0, 0, 179);
myservo.write(val*8-50 );
delay(70) ;
myservo1.write(val*6-70);
delay(500);
}
else if (val>300){
myservo.detach();
myservo1.detach();

}
}</servo.h>
Now you are done! Plug it in to your phone, computer or tablet with your favorite song playing and wach it dance!