Project tutorial
Arduino Biped (Baby Dino)

Arduino Biped (Baby Dino) © GPL3+

A basic robot using Arduino.

  • 1,246 views
  • 7 comments
  • 6 respects

Components and supplies

About this project

Baby Dino is a two-legged robot based on Arduino. It basically uses five servo motors, two for each leg and one for the head. It also uses an ultrasonic sensor to detect obstacles and avoid them. Now, let's see how to make it!

Step 1: Introduction

  • Baby Dino is a DIY robot using Arduino.
  • It is made out of cardboard.
  • It will find obstacles, then move left or right.

Step 2: Components Required

  • 1 X Arduino Uno, Nano or Mega
  • 5 X 9g servo
  • 1 X HC-SR04 ultrasonic sensor
  • 1 X LiPo battery (2s or 9v battery)

Step 3: Fixing Servo

  • Download the program
  • Upload to Arduino
  • Connect the servo according to the diagram below
  • Fix the servo horn
  • Make sure everything is at 90 degrees

Step 4: Design

  • Download the design
  • Print it onto A4
  • Paste it on cardboard
  • Cut it out

Step 5: Final Step

  • Attach the servos to cardboard
  • Upload the program to Arduino
  • Connect the servos and ultrasonic sensor
  • Manage the cable as tail
  • Connect the battery

That's it!

Code

fix.inoArduino
#include <Servo.h>

Servo s1; 
Servo s2; 
Servo s3; 
Servo s4; 
Servo s5; 

void setup() {
  s1.attach(8);
  s2.attach(9);
  s3.attach(10);
  s4.attach(11);
  s5.attach(12);
}

void loop() {
  
  s1.write(90); 
   s2.write(90); 
    s3.write(90); 
     s4.write(90); 
      s5.write(90);                 
  
}
bipedArduino
edit the servo and ultrasonic pins according to your wish
#include <Servo.h> 
#include <NewPing.h>

// edit the pin according to your connection
#define IRsensorPin  13// if you are using ir sensor insted of ultrasonic sensor
#define TRIGGER_PIN  12  // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN     11  // Arduino pin tied to echo pin on the ultrasonic sensor.
#define LEFTLEG       7
#define RIGHTLEG     10
#define LEFTFOOT      8
#define RIGHTFOOT     9
#define	HEAD          6

#define MAX_DISTANCE 200 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.
Servo Lleg;  			// create servo object to control a servo 
Servo Rleg;
Servo Lfoot;
Servo Rfoot;
Servo Head;

int Hcenter = 70;      	// variable to store the center servo position 

int RLcenter = 100;
int RFcenter = 65;     // variable to store the center servo position 

int LLcenter = 90;
int LFcenter = 75;

int tAngle = 30; 		// tilt angle
int uAngle = 35; 		// turn angle
int sAngle = 35; 		// swing angle
int hAngle = Hcenter;  

void Forward(byte Steps, byte Speed){
  Serial.println("Forward");  
  TiltRightUp(tAngle, Speed);
  for (byte j=0; j<Steps; ++j){
    SwingRight(sAngle, Speed);
    TiltRightDown(tAngle, Speed);
    TiltLeftUp(tAngle, Speed);
    SwingRcenter(sAngle, Speed);
    SwingLeft(sAngle, Speed);
    TiltLeftDown(tAngle, Speed);
    TiltRightUp(tAngle, Speed);
    SwingLcenter(sAngle, Speed);
  }
  TiltRightDown(tAngle, Speed);
}

void TurnLeft(byte Steps, byte Speed){
  Serial.println("TurnLeft");  
  TiltLeftUp(uAngle, Speed);
  delay(20);
  for (byte j=0; j<Steps; ++j){
    LeftLegIn(sAngle, Speed);
    TiltLeftDown(uAngle, Speed);
    TiltRightUp(uAngle, Speed);
    delay(20);
    LeftLegIcenter(sAngle, Speed);
    RightLegOut(sAngle, Speed);
    TiltRightDown(uAngle, Speed);
    TiltLeftUp(uAngle, Speed);
    delay(20);
    RightLegOcenter(sAngle, Speed);
  }
  TiltLeftDown(uAngle, Speed);
}

