Loading...

Human following robot using arduino and ultrasonic sensor | Arduino Geek


Hello everyone! Welcome to Arduino Geek. Today we will discuss about an Arduino based Human following robot. So let's get started.

What is Human following robot?

The uses of arduino is increasing day by day. Arduino can be used in a simple project or even it can be implemented in a complex project to simplify the project. Today we come to you with a new example of arduino project which is “human following robot”. The name simply suggest a robot which can follow the humans. But it is not so simple. A lots of action has to be done for the proper functionality of a human following robot. This complex process can be simplified and modified using an arduino. If you are well known about the properties of arduino, then it will be more easier for you to make this human following robot.

What are the application of human following robot?

A human following robot is used to follow a human being or a particular object. In other words a human following robot will follow any object that comes in front of it. As a result the path of the object becomes the path of the robot.

How do you make a human follow robot?

This question is often asked by the arduino lovers, who want to make a human following robot. In this post I will discuss all the necessary steps that we have to do while building a human following robot. Mainly I cover the three main topics, which are –

(1) The basic structure of human following robot

(2) How to design the circuit of human following robot

(3) How to write down the code for a human following robot

Components –

(1) DC Geared Motor

(2) Arduino Uno

(3) L293D Motor Driver Shield

(4) Servo SG90

(5) Ultrasonic Sensor

(6) IR Sensor

(7) Jumper Wire

(8) Wheels

(9) Lipo Battery

Structure –

The structure of a human following robot is quite different from the other arduino car because we have to include some more sensors (like ultrasonic sensor, ir sensor) in our car. Also the placement of the sensors are quite different from the other arduino project. So we have to keep more attention while building a human following robot. The first important thing is to fix the dc geared motor with the chassis of the car. Take the four dc geared motor and then fix it in the bottom side of the chassis.

The chassis can be made up of ply wood or plastic. After successful completion of this process, take the shaft coupling and connect it with the output shaft of every dc geared motor. The uses of shaft coupling may avoid the vibration of wheels at the time of actual running of car. Then take the wheels and attach them in the shaft coupling. At last make two holes in the middle of chassis and take out the wires of the motor in the upper side of the chassis.

Here the basic structure of the robot is ready. Now we have to look into the component placement and circuit connection.

 

Circuit Connection –

To make the circuit we need different circuit components like Arduino uno, L293D motor driver shield, Ultrasonic sensor, IR sensor and servo motor. At first you have to take the Arduino uno and then fix it in the middle of the chassis. Then take the L293D motor driver shield and put it on Arduino uno. Now gradually connect the dc motors with the motor driver. Also connect the servo in the motor driver. At last you have to connect the Ultrasonic sensor and IR sensors to the arduino.

Connections of Ultrasonic sensor with Arduino –

(1) VCC pin of Ultrasonic sensor – +5 Volt pin of Arduino

(2) GND pin of Ultrasonic sensor – GND pin of Arduino

(3) Echo pin of Ultrasonic sensor – A0 pin of Arduino

(4) Trigger pin of Ultrasonic sensor – A1 Volt pin of Arduino

Connections of IR sensor with Arduino –

(1) VCC pin of the both IR sensor – +5 Volt pin of Arduino

(2) GND pin of both IR Sensor – GND pin of Arduino

(3) Output pin of Right IR sensor – A2 pin of Arduino

(4) Output pin of Left IR sensor – A3 pin of Arduino

 

This is all about the circuit connection. Now you have to give a 12 volt power supply to the circuit. It is always recommended to use a Lipo battery or a Li-ion battery. Remember you have to calibrate the potentiometer of the both IR sensors after uploading the code in Arduino.

Arduino Coding –

Coding is the main important thing of any arduino project. The performance of the robot is fully dependent on the programming. At first connect the arduino with your computer. Then open the Arduino IDE software. Here you have to write the following code –

// Human Following Robot

