An autonomous 4-wheel drive explorer robot based on Arduino UNO R4 WiFi, designed to navigate through paths and mazes while detecting surrounding obstacles. The robot performs 180° radar scans via an ultrasonic sensor mounted on a servo motor and transmits real-time telemetry via Wi-Fi (Simultaneous Localization and Mapping) to an interactive Web dashboard, which reconstructs the 2D vector map of the surrounding walls.
Devices & Components

Arduino® UNO R4 WiFi

Geared Motor

IR-Sensors

4WD chassis

2 x 18650 Battery Holder With DC Jack

4 x AA Battery Holder with Jumper Header Wires

Driver L298N

Sensor Shield V5.0

4-channel infrared module

Servo SG90

HC SR04
Wiring and Hardware (3D Model -> 3D_Viewer)
Microcontroller : Arduino UNO R4 WiFi + Sensor Shield V5.0
Chassis & Motors: 4WD Chassis with 4 DC TT gear motors (yellow)
Motor Driver: H-Bridge module L298N (with jumpers inserted on `ENA` and `ENB` to deliver 100% power)
Radar Turret: HC-SR04 ultrasonic sensor mounted on an SG90 micro-servo motor
Waypoint Odometry: Module with 3 Infrared (IR) Sensors positioned under the chassis for detecting configurable checkpoints (black tape at fixed intervals on the floor)
Separate Dual Power Supply:
Logic (Arduino, Wi-Fi, Sensors, Servo): Battery pack with 2 Li-Ion 18650 cells (7.4V – 8.4V) connected to the Arduino R4 Barrel Jack.
Power (4 DC Motors): 4x AA battery holder connected to the 12V/VMS and GND terminals of the L298N driver (with shared `GND` reference with the Sensor Shield and the `+5V` line disconnected to isolate the two circuits).
Pin Map on Sensor Shield
| Component | Module Pin | Arduino Pin (Sensor Shield) | Function |
| L298N Driver | `IN1` | Pin 4 | Left Motor Direction 1 |
| L298N Driver | `IN2` | Pin 12 | Left Motor Direction 2 |
| L298N Driver | `IN3` | Pin 13 | Right Motor Direction 1 |
| L298N Driver| `IN4` | Pin 6 | Right Motor Direction 2 |
| L298N Driver | `ENA` / `ENB` | *Black Jumpers* | Permanent 100% power enable |
| SG90 Servo | VCC/GND/Signal | Column 7 | Radar turret rotation (`5°` – `175°`) |
| HC-SR04 | `TRIG` | Pin 8 | Ultrasonic trigger pulse |
| HC-SR04 | `ECHO` | Pin 9 | Ultrasonic echo return reading |
| IR Sensors | `IR_SX` (`IN1`) | Pin 2 | Left IR Sensor (black tape reading) |
| IR Sensors | `IR_CENTRO` (`IN3`) | Pin 10 | Center IR Sensor (black tape reading) |
| IR Sensors | `IR_DX` (`IN4`) | Pin 11 | Right IR Sensor (black tape reading) |


Instructions for Use
Uploading the Arduino Sketch
1 - Open the `4wd.ino` file in the Arduino IDE.
2 - Enter your Wi-Fi network name (`ssid`) and password (`password`) in the first lines of the code.
3 - Connect the Arduino R4 WiFi to your computer via USB-C cable and upload the sketch to the board.
Obtaining the IP Address from the Serial Monitor
1 - Once the upload is complete, open the Arduino IDE **Serial Monitor** and set the baud rate to **`115200 baud`**.
2 - Wait a few seconds until the Arduino connects to the Wi-Fi router.
3 - Copy the **local IP address** printed on the screen in the monitor.
4 - Disconnect the USB cable and turn on the batteries (18650 pack on Arduino + 4xAA pack on motors).
Opening the HTML Web Interface
1 - Open the `map.html` file directly in your PC/Mac browser.
(Note for Safari users on Mac: from the top menu `Develop`, enable "Disable Local File Restrictions" to allow the local page to communicate via HTTP with the robot's IP, or use Google Chrome).
2 - In the top-left bar of the web page, paste the robot's **IP address** into the text box and click **"Connect Wi-Fi"**.

Starting and Stopping Exploration
* Click the light blue **` Start`** button in the top bar to command the robot to begin scanning and autonomous path exploration.
* Click the red **` STOP`** button to instantly interrupt motor movement and pause the robot.
Operating Cycle
Navigation and Mapping Logic
The robot's operating cycle consists of 4 synchronized phases:
1 - **7-Angle Radar Scan:**
While stationary, the robot rotates the SG90 servo motor across 7 angles distributed along the entire front arc (`5°`, `35°`, `65°`, `90°`, `115°`, `145°`, `175°`). At each step, it measures the distance in centimeters using the ultrasonic sensor.
2 - **Free Navigation with Ultrasonic Emergency Brake**
The robot moves using short timed bursts in free space. During travel, ultra-fast monitoring continuously queries the HC-SR04: if a wall drops below 13 cm, the robot brakes instantly to avoid collisions.
3 - **Anti-Double-Scan Disengagement Maneuver:**
If a close front obstacle is detected, the robot reverses by `4.5 cm` (subtracting the displacement from odometry coordinates), inspects the two extremes (`5°` far right and `175°` far left), and rotates toward the freer side. To avoid redrawing the same wall twice by overlapping lines, the software inhibits sending new scans until the robot has completed a new effective forward step.
4 - **Final Target Detection**
The IR sensors passively monitor the floor. As soon as they intercept the single end-of-course black tape, the robot stops the motors, notifies completion, and transmits the target signal to the dashboard.
**Automatic Trajectory Cleaning (In-browser Ray Casting):**
The web dashboard tracks the robot's trail and automatically removes all impact points recorded within a 9 cm radius of the passage, ensuring a central space perfectly clear of phantom points or spurious artifacts, cleanly and continuously highlighting only the outer perimeter walls of the route.
`MAP` Packet Format
The web dashboard cyclically queries the HTTP endpoint `http://<ROBOT_IP>/map` (equipped with CORS header `Access-Control-Allow-Origin: *`). The robot responds with a formatted string:
counter#MAP:posX,posY,thetaAngle|ang1:dist1|ang2:dist2|ang3:dist3|ang4:dist4|ang5:dist5|ang6:dist6|ang7:dist7
Example: 1#MAP:0.0,15.0,90.0|5:14|35:20|65:44|90:57|115:37|145:17|175:160.0, 15.0, 90.0:
The robot is located at X = 0.0 cm, Y = 15.0 cm and heading 90°.5:14... 90:57... 175:16: At various servo angles (from right to left), the sonar detected side walls at 14 cm and 16 cm and the free corridor ahead at 57 cm.
The HTML interface converts each (servoAngle, distance) pair into global Cartesian coordinates using trigonometry (coscosand sinsin), drawing green impact points and connecting them with cyan vector segments.
CODE--> 4WD-SLAM-Radar-2D-Robot-Car