void TurnRight(byte Stps, byte Speed){
  Serial.println("TurnRight");  
  TiltRightUp(uAngle, Speed);
  delay(20);
  for (byte f=0; f<=Stps; ++f){
    RightLegIn(sAngle, Speed);
    TiltRightDown(uAngle, Speed);
    TiltLeftUp(uAngle, Speed);
    delay(20);
    RightLegIcenter(sAngle, Speed);
    LeftLegOut(sAngle, Speed);
    TiltLeftDown(uAngle, Speed);
    TiltRightUp(uAngle, Speed);
    delay(20);
    LeftLegOcenter(sAngle, Speed);
  }
  TiltRightDown(uAngle, Speed);
}

void HeadRight() {
  Serial.println("HeadRight");  
  Head.write(Hcenter - 105);              
  delay(1000);
}

void HeadLeft() {
  Serial.println("HeadLeft");  
  Head.write(Hcenter + 105);         
  delay(1000);
}

void HeadCenter() {
  Serial.println("HeadCenter");  
  Head.write(Hcenter);              
  delay(1000);
}
void TiltRightUp(byte ang, byte sp){  
  //tilt right up
  for (int i=0; i<=ang; i+=5){
    Lfoot.write(LFcenter+i);
    Rfoot.write(RFcenter+i);
    delay(sp);
  }
}
void TiltRightDown(byte ang, byte sp){
  //tilt right down
  for (int i=ang; i>0; i-=5){
    Lfoot.write(LFcenter+i);
    Rfoot.write(RFcenter+i);
    delay(sp);
  }
}

void TiltLeftUp(byte ang, byte sp){
  //tilt left up
  for (int i=0; i<=ang; i+=5){
    Lfoot.write(LFcenter-i);
    Rfoot.write(RFcenter-i);
    delay(sp);
  }
}
void TiltLeftDown(byte ang, byte sp){
  //tilt left down
  for (int i=ang; i>0; i-=5){
    Lfoot.write(LFcenter-i);
    Rfoot.write(RFcenter-i);
    delay(sp);
  }
}

void LeftFootUp(char ang, byte sp){
  //tilt left up
  for (int i=0; i<=ang; i+=5){
    Lfoot.write(LFcenter-i);
    delay(sp);
  }
}
void LeftFootDown(byte ang, byte sp){
  //tilt left down
  for (int i=ang; i>0; i-=5){
    Lfoot.write(LFcenter-i);
    delay(sp);
  }
}

void RightFootUp(byte ang, byte sp){  
  //tilt right up
  for (int i=0; i<=ang; i+=5){
    Rfoot.write(RFcenter+i);
    delay(sp);
  }
}
void RightFootDown(byte ang, byte sp){
  //tilt right down
  for (int i=ang; i>0; i-=5){
    Rfoot.write(RFcenter+i);
    delay(sp);
  }
}

void SwingRight(byte ang, byte sp){
  //swing right
  for (int i=0; i<=ang; i+=5){
    Lleg.write(LLcenter-i);
    Rleg.write(RLcenter-i);
    delay(sp);
  }
}
void SwingRcenter(byte ang, byte sp){
  //swing r->center
  for (int i=ang; i>0; i-=5){
    Lleg.write(LLcenter-i);
    Rleg.write(RLcenter-i);
    delay(sp);
  }
}

void SwingLeft(byte ang, byte sp){
  //swing left
  for (byte i=0; i<=ang; i=i+5){
    Lleg.write(LLcenter+i);
    Rleg.write(RLcenter+i);
    delay(sp);
  }
}
void SwingLcenter(byte ang, byte sp){
  //swing l->center
  for (byte i=ang; i>0; i=i-5){
    Lleg.write(LLcenter+i);
    Rleg.write(RLcenter+i);
    delay(sp);
  }
}

void RightLegIn(byte ang, byte sp){
  //swing right
  for (int i=0; i<=ang; i+=5){
    Rleg.write(RLcenter-i);
    delay(sp);
  }
}
void RightLegIcenter(byte ang, byte sp){
  //swing r->center
  for (int i=ang; i>0; i-=5){
    Rleg.write(RLcenter-i);
    delay(sp);
  }
}

void RightLegOut(byte ang, byte sp){
  //swing right
  for (int i=0; i<=ang; i+=5){
    Rleg.write(RLcenter+i);
    delay(sp);
  }
}
void RightLegOcenter(byte ang, byte sp){
  //swing r->center
  for (int i=ang; i>0; i-=5){
    Rleg.write(RLcenter+i);
    delay(sp);
  }
}

