You've probably seen or heard of at least one of the following:
- A smart luggage cart at an airport, train or bus station, powered by a motor or battery and automatically following its “owner”.
- A smart cart in a department store follows the customer using it.
- A smart suitcase that pairs with the owner's smartphone and automatically follows that person.
These are examples of an “object-following robot”. This project is based on this concept. The robot will be programmed to look for a nearby object and, once found, will follow it.
Our robot here uses an ultrasonic distance measurement (UDM) sensor to find an object and measure its distance to it. It employs a servo motor to rotate the UDM sensor and is powered by two DC motors. Our robot's control circuit is built using an Arduino Nano board.
Check it out here:
What is necessary
Here's what you need to get started:
1. Wheels
2. DC Gear Motors (200-300 RPM)
3. Mini DC Servo Motor
4. L298 Dual DC Motor Driver Module
5. ArduinoNano Board
6. UDM HC SR04 Sensor
7. A12V Battery
8. 7805 Voltage Regulator
9. A UM66 Melody Tone Generator
10. A small 8 ohm speaker
Robot construction
The complete robot is constructed using plywood or thin sheets of wood. Divide the robot into three sections:
1. Base (platform) – houses two DC motors where the wheels are attached. Two additional free wheels are also attached to this base, helping to move the robot in the required direction.
2. Main body – houses the robot’s main circuit and battery. The servo motor is fixed on top of this body.
3. Robot head – attached to the servo motor shaft and houses the UDM sensor. It can move in different directions.
This figure provides a visual representation of each of the robot's parts:
After the robot body is completed, let's build its control circuit.
System block diagram:
As shown in this diagram, the main building blocks of the robot include:
- UDM HC SR04 sensor: used to find a nearby object and measure its distance from the robot
- L298 Dual DC Motor Driver Module: Used to drive both DC motors, providing the required voltage and current for each
- LM7805 voltage regulator: used to supply 5V power to the UDM sensor and power the servo motor via the battery
- UM66 tone generator speaker: generates melodious audio tone through a speaker, which is used to provide audio output
- Two DC motors: used to drive the robot's rear wheels, moving the robot forward and backward as well as left and right
- A servo motor: used to rotate the robot head (using the UDM sensor) back and forth (CW and CCW) — from 45 to 135 degrees
- 12V Battery: Provides DC motors and the motor driver module as well as the Arduino board
- Arduino Nano development board: the main building block, or brain, of the system and software program.
The Arduino board is responsible for the robot's functionality, performing tasks such as:
- Searching and detecting an object
- Measuring your distance using the UDM sensor
- Rotating the servo motor clockwise (CW) and counterclockwise (CCW) to scan the area using the UDM
- Powering the two DC motors to move the robot forward or to turn left or right
- Continuously tracking the object and its distance using UDM and following it through DC motors
- Playing an audio tone through the speaker using the UM66
Now, let's review the system in detail, starting with the circuit diagram and then its operation.
Circuit Diagram:
As shown in this diagram, the circuit is built using a UDM HC SR04 sensor, an L298 dual DC motor driver module, an LM7805 voltage regulator, and an Arduino Nano development board.
The UDM HC SR04 sensor has four pins: VCC, GND, Trigger and Echo.
- The VCC pin connects to the 5V output of the LM7805
- The GND pin connects to the circuit's common ground
- The Trigger pin is an input pin that connects to the Arduino's D7 pin.
- The Echo pin is an output pin that connects to the Arduino's D6 pin
The servo motor has a three-wire interface: VCC, GND and Signal.
- The LM7805 provides a 5V supply to VCC.
- The pulse width modulation (PWM) signal is supplied to the signal pin from Arduino pin D10
Arduino pins D2 to D5 drive the two DC motors through the L298 driver. These pins connect to the input of the motor driver module, and DC motors connect to the output of the motor driver.
The motor driver requires two sources: 12V from the battery for the motors and 5V from the LM7805 for internal bias and operation.
The UM66 has three pins: input, output and ground.
- The input pin connects to the Arduino's D12 pin
- Output pin connects to speaker
The LM7805 receives 12V input from the battery and generates 5V regulated output. The output is provided to the servo motor, the UDM sensor and the L298 motor driver module.
The operation
The main task of this robot is to search for a nearby object and follow it, keeping a maximum distance of 30 cm behind it. If the object stops, the robot will come within 10 cm of it before stopping too.
If that object moves fast enough more than 30 cm away from the robot, the robot will stop and look for a new object closer to it.
- The robot's operation begins with searching for a nearby object.
- The Arduino board will give the PWM signal to the servo motor to rotate it CCW from 45 o to 135 o in 5 o step (the robot head will move slowly from right to left).
- As the robot head moves, the microcontroller continuously searches for a nearby object using the UDM sensor. It delivers a trigger signal to the sensor and waits for an echo signal in return.
- If no objects are found after a complete cycle, the microcontroller will rotate the servo motor counterclockwise from 135 o to 45 o (and the robot head will move from right to left) and search again.
- If an object is located in front of the UDM sensor, it will send an echo signal back to the microcontroller, which then calculates its distance from the object.
- If the distance is more than 30 cm, it will ignore it and continue to look for a closer object.
- If the distance is less than 30 cm, the microcontroller will stop the servo motor and tilt it towards the nearby object.
- If the servo motor angle is less than 90 ° (meaning between 45 ° to 90 ° ), then the robot will direct both DC motors to turn right.
- And if the motor angle is greater than 90° the robot will direct the DC motors to turn left.
- After turning left or right, the microcontroller will drive both motors forward so that the robot approaches the object.
- While the robot is moving forward, the microcontroller continuously measures the distance to this object using the UDM sensor. The robot will continue to move forward until it reaches a distance of less than 30 cm from the object.
At this point, there may be three possible outcomes:
1. If the object is not moving – the microcontroller will stop the motors (and therefore the robot) as soon as the robot is 10 cm away from the object. Then, the microcontroller will trigger the sensor to start searching for a new object.
2. If the object is moving – the robot moves forward and follows the object.
3. If the object moves more than 30 cm away from the robot – the The microcontroller stops the motors and therefore the robot and triggers the sensor to start searching for a new object.
These operations are available in a program that is downloaded into the internal FLASH memory of the Arduino ATMega328 board. This program is written in C/C++ language on Arduino IDE software tool. It is compiled using the same software and then downloaded to the Arduino Nano board via USB.
Software program
(tagsToTranslate)Arduino