Megan Ying Logo Image
Megan Ying

Mobile Robot

Programming an Arduino robot to autonomously navigate an obstacle course by using infrared and ultrasonic sensor input for motor control.

Overview

In this project, I worked in a team to program a mobile robot using Arduino. Our objective was to design a control algorithm to allow the robot to navigate through an obstacle course as quickly as possible. The course inovlved following a curved line and evading a series of sliding walls.

Code

Our robot utilized a differential drive mechanism, featuring wheels on each side attached to individual motors. Our program uses input from an ultrasonic sensor and an infrared sensor to determine the voltage that needs to be supplied to each motor. In the initial phase of code development, our team focused on determining which values were needed to assess whether the line tracking sensors detected the line. We devised a program that would print the sensor values when placed directly on the line. This enabled us to fine-tune our program to recognize the robot was positioned on the line when sensor readings surpassing a specific threshold. Furthermore, our program would deactivate the robot's motors when the ultrasonic sensor detected an object within a certain distance.

Within the loop section of our code, we integrated several if statements to assess whether the robot is on the line and whether there is a nearby obstacle. Specifically, one set of if statements allowed the algorithm to determine which infrared sensor (left, right, or middle) last detected the line once the robot deviates from the path. If the line was last detected on the right side, our algorithm adjusted the motor voltages to prompt the robot to turn left, enabling it to realign with the line. The same applies for if the line was last detected on the left side.

We also used a series of if statements to regulate the speed of our robot. If an object is detected by the ultrasonic sensor, both motor voltages are set to 0 volts. If only the middle infrared sensor detected the line, both motors operate at the same speed. However, if both the middle and left sensors detect the line, the speed of the left motor is adjusted to be slightly slower than the right motor. This prevent abrupt turns in the opposite direction. The same adjustment is made if the middle and right sensors both detect the line. Conversely, if only the left or right sensor detected the line, the speed difference between the right and left motors increases to facilitate quicker turns.

Mobile robot
Figure 1: Robot navigating obstacle course

Results

During testing, our robot successfully evaded all moving obstacles and completed the course in 26 seconds, outperforming 75% of other robots. It was able to steer itself back onto the line when a deviation was detected. This project provided me with valuable experience in Arduino programming. Additionally, I gained insight into the kinematics of differential drive robots.

Tools Used

Arduino