This is an autonomous 4-wheel robot built using an Arduino Uno. It uses an HC-SR04 ultrasonic sensor mounted on a servo motor to scan its surroundings, detect obstacles, and navigate around them.
- Arduino Uno R3
- L293D Motor Driver Shield
- TT Gear Motor (4x)
- Wheels (4x)
- Robot Chassis
- Servo Motor
- Ultrasonic Sensor (HC-SR04)
- ICR 18650 3000mAh 3.7v Rechargeable Li-ion Battery
- 18650 Battery Holder
- DC Power Switch
- Male and Female Jumper wires
- Solder
- Arduino IDE
Here is the wiring diagram for the project.
Connect the four TT Gear Motors to the L293D Motor Driver Shield's screw terminals:
- Motor 1: Connect to
M1AandM1B. - Motor 2: Connect to
M2AandM2B. - Motor 3: Connect to
M3AandM3B. - Motor 4: Connect to
M4AandM4B.
Connect the sensors directly to the Arduino pins:
- HC-SR04 Ultrasonic Sensor:
VCC→5Von ArduinoTrig→ Digital PinD8on ArduinoEcho→ Digital PinD9on ArduinoGND→GNDon Arduino
- Servo Motor:
VCC(Red wire) →5Von ArduinoSignal(Yellow/Orange wire) → Digital PinD7on ArduinoGND(Brown/Black wire) →GNDon Arduino
- The L293D Motor Driver Shield is placed directly on top of the Arduino Uno, connecting all necessary pins automatically.
- The shield's input pins (
ENA,IN1,IN2,IN3,IN4,ENB) are connected to the Arduino's digital pins (e.g., D2-D7) to control motor speed and direction.
- Connect the ICR 18650 batteries to the battery holder.
- Connect the positive (red) and negative (black) wires from the battery holder to the Motor Driver Shield’s
VCCandGNDterminals to power the motors. - Connect another set of wires from the battery holder to the Arduino Uno's
VINandGNDpins to power the Arduino. - Install the DC Power Switch in series with the positive (red) wire coming from the battery holder. This will act as the master power switch for the entire robot.
Here is a picture of the finished robot:
Watch it in action!
-
Arduino Uno (The Brain): The microcontroller that runs the code. It processes data from the ultrasonic sensor and sends commands to the motor driver to control the robot's movement.
-
L293D Motor Driver Shield (The Muscle): An interface between the Arduino and the motors. Because the Arduino's pins cannot provide enough current to run the motors directly, the shield handles the high-power switching required. When placed on the Arduino, its input pins (
ENA,IN1,IN2, etc.) connect to the Arduino's digital pins to control the motors' direction and speed. -
TT Gear Motors (The Legs): These motors are responsible for propelling the robot's four wheels based on the signals received from the motor driver shield.
-
HC-SR04 Ultrasonic Sensor (The Eyes): This sensor detects obstacles. It sends out an ultrasonic pulse from its
Trigpin and listens for the echo on itsEchopin. The time taken for the echo to return is used to calculate the distance to an object. -
Servo Motor (The Neck): This motor rotates the ultrasonic sensor, allowing the robot to scan its surroundings (left, right, and center) for a wider field of view instead of just looking straight ahead.
-
DC Power Switch (The Master Control): Connected in series with the battery, this switch allows you to conveniently turn the power on and off, controlling the entire robot's power supply.
Please Note: The initial version of the code in this repository was adapted from a public tutorial on YouTube for an obstacle-avoiding robot project that I followed several years ago.
Unfortunately, I no longer have the link to the specific video or creator. I am sharing this project as a record of my learning process. My intention is to refactor, modify, and build upon this base code to add my own unique features.
If you recognize this code or know the original source, please let me know so I can provide proper attribution.



