How to make a hand following robot using Arduino | Human following robot

Hello, welcome back. In this tutorial, we will learn how to make a Hand following robot using an Arduino. Two IR sensors are mainly used for this project. Also, this project is based on the Arduino UNO board and the L293D motor driver shield. This tutorial shows you step by step how to build a robot car with pictures. So you can easily make this.

The process of this hand following robot

When this robot car is activated, the two IR sensors are activated and start receiving inputs. Then, when moving your hand near the sensor on the left side, the robot car turns to the left as it receives a signal through that sensor, and when you move your hand near the sensor on the right side, the robot car turns right. Also, when you move your hand near the two sensors, the robot car moves forward as it receives a signal from both sensors.

OK, let’s do this project step by step. The required components are given below.

Step 1

Firstly, identify these components.

Step 2

Secondly, glue the gear motors as follows.

Step 3

Thirdly, connect the L293D motor shield to the Arduino UNO board. Then, glue the top of the dot board.

Step 4

Now, connect the gear motors to the motor driver shield. To do this, use the circuit diagram below.

How to make a hand following robot using Arduino

Step 5

Now, glue the two IR sensors to a piece of foam board or cardboard as follows.

Step 6

Then, connect these sensors to the Arduino board. After, glue it to the dot board.

Step 7

Next, attach the li-ion battery holder to the dot board and connect it to the Arduino board.

Step 8

Now, connect this robot car to the computer using a USB cable.

Step 9

OK, let’s creates the program for this project.

/*Human following robot with Arduino.
  created by the SriTu Hobby team.
  Read the code below and use it for any of your creations.
*/

#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

int Speed = 200;

#define sensor1 A0
#define sensor2 A1

void setup() {
  Serial.begin(9600);
  motor1.setSpeed(Speed);
  motor2.setSpeed(Speed);
  motor3.setSpeed(Speed);
  motor4.setSpeed(Speed);
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
}

void loop() {

  bool value1 = digitalRead(sensor1);
  bool value2 = digitalRead(sensor2);
  Serial.println(value2);
  Serial.println(value1);

  if (value1 == 0 && value2 == 0 ) {
    motor1.run(FORWARD);
    motor2.run(FORWARD);
    motor3.run(FORWARD);
    motor4.run(FORWARD);
  } else if (value1 == 1 && value2 == 1) {
    motor1.run(RELEASE);
    motor2.run(RELEASE);
    motor3.run(RELEASE);
    motor4.run(RELEASE);
  } else if (value1 == 0 && value2 == 1) {
    motor1.run(FORWARD);
    motor2.run(FORWARD);
    motor3.run(BACKWARD);
    motor4.run(BACKWARD);
  } else if (value1 == 1 && value2 == 0) {
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
    motor3.run(FORWARD);
    motor4.run(FORWARD);
  }
}

Code explanation

First, the AF Motor Library is included. Then, objects are created for the motor drive shield terminals.

#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
AF_DCMotor motor3(3);
AF_DCMotor motor4(4);

Secondly, sensor pins are defined.

#define sensor1 A0
#define sensor2 A1

In the setup function,

void setup() {
//The serial monitor is begin
  Serial.begin(9600);
//These codes set the motor speed
  motor1.setSpeed(Speed);
  motor2.setSpeed(Speed);
  motor3.setSpeed(Speed);
  motor4.setSpeed(Speed);
//The sensor pins are set as INPUT pins
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
}

In the loop function,

void loop() {
//Gets the sensor values
  bool value1 = digitalRead(sensor1);
  bool value2 = digitalRead(sensor2);
//These values are printed on the serial monitor
  Serial.println(value2);
  Serial.println(value1);
//These values are checked using the IF condition. If the value of both sensors is 0, the robot car move forward.
  if (value1 == 0 && value2 == 0 ) {
    motor1.run(FORWARD);
    motor2.run(FORWARD);
    motor3.run(FORWARD);
    motor4.run(FORWARD);
//If the values of both sensors is 1, the robot car is stopped
  } else if (value1 == 1 && value2 == 1) {
    motor1.run(RELEASE);
    motor2.run(RELEASE);
    motor3.run(RELEASE);
    motor4.run(RELEASE);
//If the left sensor value is 0, the robot car turns left
  } else if (value1 == 0 && value2 == 1) {
    motor1.run(FORWARD);
    motor2.run(FORWARD);
    motor3.run(BACKWARD);
    motor4.run(BACKWARD);
//If the right sensor value is 0, the robot car turns right
  } else if (value1 == 1 && value2 == 0) {
    motor1.run(BACKWARD);
    motor2.run(BACKWARD);
    motor3.run(FORWARD);
    motor4.run(FORWARD);
  }
}

Step 10

Then, select board and port. After, upload this code to the Arduino board.

Step 11

Lastly, attach the robot wheels and put the batteries into the battery holder.

OK, enjoy this project. The full video guide is given below. So, we will meet in the next tutorial.

How to make a hand following robot using Arduino | Human following robot

Similar Posts

Leave a Reply

Your email address will not be published.