# Hardware Architecture

KLNavBot is built as a compact differential-drive robot with a cloud-connected control core.

## Hardware Stack

| Component | Role | Notes |
| --- | --- | --- |
| ESP32 | Main controller | Handles WiFi, control logic, sensor polling, and Firebase communication |
| NEO-6M GPS | Position tracking | Streams NMEA data to the ESP32 over UART1 |
| HC-SR04 | Obstacle detection | Stops the robot when an object is within the configured threshold |
| L298N | Motor driver | Drives left and right DC motors with PWM speed control |
| MPU6050 | IMU expansion path | Recommended for heading stabilization and dead-reckoning fusion |
| WiFi router / hotspot | Network link | Connects robot telemetry to Firebase and the dashboard |

## Wiring Map

| Function | ESP32 Pin |
| --- | --- |
| GPS TX | GPIO 17 |
| GPS RX | GPIO 16 |
| Ultrasonic TRIG | GPIO 19 |
| Ultrasonic ECHO | GPIO 18 |
| Left motor IN1 | GPIO 25 |
| Left motor IN2 | GPIO 26 |
| Left motor ENA | GPIO 27 |
| Right motor IN3 | GPIO 32 |
| Right motor IN4 | GPIO 33 |
| Right motor ENB | GPIO 14 |

## Physical Architecture

```mermaid
flowchart TB
    Battery[Battery Pack] --> ESP32[ESP32]
    Battery --> MotorDriver[L298N]
    ESP32 --> GPS[NEO-6M GPS]
    ESP32 --> Ultrasonic[HC-SR04]
    ESP32 --> MotorDriver
    MotorDriver --> LeftMotor[Left DC Motor]
    MotorDriver --> RightMotor[Right DC Motor]
    ESP32 <--> WiFi[WiFi / Firebase]
```

## Hardware Behavior

- The ESP32 continuously checks the ultrasonic sensor before accepting movement commands.
- Motor power is cut immediately when the obstacle threshold is crossed.
- GPS readings are pushed to Firebase at a lower rate than obstacle checks to conserve bandwidth.
- The wiring keeps sensing and actuation separate enough to make the platform easy to expand with an MPU6050, battery monitor, or encoder inputs.