#include<NewPing.h>
#include<Servo.h>
#include<AFMotor.h>
#define RIGHT A2
#define LEFT A3
#define TRIGGER_PIN A1
#define ECHO_PIN A0
#define MAX_DISTANCE 100
 NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE);
AF_DCMotor Motor1(1,MOTOR12_1KHZ);
AF_DCMotor Motor2(2,MOTOR12_1KHZ);
AF_DCMotor Motor3(3,MOTOR34_1KHZ);
AF_DCMotor Motor4(4,MOTOR34_1KHZ);
Servo myservo;
int pos =0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
myservo.attach(10);
{
for(pos = 90; pos <= 180; pos += 1){
  myservo.write(pos);
  delay(15);
} for(pos = 180; pos >= 0; pos-= 1) {
  myservo.write(pos);
  delay(15);
}for(pos = 0; pos<=90; pos += 1) {
  myservo.write(pos);
  delay(15);
}
}
pinMode(RIGHT, INPUT);
pinMode(LEFT, INPUT);
}
void loop() {
  // put your main code here, to run repeatedly:
  delay(50);
 unsigned int distance = sonar.ping_cm();
Serial.print("distance");
Serial.println(distance);
int Right_Value = digitalRead(RIGHT);
int Left_Value = digitalRead(LEFT);
Serial.print("RIGHT");
Serial.println(Right_Value);
Serial.print("LEFT");
Serial.println(Left_Value);
if((Right_Value==1) && (distance>=10 && distance<=30)&&(Left_Value==1)){
  Motor1.setSpeed(120);
  Motor1.run(FORWARD);
  Motor2.setSpeed(120);
  Motor2.run(FORWARD);
  Motor3.setSpeed(120);
  Motor3.run(FORWARD);
  Motor4.setSpeed(120);
  Motor4.run(FORWARD);
}else if((Right_Value==0) && (Left_Value==1)) {
  Motor1.setSpeed(200);
  Motor1.run(FORWARD);
  Motor2.setSpeed(200);
  Motor2.run(FORWARD);
  Motor3.setSpeed(100);
  Motor3.run(BACKWARD);
  Motor4.setSpeed(100);
  Motor4.run(BACKWARD);
}else if((Right_Value==1)&&(Left_Value==0)) {
  Motor1.setSpeed(100);
  Motor1.run(BACKWARD);
  Motor2.setSpeed(100);
  Motor2.run(BACKWARD);
  Motor3.setSpeed(200);
  Motor3.run(FORWARD);
  Motor4.setSpeed(200);
  Motor4.run(FORWARD);
}else if((Right_Value==1)&&(Left_Value==1)) {
  Motor1.setSpeed(0);
  Motor1.run(RELEASE);
  Motor2.setSpeed(0);
  Motor2.run(RELEASE);
  Motor3.setSpeed(0);
  Motor3.run(RELEASE);
  Motor4.setSpeed(0);
  Motor4.run(RELEASE);
}else if(distance > 1 && distance < 10) {
  Motor1.setSpeed(0);
  Motor1.run(RELEASE);
  Motor2.setSpeed(0);
  Motor2.run(RELEASE);
  Motor3.setSpeed(0);
  Motor3.run(RELEASE);
  Motor4.setSpeed(0);
  Motor4.run(RELEASE);
  }
 }

After write down the code, you have to upload it in your arduino. But before this, you have to choose the correct board type and port. Open the tools and then select the board type which is “Arduino uno”. Again select the correct port from the tools menu. Finally upload the code to the arduino. After uploading the code you can disconnect the arduino from your computer.

How do Human following robot work?

Place the human following robot in a flat surface and switch on the circuit. Now the servo motor will start moving and the robot is trying to find some object to follow. As soon as it detects any object it will start to follow it. For an experiment you can put one of your hand in front of the robot. You can observe that the robot is coming towards your hand. Similarly you can hold any other object in front of the robot and the robot will start to follow the object. 

 
close