Build Your Own Human Following Bot with Arduino

13 May 2023 Balmiki Mandal 0 µC - µP

This is How You Can Create Your Own Human Following Bot Using Arduino

Arduino is an open-source electronics platform that allows you to build projects with ease. With its versatility and affordability, it has become a popular platform for making robotic projects. One of the most interesting projects that you can make is a human following bot. This bot will be able to identify a person and then follow them around. In this article, we are going to show you how you can create your own human-following bot using Arduino.

Step 1: Gather the Components

Before you can start building your robot, you need to gather all the components that you will need. Here is a list of what you will need:

  • Arduino board
  • Ultrasonic sensor
  • Servo motors
  • Wheels
  • Chassis
  • Wires and connectors

Step 2: Connect the Components

Now that you have all the components, you can start connecting them together. Connect the Arduino board to the ultrasonic sensor and then connect it to the servo motors. Once you have connected everything, you can start programming the Arduino board.

Step 3: Program the Arduino Board

Using the Arduino IDE, you can start programming your robot. You will need to write code that will allow the robot to detect the presence of a human and then follow them. This code will require you to use the ultrasonic sensor to detect the distance between the robot and a person and then use the servo motors to adjust the direction of the wheels accordingly.

Step 4: Assemble the Chassis

Once you have programmed your robot, you will need to assemble the chassis. First, attach the wheels to the chassis and then mount the servo motors to the top. Finally, connect all the wires and the Arduino board to the chassis.

Step 5: Test the Robot

Finally, you can now test your robot and see if it is working. Place the robot in front of a person and it should start following them around. If everything is working as expected, then your robot is ready to go.

Here is an example source code for building a human following robot using Arduino:

#include <AFMotor.h>  // include AFMotor library

#define LEFT_SENSOR A0  // analog input pin for left sensor
#define RIGHT_SENSOR A1  // analog input pin for right sensor
#define LEFT_MOTOR 1  // motor number for left motor
#define RIGHT_MOTOR 2  // motor number for right motor
#define MOTOR_SPEED 100  // motor speed
#define MIN_SENSOR_VALUE 400  // minimum sensor value
#define MAX_SENSOR_VALUE 600  // maximum sensor value
#define MAX_SENSOR_DIFF 50  // maximum difference between sensor values

AF_DCMotor leftMotor(LEFT_MOTOR, MOTOR12_1KHZ);  // create AF_DCMotor instance for left motor
AF_DCMotor rightMotor(RIGHT_MOTOR, MOTOR12_1KHZ);  // create AF_DCMotor instance for right motor

void setup() {
  Serial.begin(9600);  // initialize serial communication
  pinMode(LEFT_SENSOR, INPUT);  // set left sensor pin as input
  pinMode(RIGHT_SENSOR, INPUT);  // set right sensor pin as input
  leftMotor.setSpeed(MOTOR_SPEED);  // set left motor speed
  rightMotor.setSpeed(MOTOR_SPEED);  // set right motor speed
}

void loop() {
  int leftSensorValue = analogRead(LEFT_SENSOR);  // read left sensor value
  int rightSensorValue = analogRead(RIGHT_SENSOR);  // read right sensor value
  int sensorDiff = leftSensorValue - rightSensorValue;  // calculate sensor difference
  Serial.println(sensorDiff);  // print sensor difference to serial monitor
  if (leftSensorValue > MIN_SENSOR_VALUE && rightSensorValue > MIN_SENSOR_VALUE && abs(sensorDiff) < MAX_SENSOR_DIFF) {  // check for valid sensor values and difference
    leftMotor.run(FORWARD);  // set left motor direction to forward
    rightMotor.run(FORWARD);  // set right motor direction to forward
    if (sensorDiff < 0) {  // if sensor difference is negative
      leftMotor.setSpeed(MOTOR_SPEED - (abs(sensorDiff) * 2));  // adjust left motor speed
    } else if (sensorDiff > 0) {  // if sensor difference is positive
      rightMotor.setSpeed(MOTOR_SPEED - (abs(sensorDiff) * 2));  // adjust right motor speed
    }
  } else {  // if sensor values or difference are invalid
    leftMotor.run(RELEASE);  // stop left motor
    rightMotor.run(RELEASE);  // stop right motor
  }
}

In this example, two infrared sensors are connected to the Arduino, and two DC motors are connected to the motor driver shield. The DC motors are controlled using the AFMotor library.

In the setup() function, serial communication is initialized at a baud rate of 9600, and the pins for the infrared sensors are set as inputs. The motor speed is set to 100 using the setSpeed() function for both left and right motors.

In the loop() function, the analogRead() function is used to read the sensor values for both left and right sensors. The difference between the sensor values is then calculated, and printed to the serial monitor using the Serial.println() function.

If the sensor values and difference are valid, the motors are set to run forward using the run() function. The motor speed is adjusted based on the sensor difference using the setSpeed() function. If the sensor difference is negative, the speed of the left motor is decreased, and if the sensor difference is

Conclusion

Building a human following robot using Arduino is a great way to learn about robotics and have some fun at the same time. It won’t be easy but with a little patience and perseverance you will be able to make a robot that will follow you around like a loyal pet. Good luck and have fun!

BY: Balmiki Mandal

Related Blogs

Post Comments.

Login to Post a Comment

No comments yet, Be the first to comment.