void LeftLegIn(byte ang, byte sp){
  //swing left
  for (byte i=0; i<=ang; i=i+5){
    Lleg.write(LLcenter+i);
    delay(sp);
  }
}
void LeftLegIcenter(byte ang, byte sp){
  //swing l->center
  for (byte i=ang; i>0; i=i-5){
    Lleg.write(LLcenter+i);
    delay(sp);
  }
}

void LeftLegOut(byte ang, byte sp){
  //swing left
  for (byte i=0; i<=ang; i=i+5){
    Lleg.write(LLcenter-i);
    delay(sp);
  }
}
void LeftLegOcenter(byte ang, byte sp){
  //swing l->center
  for (byte i=ang; i>0; i=i-5){
    Lleg.write(LLcenter-i);
    delay(sp);
  }
}

void setup() {
	Serial.begin(19200);
	Serial.println("Bipedino setup is running.");
	Lleg.attach(LEFTLEG);
	Rleg.attach(RIGHTLEG);  
	Lfoot.attach(LEFTFOOT);  
	Rfoot.attach(RIGHTFOOT);  
	Head.attach(HEAD); 

	CenterServos(); 
	delay(500);

	for (int i = 0; i < 5; ++i) {
		GetSonar();
		delay(1000);
	}
	Serial.println("Bipedino is ready.");
} // setup()

void loop() {
	unsigned int cmCenter = MAX_DISTANCE;
	unsigned int cmLeft   = MAX_DISTANCE;
	unsigned int cmRight  = MAX_DISTANCE;

	HeadCenter();
	cmCenter = GetSonar();

	if (cmCenter < 20) {
		HeadRight();
		cmRight = GetSonar();
		HeadCenter();
		if (cmRight > 20) {
			TurnRight(1, 30);
		} else {
			HeadLeft();
			cmLeft = GetSonar();
			HeadCenter();
			if (cmLeft > 20) {
				TurnLeft(1, 30);
			}
		} 
	} else {
		int nSteps = cmCenter / 5;

		if (nSteps > 5) {
			nSteps = 5;
		}
		else {
			nSteps = 1;
		}
		
		Serial.print("Steps <");
		Serial.print(nSteps); 
		Serial.println(">");  
		
		for (int n = 0; n < nSteps; n++) {
			Forward(1, 30); 
		}
	}
} // loop()

int GetSonar() {
	unsigned int uS = sonar.ping(); // Send ping, get ping time in microseconds (uS).
	Serial.print("Ping: ");
	Serial.print(uS / US_ROUNDTRIP_CM); // Convert ping time to distance and print result (0 = outside set distance range, no ping echo)
	Serial.println("cm");  

	return uS / US_ROUNDTRIP_CM;
} // GetSonar()

void CenterServos() { 
	Lleg.write(LLcenter);              // tell servo to go to position in variable 'center' 
	Rleg.write(RLcenter);              // tell servo to go to position in variable 'center' 
	Lfoot.write(LFcenter);              // tell servo to go to position in variable 'center' 
	Rfoot.write(RFcenter);              // tell servo to go to position in variable 'center' 
	Head.write(Hcenter);              // tell servo to go to position in variable 'center' 
	delay(1000);                     // waits 100ms for the servos to reach the position 
} // CenterServos()

Custom parts and enclosures

design

Schematics

connection
Final pmqr4tgkqj

Comments

Similar projects you might like

Arduino Quadruped

Project tutorial by Renga

  • 1,724 views
  • 0 comments
  • 15 respects

Project 1: 2WD Obstacle Avoiding Robot

Project showcase by HDA Robotics

  • 20,851 views
  • 11 comments
  • 32 respects

Arduino Training Platform

Project tutorial by MEGA DAS

  • 2,909 views
  • 9 comments
  • 17 respects

3D-Printed Arduino Obstacle Avoiding Robot

Project tutorial by Arnov Sharma

  • 2,143 views
  • 0 comments
  • 3 respects

Obstacles Avoiding Robot With Servo Motor

Project tutorial by Sora JY

  • 9,440 views
  • 3 comments
  • 26 respects

Ugly Bug

Project tutorial by Jeremie

  • 9,152 views
  • 13 comments
  • 42 respects
Add projectSign up / Login