STEMpedia
Published © CC BY

Autonomous Biped Robot Using Arduino Based Embedded Platform

This project will show you how to make a DIY autonomous biped robot.

AdvancedFull instructions provided1,053
Autonomous Biped Robot Using Arduino Based Embedded Platform

Things used in this project

Hardware components

evive
STEMpedia evive
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×1
Metal Servo
×4
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Ultrasonic Sensor Holder
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Arduino Mega 2560
Arduino Mega 2560
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Custom parts and enclosures

Foot+Left.STL

Foot+Right.STL

Leg.STL

Base+Plate.STL

Schematics

Fritzing Diagram for Biped

Code

Arduino Code for Biped

Arduino
#include <Arduino.h>
#include <Wire.h>
#include <SoftwareSerial.h>

#include "evive.h"
#include "Servo.h"

double angle_rad = PI/180.0;
double angle_deg = 180.0/PI;
void stop();
Servo servo_4;
Servo servo_44;
Servo servo_2;
Servo servo_45;
Servo servo_3;
void back();
double dela;
void reverse();
double DelayTime;
void Forward();
void Left();
void Right();
TFT_ST7735 lcd = TFT_ST7735();
float getDistance(int trig,int echo){
    pinMode(trig,OUTPUT);
    digitalWrite(trig,LOW);
    delayMicroseconds(2);
    digitalWrite(trig,HIGH);
    delayMicroseconds(10);
    digitalWrite(trig,LOW);
    pinMode(echo, INPUT);
    return pulseIn(echo,HIGH,30000)/58.0;
}


void stop()
{
    servo_4.write(90); // write to servo
    
    servo_44.write(90); // write to servo
    
    servo_2.write(90); // write to servo
    
    servo_45.write(90); // write to servo
    
    servo_3.write(90); // write to servo
    
}

void back()
{
    servo_4.write(90); // write to servo
    
    servo_2.write(145); // write to servo
    
    _delay(dela);
    
    servo_3.write(125); // write to servo
    
    _delay(dela);
    
    servo_44.write(110); // write to servo
    
    servo_45.write(110); // write to servo
    
    _delay(dela);
    
    servo_2.write(90); // write to servo
    
    _delay(dela);
    
    servo_3.write(90); // write to servo
    
    _delay(dela);
    
    servo_3.write(35); // write to servo
    
    _delay(dela);
    
    servo_2.write(55); // write to servo
    
    _delay(dela);
    
    servo_44.write(70); // write to servo
    
    servo_45.write(70); // write to servo
    
    _delay(dela);
    
    servo_3.write(90); // write to servo
    
    _delay(dela);
    
    servo_2.write(90); // write to servo
    
    _delay(dela);
    
}

void reverse()
{
    back();
    
    _delay(DelayTime);
    
    Left();
    
    _delay((DelayTime) * (3));
    
}

void Forward()
{
    servo_4.write(90); // write to servo
    
    servo_2.write(145); // write to servo
    
    _delay(0.1);
    
    servo_3.write(125); // write to servo
    
    _delay(dela);
    
    servo_44.write(70); // write to servo
    
    servo_45.write(80); // write to servo
    
    _delay(0.1);
    
    servo_45.write(70); // write to servo
    
    _delay(0.1);
    
    servo_2.write(90); // write to servo
    
    _delay(0.1);
    
    servo_3.write(90); // write to servo
    
    _delay(dela);
    
    servo_3.write(35); // write to servo
    
    _delay(dela);
    
    servo_2.write(55); // write to servo
    
    _delay(dela);
    
    servo_45.write(110); // write to servo
    
    servo_44.write(80); // write to servo
    
    _delay(0.1);
    
    servo_44.write(90); // write to servo
    
    _delay(0.1);
    
    servo_44.write(100); // write to servo
    
    _delay(0.1);
    
    servo_44.write(110); // write to servo
    
    _delay(0.1);
    
    servo_3.write(90); // write to servo
    
    _delay(0.1);
    
    servo_2.write(90); // write to servo
    
    _delay(dela);
    
}

