Hands-on robotics project that turns an Arduino UNO WiFi R3 (ATmega328P + ESP8266) into a versatile, classroom-ready robot car. The sketch powers multiple autonomous and remote-control modes, adds safety protections for edges/cliffs, and documents all wiring so you can recreate or showcase the build on LinkedIn.
- Six driving modes:
- Line follower (dual IR sensors on D4/D2).
- Obstacle avoider with ultrasonic scanning (HC-SR04 on D8/D7 plus a servo on D3).
- Combo sprint mode that prioritizes max-speed line following.
- IR-remote driving (receiver on D13 with configurable codes).
- Wi‑Fi serial control via the UNO WiFi’s shared hardware serial port.
- Bluetooth serial control (e.g., HC-05) using the same serial command set.
- Motor control: L298N H-bridge with PWM speed on D5/D6 and direction on D9–D12; helper functions handle forward, reverse, in-place turns, and a dedicated U-turn routine.
- Safety features: cliff/edge protection using the line sensors, emergency stop from the IR remote, obstacle avoidance fallback logic, and timed servo pauses for stable distance reads.
- Tunable performance: adjust default/turn speeds, max speed, servo settle delay, and obstacle thresholds at the top of the sketch.
| Component | Pin mapping |
|---|---|
| L298N ENA / ENB | D5 (PWM) / D6 (PWM) |
| L298N IN1 / IN2 | D12 / D11 |
| L298N IN3 / IN4 | D10 / D9 |
| IR line sensors | Left -> D4, Right -> D2 |
| Ultrasonic HC-SR04 | TRIG -> D8, ECHO -> D7 |
| Servo (SG90) | Signal -> D3 |
| IR receiver | Signal -> D13 |
| Wi‑Fi (ESP8266) / Bluetooth HC-05 | Hardware serial (baud selectable; sketch uses 115200 by default) |
If your wiring differs, edit the pin constants near the top of
robot_car.ino.
- IR remote
- Direction:
IR_CODE_FWD,IR_CODE_BACK,IR_CODE_LEFT,IR_CODE_RIGHT,IR_CODE_STOP(replace with your remote’s codes). - Modes: buttons mapped to
IR_CODE_MODE_LINE/OBSTACLE/COMBO/IR/WIFI/BTplus combo-onlyIR_CODE_COMBO_STOPandIR_CODE_COMBO_UTURNfor a quick escape.
- Direction:
- Serial (Wi‑Fi or Bluetooth)
- Movement:
F,B,L,R,S(stop),U(U-turn + resume forward). - Modes:
1line follower,2obstacle avoider,3combo sprint,4IR driving,5Wi‑Fi serial,6Bluetooth serial. - Speed: digits
0–9map to PWM100–255.
- Movement:
- Line follower: stays centered on the track; slows to turn when a single sensor sees the line and creeps forward when both lose it.
- Obstacle avoider: checks distance every 100 ms; backs up and turns toward the clearer side when an object is within the threshold (15 cm by default).
- Combo sprint: drives at
MAX_SPEEDon the line for showcase laps; intentionally ignores obstacle/cliff logic unless you hit the emergency stop. - IR driving: IR codes set movement instantly; emergency stop halts any mode.
- Wi‑Fi/Bluetooth: processes the same serial commands as above so you can drive from a phone app or serial console.
- Open
robot_car.inoin the Arduino IDE. - Select Arduino UNO WiFi and set the serial monitor to 115200 baud (match
SERIAL_DEBUG_BAUD). - Install libraries via Library Manager: Servo and IRremote 4.x.
- Upload. On boot you’ll see
Robot car startingin the serial monitor.
- Adjust
DEFAULT_SPEED,TURN_SPEED, andOBSTACLE_THRESHOLD_CMto fit your motor torque and sensor noise. - If the servo horn is off-center, change the initial
moveServoAndWait(90);call insetup()to your neutral angle. - Increase
SCAN_DELAY_MSif ultrasonic readings seem unstable during scans. - Customize IR codes (
IR_CODE_*constants) with values captured via theIRrecvDumpexample so your remote matches.