HUMAN FOLLOWER ROBOT

by msnikhilslm in Workshop > Science

46 Views, 2 Favorites, 0 Comments

HUMAN FOLLOWER ROBOT

idn.png

The robot utilizes an HC-SR04 Ultrasonic Sensor to maintain a specific distance from a target (a human). By calculating the "Time of Flight" of sound waves, the Arduino Nano adjusts the motor speeds and directions via the L298N Dual H-Bridge driver. The mechanical configuration uses a Differential Drive system with two powered wheels and one passive castor wheel for 360-degree mobility.

Supplies

BO.png
l29.png
ser.png
ult.png

1.Ultrasonic sensor

2.L298N motor driver

3.jumper cables

4. 2 X BO Motors

5.SG90 Servo motor

6.Castor wheel

7.Arduino nano

Chassis Assembly

cah.png


The balance of the robot is really important for it to move smoothly.

Mount the Motors: Put your two DC gear motors at the back or middle of the chassis. Make sure they are perfectly parallel to each other.

Install the Castor Wheel: Put the castor wheel at the front. This will help form a tripod.

Sensor Placement: Put the HC-SR04 sensor right at the front facing forward. It should be, at a height where it can easily detect a persons legs. Avoid putting it too low where it might detect the floor.

Wiring

Motor Connections: Connect the left motor to the Out1/Out2 terminals and the right motor to Out3/Out4.

L298N motor driver connection

IN1-D5

IN2-D4

IN3-D3

IN4-D2

ENA-D6

ENB-D7

Servo motor connection

VCC-5V

GND-GND

Signal-D8

Ultrasonic sensor connection

VCC-5V

GND-GND

TRIG-D10

ECHO-D11

Wiring & Power Management

ls.png

Drive Power: Connect a 7.4V or 9V battery to the L298N 12V and GND terminals.

The Common Ground Rule: Connect the GND of the L298N to the GND pin of the Arduino Nano.

Note: If the servo jitter causes the Nano to reset, use a dedicated 5V regulator for the servo.

Coding

155.png

Uploading the code: Open the Arduino IDE and type the code and Upload it

CODE

165.png
/*
* Project: Human Follower Robot (by nikhil.M.S)
* Hardware: Arduino Nano, L298N Motor Driver, HC-SR04, Micro Servo
* Pin Mapping:
* - Servo: D8
* - Ultrasonic: Trig (D10), Echo (D11)
* - L298N: IN1(D5), IN2(D4), IN3(D3), IN4(D2), ENA(D6), ENB(D7)
*/

#include <Servo.h>

// Pin Definitions
const int servoPin = 8;
const int trigPin = 10;
const int echoPin = 11;
const int in1 = 5;
const int in2 = 4;
const int in3 = 3;
const int in4 = 2;
const int ena = 6;
const int enb = 7;

// Calibration Constants
const int targetDistance = 20; // Maintain 20cm distance
const int buffer = 5; // Allow 5cm "Dead Zone"
const int maxSpeed = 180; // PWM Speed (0-255)

Servo radarServo;

void setup() {
// Motor Pins
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(ena, OUTPUT);
pinMode(enb, OUTPUT);

// Sensor Pins
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);

// Initialize Servo
radarServo.attach(servoPin);
radarServo.write(90); // Look straight ahead

Serial.begin(9600);
}

void loop() {
int distance = getDistance();

// Logic Cycle
if (distance > (targetDistance + buffer) && distance < 50) {
// Target is moving away - FOLLOW
moveForward();
}
else if (distance < (targetDistance - buffer) && distance > 2) {
// Target is too close - BACK UP
moveBackward();
}
else {
// Target is in the "Sweet Spot" - STOP
stopMotors();
}

delay(60); // Stability delay for the ultrasonic sensor
}

// Function to calculate distance using the HC-SR04
int getDistance() {
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);

long duration = pulseIn(echoPin, HIGH);
int d = duration * 0.034 / 2;

// Filtering out-of-range noise
if (d == 0 || d > 200) return 100;
return d;
}

void moveForward() {
analogWrite(ena, maxSpeed);
analogWrite(enb, maxSpeed);
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
digitalWrite(in3, HIGH);
digitalWrite(in4, LOW);
}

void moveBackward() {
analogWrite(ena, maxSpeed - 30); // Slower reverse for safety
analogWrite(enb, maxSpeed - 30);
digitalWrite(in1, LOW);
digitalWrite(in2, HIGH);
digitalWrite(in3, LOW);
digitalWrite(in4, HIGH);
}

void stopMotors() {
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}

Conclusion

The Human Follower Robot operates as a closed-loop feedback system where the Arduino Nano acts as the central processor, constantly polling an HC-SR04 ultrasonic sensor mounted on a servo to map the distance to a target. By triggering a sonic pulse and measuring its return time, the Nano calculates the real-time proximity of a human; if the target moves beyond a set threshold, the Nano sends PWM signals to the L298N motor driver (via pins D2-D7) to engage the dual DC motors and close the gap. The mechanical stability is maintained by a differential drive system and a front castor wheel, allowing the robot to pivot smoothly and adjust its heading based on the sensor's wide-angle scan, ensuring it maintains a consistent "sweet spot" distance without physical collision.