A fully autonomous 2-wheeled robot built with an Arduino UNO and the L293D Motor Shield. This robot uses an ultrasonic sensor mounted on a servo motor to navigate through environments, backing up when it gets stuck and scanning for the best path forward.
- Microcontroller: Arduino UNO
- Motor Driver: L293D Motor Driver Shield
- Motors:
- 2x DC Gear Motors (connected to M1 and M3)
- 1x SG90 Servo Motor (connected to SER1 / Pin 10)
- Sensor: HC-SR04 Ultrasonic Sensor (Trig: A0, Echo: A1)
- Power: 3x 18650 Li-ion Batteries (~11.1V - 12.6V)
The L293D Shield simplifies wiring. Ensure connections match the following:
| Component | Shield Terminal / Pin | Description |
|---|---|---|
| Left Motor | M1 | Drive motor |
| Right Motor | M3 | Drive motor |
| Servo Motor | SER1 (Pin 10) | Pan motor for sensor |
| Ultrasonic Trigger | A0 | Trigger pulse |
| Ultrasonic Echo | A1 | Echo return |
| Battery (+) | M+ | External power input |
| Battery (-) | GND | Common ground |
IMPORTANT: Remove the PWR Jumper on the shield if powering the Arduino via USB while batteries are connected to prevent damage.
The robot follows a "Scan-Decide-Act" loop:
- Drive – Move forward at constant speed
- Detect – If obstacle detected within 15cm:
- Stop and move backward for 400ms to create space
- Scan – Servo rotates sensor left and right
- Compare – Arduino compares distance readings from both sides
- Turn – Robot turns toward the most open space and resumes forward movement
- Install Adafruit Motor Shield V1 via the Arduino Library Manager
- Servo Alignment: Adjust
myServo.write()values in code if needed to ensure 180° points forward - Motor Polarity: If the robot spins in place instead of moving forward, swap the wires of one motor on the terminal block