An Arduino-based autonomous vehicle that follows a line using six infrared sensors and detects obstacles using an HC-SR04 ultrasonic sensor. The project combines embedded C++ programming, sensor integration, motor control, and a custom 3D-designed steering mechanism.
This project was developed during my first semester at Cairo University as an introduction to embedded systems and hardware-software integration.
The vehicle uses infrared sensors to detect and follow a track while continuously monitoring its surroundings with an ultrasonic sensor. When an obstacle is detected within a defined distance, the vehicle stops to prevent a collision.
In addition to the control software and electronics, I designed a custom steering mechanism in Tinkercad and integrated it with a servo motor as part of the vehicle's mechanical design.
- Line Following — Uses six IR sensors (three front and three rear) to detect the track and determine the vehicle's direction.
- Obstacle Detection — Uses an HC-SR04 ultrasonic sensor to detect objects within 20 cm and stop the vehicle.
- Motor Control — Controls two DC motors through an L298N motor driver for forward movement, turning, and stopping.
- Speed Control — Adjusts motor behavior according to sensor readings and movement conditions.
- Custom Steering System — Designed a 3D-printed steering mechanism and integrated it with a servo motor.
- Embedded Control — Programmed the vehicle in C++ using the Arduino platform.
| Component | Purpose |
|---|---|
| Arduino Uno R3 | Main microcontroller |
| 6 × IR Sensors | Line detection |
| HC-SR04 Ultrasonic Sensor | Obstacle detection |
| 2 × DC Motors | Vehicle movement |
| L298N Motor Driver | Motor control |
| Servo Motor | Steering mechanism |
| DC-DC Converter | Power regulation |
| Battery / Power Supply | Vehicle power |
- C++
- Arduino IDE
- Arduino platform
- Tinkercad
- Embedded sensor and motor control
The vehicle continuously processes sensor input and uses it to determine the appropriate motor behavior.
┌─────────────────┐
│ IR Sensors │
│ 3 Front + 3 Rear
└────────┬────────┘
│
▼
┌─────────────────┐
│ Arduino Uno │
│ Control Logic │
└───────┬─────────┘
│
┌─────────┴─────────┐
│ │
▼ ▼
┌───────────────┐ ┌────────────────┐
│ Motor Driver │ │ HC-SR04 │
│ L298N │ │ Ultrasonic │
└───────┬───────┘ └───────┬────────┘
│ │
▼ │
┌─────────────┐ │
│ DC Motors │◄──────────┘
└─────────────┘
The six IR sensors continuously monitor the position of the line beneath the vehicle.
Based on the sensor readings, the controller determines whether the vehicle should:
- Continue forward
- Turn left
- Turn right
- Stop
The HC-SR04 measures the distance to objects in front of the vehicle.
If the measured distance falls below 20 cm, the Arduino stops the motors.
if (distance < 20) {
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
digitalWrite(in3, LOW);
digitalWrite(in4, LOW);
}Otherwise, the controller continues the line-following logic.
A custom steering mechanism was designed in Tinkercad and integrated with a servo motor.
The design consisted of:
- Connecting arms
- Structural supports
- Servo motor housing
- Steering components
The design was developed virtually before being incorporated into the physical vehicle.
The virtual assembly demonstrates how the servo motor integrates with the custom steering mechanism.
The Tinkercad model shows the individual components of the custom steering system and their intended arrangement.
The wiring integrates the Arduino, IR sensors, ultrasonic sensor, motor driver, motors, servo, battery, and power regulation components.
The completed vehicle integrates the sensing, control, mechanical, and power systems into a single autonomous platform.
The completed vehicle was able to:
- Follow a predefined track using IR sensor feedback.
- Adjust its movement according to the detected line.
- Detect obstacles using ultrasonic distance measurement.
- Stop automatically when an obstacle was detected within 20 cm.
- Integrate a custom-designed steering mechanism with a servo motor.
This project provided practical experience with:
- Embedded C++ programming
- Arduino microcontroller programming
- Digital sensor integration
- Ultrasonic distance measurement
- DC motor and servo control
- Motor-driver interfacing
- Hardware wiring and debugging
- 3D mechanical prototyping
- Hardware-software integration
It was one of my first projects involving the integration of software, electronics, and mechanical components into a single working system.
.
├── README.md
├── src/
│ └── line_follower.cpp
├── images/
│ ├── final-vehicle.png
│ ├── line-following.png
│ ├── wiring-overview.png
│ ├── steering-assembly.png
│ └── steering-cad.png
└── LICENSE
This project is licensed under the MIT License. See LICENSE for details.
- Arduino for the Arduino hardware and software ecosystem.
- HC-SR04 ultrasonic sensor documentation for distance-measurement implementation.
- IR sensor documentation for line-detection implementation.