void Left()
{
    servo_4.write(90); // write to servo
    
    servo_2.write(145); // write to servo
    
    _delay(0.1);
    
    servo_3.write(125); // write to servo
    
    _delay(dela);
    
    servo_44.write(70); // write to servo
    
    servo_45.write(80); // write to servo
    
    _delay(0.1);
    
    servo_45.write(70); // write to servo
    
    _delay(0.1);
    
    servo_2.write(90); // write to servo
    
    _delay(0.1);
    
    servo_3.write(90); // write to servo
    
    _delay(dela);
    
    servo_3.write(35); // write to servo
    
    _delay(dela);
    
    servo_2.write(55); // write to servo
    
    _delay(dela);
    
    servo_44.write(130); // write to servo
    
    servo_45.write(90); // write to servo
    
    _delay(0.1);
    
    servo_3.write(90); // write to servo
    
    _delay(0.1);
    
    servo_2.write(90); // write to servo
    
    _delay(dela);
    
}

void Right()
{
    servo_4.write(90); // write to servo
    
    servo_2.write(145); // write to servo
    
    _delay(0.1);
    
    servo_3.write(125); // write to servo
    
    _delay(dela);
    
    servo_44.write(70); // write to servo
    
    servo_45.write(80); // write to servo
    
    _delay(0.1);
    
    servo_45.write(70); // write to servo
    
    _delay(0.1);
    
    servo_2.write(90); // write to servo
    
    _delay(0.1);
    
    servo_3.write(90); // write to servo
    
    _delay(dela);
    
    servo_3.write(35); // write to servo
    
    _delay(dela);
    
    servo_2.write(55); // write to servo
    
    _delay(dela);
    
    servo_45.write(130); // write to servo
    
    servo_44.write(90); // write to servo
    
    _delay(0.1);
    
    servo_3.write(90); // write to servo
    
    _delay(0.1);
    
    servo_2.write(90); // write to servo
    
    _delay(dela);
    
}


void setup(){
    lcd.init(INITR_BLACKTAB);
     lcd.setRotation(1);
    DelayTime = 0.5;
    dela = 0.5;
    lcd.fillScreen(0);
    
    servo_4.attach(4); // init pin
    servo_44.attach(44); // init pin
    servo_2.attach(2); // init pin
    servo_45.attach(45); // init pin
    servo_3.attach(3); // init pin
    pinMode(A0+7,INPUT);
    pinMode(40,INPUT);
}

void loop(){
    
    lcd.setCursor(10, 10);
    lcd.print((analogRead(A0+7)) / (0.0381));
    if(((digitalRead(40))==(1))){
        if((getDistance(8,9)) < (15)){
            stop();
            lcd.setCursor(10, 20);
            lcd.print("Obstacle");
            servo_4.write(45); // write to servo
            _delay(0.5);
            if((getDistance(8,9)) > (25)){
                Right();
                lcd.setCursor(10, 20);
                lcd.print("Right   ");
                _delay(DelayTime);
            }else{
                servo_4.write(135); // write to servo
                lcd.setCursor(10, 20);
                lcd.print("Obstacle");
                _delay(0.5);
                if((getDistance(8,9)) > (25)){
                    Left();
                    lcd.setCursor(10, 20);
                    lcd.print("Left    ");
                    _delay(DelayTime);
                }else{
                    servo_4.write(0); // write to servo
                    lcd.setCursor(10, 20);
                    lcd.print("obstacle");
                    _delay(0.5);
                    if((getDistance(8,9)) > (25)){
                        Right();
                        lcd.setCursor(10, 20);
                        lcd.print("Right   ");
                        _delay((DelayTime) * (2));
                    }else{
                        servo_4.write(180); // write to servo
                        lcd.setCursor(10, 20);
                        lcd.print("obstacle");
                        _delay(0.5);
                        if((getDistance(8,9)) > (25)){
                            Left();
                            lcd.setCursor(10, 20);
                            lcd.print("Left    ");
                            _delay((DelayTime) * (2));
                        }else{
                            reverse();
                            lcd.setCursor(10, 20);
                            lcd.print("Reverse ");
                        }
                    }
                }
            }
        }
        Forward();
        lcd.setCursor(10, 20);
        lcd.print("forward ");
        _delay(0.2);
    }else{
        stop();
        lcd.setCursor(10, 20);
        lcd.print("Stop    ");
    }
    
    _loop();
}

void _delay(float seconds){
    long endTime = millis() + seconds * 1000;
    while(millis() < endTime)_loop();
}

void _loop(){
    
}

evive Library

C/C++
No preview (download only).

Credits

STEMpedia

STEMpedia

42 projects • 169 followers
STEMpedia blends theory with experiential learning by offering state-of-the-art technology, projects, tutorials, courses, and much more.

Comments