
Components
Wiring diagram| Component | Pin | Connect To |
|---|---|---|
| 12V Input | + | Power Switch |
| 12V Input | - | GND |
| Power Switch Output | + | Arduino VIN |
| Power Switch Output | + | L298N 12V |
| Power Switch Output | + | Battery Level Indicator + |
| Power Switch Output | - | Common GND |
| Arduino Pin | Connected To |
|---|---|
| VIN | 12V |
| GND | Common GND |
| 5V | HC-SR04, IR Sensor, HC-05 |
| GND | HC-SR04, IR Sensor, HC-05, L298N |
| HC-SR04 Pin | Arduino |
|---|---|
| VCC | 5V |
| GND | GND |
| TRIG | D8 |
| ECHO | D9 |
| IR Sensor Pin | Arduino |
|---|---|
| VCC | 5V |
| GND | GND |
| OUT | D7 |
| HC-05 Pin | Arduino |
|---|---|
| EN | NC |
| VCC | 5V |
| GND | GND |
| TXD | D11 |
| RXD | D12 |
| STATE | NC |
The switch selects between Bluetooth Mode and Autonomous Mode.
| Switch Pin | Connection |
|---|---|
| Center Pin | Arduino D13 |
| One Side | GND |
| Other Side | Not Connected (Pull-up used internally) |
Arduino D13 readsLOW → Bluetooth ModeHIGH → Obstacle Avoidance Mode
Power:-
| L298N | Connection |
|---|---|
| 12V | 12V Battery |
| GND | Common GND |
| 5V | Leave as module output or connect according to jumper configuration (do not power Arduino from it unless intended) |
Control Pins:-
| L298N | Arduino |
|---|---|
| ENA | D6 |
| IN1 | D2 |
| IN2 | D3 |
| IN3 | D4 |
| IN4 | D5 |
| ENB | D10 |
Left Motor (M1)
| Motor Wire | L298N |
|---|---|
| Wire 1 | OUT1 |
| Wire 2 | OUT2 |
Right Motor (M2)
| Motor Wire | L298N |
|---|---|
| Wire 1 | OUT3 |
| Wire 2 | OUT4 |
If a motor rotates in the wrong direction, simply swap its two wires.
| Battery Indicator | Connection |
|---|---|
| + | 12V |
| - | GND |
All of these must share the same GND:
Arduino UNOL298NHC-05HC-SR04IR SensorBattery12V SupplyComplete Arduino Pin Mapping
| Arduino Pin | Connected Device |
|---|---|
| D2 | L298N IN1 |
| D3 | L298N IN2 |
| D4 | L298N IN3 |
| D5 | L298N IN4 |
| D6 | L298N ENA |
| D7 | IR Sensor OUT |
| D8 | HC-SR04 TRIG |
| D9 | HC-SR04 ECHO |
| D10 | L298N ENB |
| D11 | HC-05 TXD |
| D12 | HC-05 RXD |
| D13 | Mode Switch |
| 5V | HC-SR04, HC-05, IR Sensor |
| GND | All Modules |
| VIN | 12V Supply |
Power ON│▼Initialize Hardware│▼Check IR Sensor│┌───────────┴───────────┐│ │Unsafe Surface Safe Surface│ │▼ ▼Stop Robot Read Mode Switch│┌───────────────────┴───────────────────┐│ │Auto Mode Bluetooth Mode│ │Read Distance Wait for Commands│ │┌─────────┴─────────┐ F/B/L/R/S│ │Obstacle No Obstacle│ │▼ ▼Stop Robot Move Forward│▼Move Backward│▼Turn Right│▼Continue Navigation
Dual operation modes: Autonomous navigation and Bluetooth manual control. Obstacle avoidance: Uses an HC-SR04 ultrasonic sensor to detect obstacles within 25 cm and automatically avoid them. Manual control: Receives movement commands (F, B, L, R, S) via an HC-05 Bluetooth module. Safety mechanism: An IR sensor has the highest priority and immediately stops the robot when it detects an unsafe condition. Mode switching: A hardware switch selects between autonomous and manual modes, with a controlled stop before changing modes. Speed control: PWM outputs on the L298N enable pins regulate the left and right motor speeds independently.
Download the complete source code for this project.
Get every component for this project delivered to your door.