arduino Dancing Autobot
hello guys this is our project..and new thats called autobot with dancing like michael jackson....
its amazing...
we have made this cutting cardboard..but you can make this with using 3d printer..
now lets goooooooo.....
Step 1:-components
1:-arduino uno/nano
2:-servo motor
3:-9v battery or power bank
4:-jumper wires
5:-mini breadboard
Step 2:-servo Motor
servo motor have 3pins
you can identified by red ,black and yellow color
1st of all
red color wire is connect to +5v
black color wire is connect to gnd
and yellow color wire is connect to microcontroller means to arduino.
Step 3: Step 3:-fix This Robot
see this pic..
4servo motor are used in this project..
so servo motor fix is important in this project..
see this pic..and follow how to connect this 4 servo motors...
Step 4:-circuit Diagram
fix your motors..
then connect 4servo motors to arduino..
all red wire of servo motor is connect to +5v
black wire connect to gnd
and yellow wire is connect to arduino pin..
see this pic..
2servo motor is connect to 2pin of arduino
3servo motor is connect to 3pin of arduino
4servo motor is connect to 4pin of arduino
5servo motor is connect to 5pin of arduino..
thats all in easy connection...
Step 5:-uploading the Code
here is the pic of screenshot of code...
copy this code below and paste to arduino..1st compile then upload....
#include<servo.h>
#include<Oscillator.h>
#include<EEPROM.h>
#define N_SERVOS 4 //-- First step: Configure the pins where the servos are attached /*
--------------- | O O | |---------------| YR 3==> |
| <== YL 2 --------------- || || || || RR 5==> ----- ------ <== RL 4 |----- ------| */ #define EEPROM_TRIM false // Activate to take callibration data from internal memory #define TRIM_RR 7 #define TRIM_RL 4 #define TRIM_YR 4 #define TRIM_YL -7 //OTTO.setTrims(-7,-4,-4,7);
#define PIN_RR 5 #define PIN_RL 4 #define PIN_YR 3 #define PIN_YL 2
#define INTERVALTIME 10.0
Oscillator servo[N_SERVOS];
void goingUp(int tempo); void drunk (int tempo); void noGravity(int tempo); void kickLeft(int tempo); void kickRight(int tempo); void run(int steps, int T=500); void walk(int steps, int T=1000); void backyard(int steps, int T=3000); void backyardSlow(int steps, int T=5000); void turnLeft(int steps, int T=3000); void turnRight(int steps, int T=3000); void moonWalkLeft(int steps, int T=1000); void moonWalkRight(int steps, int T=1000); void crusaito(int steps, int T=1000); void swing(int steps, int T=1000); void upDown(int steps, int T=1000); void flapping(int steps, int T=1000);
void setup() { Serial.begin(19200); servo[0].attach(PIN_RR); servo[1].attach(PIN_RL); servo[2].attach(PIN_YR); servo[3].attach(PIN_YL); //EEPROM.write(0,TRIM_RR); //EEPROM.write(1,TRIM_RL); //EEPROM.write(2,TRIM_YR); //EEPROM.write(3,TRIM_YL); int trim; if(EEPROM_TRIM){ for(int x=0;x<4;x++){ trim=EEPROM.read(x); if(trim>128)trim=trim-256; Serial.print("TRIM "); Serial.print(x); Serial.print(" en "); Serial.println(trim); servo[x].SetTrim(trim); } } else{ servo[0].SetTrim(TRIM_RR); servo[1].SetTrim(TRIM_RL); servo[2].SetTrim(TRIM_YR); servo[3].SetTrim(TRIM_YL); } for(int i=0;i<4;i++) servo[i].SetPosition(90); }
// TEMPO: 121 BPM int t=495; double pause=0;
void loop() { // if(Serial.available()){ // char init = Serial.read(); // if (init=='X'){ // delay(4000); //3000 - 4500 dance();
//for(int i=0;i<4;i++) servo[i].SetPosition(90);
for(int i=0;i<4;i++) servo[i].SetPosition(90); // } // } }
void dance(){ primera_parte(); segunda_parte(); moonWalkLeft(4,t*2); moonWalkRight(4,t*2); moonWalkLeft(4,t*2); moonWalkRight(4,t*2); primera_parte(); crusaito(1,t*8); crusaito(1,t*7);
for (int i=0; i<16; i++){ flapping(1,t/4); delay(3*t/4); } moonWalkRight(4,t*2); moonWalkLeft(4,t*2); moonWalkRight(4,t*2); moonWalkLeft(4,t*2);
drunk(t*4); drunk(t*4); drunk(t*4); drunk(t*4); kickLeft(t); kickRight(t); drunk(t*8); drunk(t*4); drunk(t/2); delay(t*4);
drunk(t/2);
delay(t*4); walk(2,t*2); backyard(2,t*2); goingUp(t*2); goingUp(t*1); noGravity(t*2); crusaito(1,t*2); crusaito(1,t*8); crusaito(1,t*2); crusaito(1,t*8); crusaito(1,t*2); crusaito(1,t*3);
delay(t); primera_parte(); for (int i=0; i<32; i++){ flapping(1,t/2); delay(t/2); } for(int i=0;i<4;i++) servo[i].SetPosition(90); }
//////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////FUNCIONES DE CONTROL////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////
void oscillate(int A[N_SERVOS], int O[N_SERVOS], int T, double phase_diff[N_SERVOS]){ for (int i=0; i<4; i++) { servo[i].SetO(O[i]); servo[i].SetA(A[i]); servo[i].SetT(T); servo[i].SetPh(phase_diff[i]); } double ref=millis(); for (double x=ref; x
unsigned long final_time; unsigned long interval_time; int oneTime; int iteration; float increment[N_SERVOS]; int oldPosition[]={90,90,90,90};
void moveNServos(int time, int newPosition[]){ for(int i=0;i
for(int i=0;i
////////////////////////////////////////////////////////////////////////////// ////////////////////////////////PASOS DE BAILE//////////////////////////////// //////////////////////////////////////////////////////////////////////////////
void goingUp(int tempo){ pause=millis(); for(int i=0;i<4;i++) servo[i].SetPosition(90); delay(tempo); servo[0].SetPosition(80); servo[1].SetPosition(100); delay(tempo); servo[0].SetPosition(70); servo[1].SetPosition(110); delay(tempo); servo[0].SetPosition(60); servo[1].SetPosition(120); delay(tempo); servo[0].SetPosition(50); servo[1].SetPosition(130); delay(tempo); servo[0].SetPosition(40); servo[1].SetPosition(140); delay(tempo); servo[0].SetPosition(30); servo[1].SetPosition(150); delay(tempo); servo[0].SetPosition(20); servo[1].SetPosition(160); delay(tempo); while(millis()
}
void primera_parte(){ int move1[4] = {60,120,90,90}; int move2[4] = {90,90,90,90}; int move3[4] = {40,140,90,90}; for(int x=0; x<3; x++){ for(int i=0; i<3; i++){ lateral_fuerte(1,t/2); lateral_fuerte(0,t/4); lateral_fuerte(1,t/4); delay(t); } pause=millis(); for(int i=0;i<4;i++) servo[i].SetPosition(90); moveNServos(t*0.4,move1); moveNServos(t*0.4,move2); while(millis()<(pause+t*2)); } for(int i=0; i<2; i++){ lateral_fuerte(1,t/2); lateral_fuerte(0,t/4); lateral_fuerte(1,t/4); delay(t); } pause=millis(); for(int i=0;i<4;i++) servo[i].SetPosition(90); crusaito(1,t*1.4); moveNServos(t*1,move3); for(int i=0;i<4;i++) servo[i].SetPosition(90); while(millis()<(pause+t*4)); }
void segunda_parte(){ int move1[4] = {90,90,80,100}; int move2[4] = {90,90,100,80}; int move3[4] = {90,90,80,100}; int move4[4] = {90,90,100,80}; int move5[4] = {40,140,80,100}; int move6[4] = {40,140,100,80}; int move7[4] = {90,90,80,100}; int move8[4] = {90,90,100,80}; int move9[4] = {40,140,80,100}; int move10[4] = {40,140,100,80}; int move11[4] = {90,90,80,100}; int move12[4] = {90,90,100,80}; for(int x=0; x<7; x++){ for(int i=0; i<3; i++){ pause=millis(); moveNServos(t*0.15,move1); moveNServos(t*0.15,move2); moveNServos(t*0.15,move3); moveNServos(t*0.15,move4); while(millis()<(pause+t)); } pause=millis(); moveNServos(t*0.15,move5); moveNServos(t*0.15,move6); moveNServos(t*0.15,move7); moveNServos(t*0.15,move8); while(millis()<(pause+t)); } for(int i=0; i<3; i++){ pause=millis(); moveNServos(t*0.15,move9); moveNServos(t*0.15,move10); moveNServos(t*0.15,move11); moveNServos(t*0.15,move12); while(millis()<(pause+t)); } }
void lateral_fuerte(boolean side, int tempo){ for(int i=0;i<4;i++) servo[i].SetPosition(90); if (side) servo[0].SetPosition(40); else servo[1].SetPosition(140); delay(tempo/2); servo[0].SetPosition(90); servo[1].SetPosition(90); delay(tempo/2);
}
void drunk (int tempo){ pause=millis(); int move1[] = {60,70,90,90}; int move2[] = {110,120,90,90}; int move3[] = {60,70,90,90}; int move4[] = {110,120,90,90}; moveNServos(tempo*0.235,move1); moveNServos(tempo*0.235,move2); moveNServos(tempo*0.235,move3); moveNServos(tempo*0.235,move4); while(millis()<(pause+tempo));
}
void noGravity(int tempo){ int move1[4] = {120,140,90,90}; int move2[4] = {140,140,90,90}; int move3[4] = {120,140,90,90}; int move4[4] = {90,90,90,90}; for(int i=0;i<4;i++) servo[i].SetPosition(90); for(int i=0;i
}
void kickLeft(int tempo){ for(int i=0;i<4;i++) servo[i].SetPosition(90); delay(tempo); servo[0].SetPosition(50); //pie derecho servo[1].SetPosition(70); //pie izquiero delay(tempo); servo[0].SetPosition(80); //pie derecho servo[1].SetPosition(70); //pie izquiero delay(tempo/4); servo[0].SetPosition(30); //pie derecho servo[1].SetPosition(70); //pie izquiero delay(tempo/4); servo[0].SetPosition(80); //pie derecho servo[1].SetPosition(70); //pie izquiero delay(tempo/4); servo[0].SetPosition(30); //pie derecho servo[1].SetPosition(70); //pie izquiero delay(tempo/4); servo[0].SetPosition(80); //pie derecho servo[1].SetPosition(70); //pie izquiero delay(tempo); }
void kickRight(int tempo){ for(int i=0;i<4;i++) servo[i].SetPosition(90); delay(tempo); servo[0].SetPosition(110); //pie derecho servo[1].SetPosition(130); //pie izquiero delay(tempo); servo[0].SetPosition(110); //pie derecho servo[1].SetPosition(100); //pie izquiero delay(tempo/4); servo[0].SetPosition(110); //pie derecho servo[1].SetPosition(150); //pie izquiero delay(tempo/4); servo[0].SetPosition(110); //pie derecho servo[1].SetPosition(80); //pie izquiero delay(tempo/4); servo[0].SetPosition(110); //pie derecho servo[1].SetPosition(150); //pie izquiero delay(tempo/4); servo[0].SetPosition(110); //pie derecho servo[1].SetPosition(100); //pie izquiero delay(tempo); }
void walk(int steps, int T){ int A[4]= {15, 15, 30, 30}; int O[4] = {0, 0, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; for(int i=0;i
void run(int steps, int T){ int A[4]= {10, 10, 10, 10}; int O[4] = {0, 0, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; for(int i=0;i
void backyard(int steps, int T){ int A[4]= {15, 15, 30, 30}; int O[4] = {0, 0, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)}; for(int i=0;i
void backyardSlow(int steps, int T){ int A[4]= {15, 15, 30, 30}; int O[4] = {0, 0, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(-90), DEG2RAD(-90)}; for(int i=0;i
void turnLeft(int steps, int T){ int A[4]= {20, 20, 10, 30}; int O[4] = {0, 0, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; for(int i=0;i
void turnRight(int steps, int T){ int A[4]= {20, 20, 30, 10}; int O[4] = {0, 0, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; for(int i=0;i
void moonWalkRight(int steps, int T){ int A[4]= {25, 25, 0, 0}; int O[4] = {-15 ,15, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)}; for(int i=0;i
void moonWalkLeft(int steps, int T){ int A[4]= {25, 25, 0, 0}; int O[4] = {-15, 15, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 - 120), DEG2RAD(90), DEG2RAD(90)}; for(int i=0;i
void crusaito(int steps, int T){ int A[4]= {25, 25, 30, 30}; int O[4] = {- 15, 15, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180 + 120), DEG2RAD(90), DEG2RAD(90)}; for(int i=0;i
void swing(int steps, int T){ int A[4]= {25, 25, 0, 0}; int O[4] = {-15, 15, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(0), DEG2RAD(90), DEG2RAD(90)}; for(int i=0;i
void upDown(int steps, int T){ int A[4]= {25, 25, 0, 0}; int O[4] = {-15, 15, 0, 0}; double phase_diff[4] = {DEG2RAD(180), DEG2RAD(0), DEG2RAD(270), DEG2RAD(270)}; for(int i=0;i
void flapping(int steps, int T){ int A[4]= {15, 15, 8, 8}; int O[4] = {-A[0], A[1], 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(-90)}; for(int i=0;i
void test(int steps, int T){ int A[4]= {15, 15, 8, 8}; int O[4] = {-A[0] + 10, A[1] - 10, 0, 0}; double phase_diff[4] = {DEG2RAD(0), DEG2RAD(180), DEG2RAD(90), DEG2RAD(-90)}; for(int i=0;i
Step 6:-also New Features Code
here this below code ..
you can try to upload this..
for this code,robot can move sometimes backword and forward walk with dance..
#include<servo.h>
#include<Oscillator.h>
#include<EEPROM.h>
//-- Zowi Library #include
//-- First step: Configure the pins where the servos are attached /* --------------- | | | O O | | | YR ==> | | <== YL --------------- || || || || || || RR ==> ----- ------ <== RL ----- ------ */
#define PIN_RR 5 #define PIN_RL 4 #define PIN_YR 3 #define PIN_YL 2
//-- Second step: Determine the Servo Trim values #define TRIM_RR -7 #define TRIM_RL -2 #define TRIM_YR 0 #define TRIM_YL -14
//-- This is Zowi!! Zowi z;
void setup() { //---------- Zowi Initialization //-- Set the servo pins z.init(PIN_YL, PIN_YR, PIN_RL, PIN_RR); //-- Set the servo trims z.setTrims(TRIM_YL, TRIM_YR, TRIM_RL, TRIM_RR); }
void loop() { //-- Zowi at rest position z.home(); delay(500); //-- Make zowi walk forward and backward! //-- Parameters: Number of steps, Period in ms, direction: FORWARD z.walk(4, 2000, FORWARD); //-- Move forward. Slow z.walk(4, 1000, FORWARD); //-- Move forward. Faster z.home(); delay(500); //-- Make zowi walk backward z.walk(4, 1000, BACKWARD); //-- Move backward. Fast z.walk(4, 2000, BACKWARD); //-- Move backward slot //-- Make zowi turn left and right //z.turn(3, 2000, RIGHT); //z.turn(3, 2000, LEFT); //-- Make zowi move up and down //z.updown(6, 500, SMALL); //z.updown(6, 500, MEDIUM); //z.updown(6, 500, BIG); //z.updown(2, 4000, BIG); //-- Zowi performing the moonwalker!! //z.moonwalker(3, 2000, 30, LEFT); //z.moonwalker(3, 2000, 30, RIGHT); //-- Zowi moving side to side //z.swing(6, 600, 10); //z.swing(4, 2000, 40); //-- Zowi doing the "crusaito": A mixture between walk and moonwalker //z.crusaito(6, 2000, 40, LEFT); //z.crusaito(6, 2000, 40, RIGHT); //-- Zowi moving backward and forward in a different way //z.flapping(10, 600, 10, FORWARD); //z.flapping(10, 600, 10, BACKWARD); z.home(); //-- Do not move anymore while(1);
Step 7:-result
so guys follow below this link on you tube of our channel S_R TRONICS
and this link help you how to build this project easily..
https://www.youtube.com/watch?v=9Maj5eTMXv0