Note: This project was originally developed as a so called Foundation of Design Practicum(FDP) course project in 2023.
- Arduino UNO board
- 3 Ultrasonic sensors (HC-SR04)
- 2 DC motors with wheels
- Motor driver (L298N)
- Chassis for the robot
- Power supply (Battery)
- Left Sensor: Trigger=A4, Echo=A5
- Front Sensor: Trigger=A2, Echo=A3
- Right Sensor: Trigger=A0, Echo=A1
- Left Motor: Forward=6, Backward=3, Enable=9
- Right Motor: Forward=5, Backward=10, Enable=11
double Kp = 1; // Proportional gain
double Ki = 0.05; // Integral gain
double Kd = 0.01; // Derivative gain
These values control how well the robot stays centered in the maze path. Adjust if robot wobbles or hits walls.
int LturnTime = 500; // Left turn duration
int RturnTime = 560; // Right turn duration
int UturnTime = 1050; // U-turn duration
int FATTime = 575; // Forward after turn time
These control how long each turn movement lasts. Adjust based on your robot's speed and maze dimensions.
double threshold = 0; // Initial side wall detection threshold
double fThreshold = 0; // Initial front wall detection threshold
The thresholds are dynamically calculated when the robot starts, based on the maze dimensions:
fThreshold = leftDistance + rightDistance + 10
(corridor width plus margin)threshold = mean * 4
(where mean is average of left and right distances)
This auto-calibration ensures the robot adapts to different maze sizes. The thresholds determine when the robot decides to turn.
-
Hardware Assembly:
- Mount the 3 ultrasonic sensors (left, front, right)
- Connect motors to motor driver
- Wire everything to Arduino according to pin definitions
-
Software Setup:
- Install Arduino IDE
- Install CH34X driver for Arduino communication
- Install PID Library: https://github.com/br3ttb/Arduino-PID-Library
- Upload the code to Arduino
-
Calibration Steps:
- Start with default PID values
- Test robot in a straight corridor
- If robot wobbles: decrease Kp
- If robot hits walls: increase Kp
- Adjust turn timings until robot makes proper 90Β° turns
- Fine-tune threshold values based on maze dimensions
The robot uses a Right Wall Following Algorithm with PID control:
- Continuously reads distances from all 3 sensors
- Uses PID to maintain equal distance from side walls
- Makes decisions based on sensor readings:
- Right wall open -> Turn right
- Front wall clear -> Go straight
- Left wall open -> Turn left
- Dead end -> U-turn
The code in Code.cpp contains all the logic for navigation and motor control.
Remember to test thoroughly in your specific maze as dimensions and surface conditions can affect performance.