Prod_v3 is the final version of the project. This project runs a robot navigation state machine on an Arduino. The robot connects to WiFi, opens a WebSocket connection to a server, and then drives based on its navigation mode.
It supports:
- Solo navigation: follow colored lanes and execute a fixed route
- Joint navigation: two robots coordinate progress through server messages
- Go Beyond: live remote control via WebSocket commands (FORWARD, LEFT, HONK, etc.)
- Calibration menu: tune thresholds and timings over WebSocket before starting
The sketch also prints useful debug info over Serial, including raw WebSocket messages and extracted payloads.
- Arduino with WiFiNINA support (example: Nano 33 IoT)
- Motor driver (H bridge) + 2 DC motors
- IR distance sensor on A2
- Color sensing setup:
- Red LED + Blue LED illumination
- Analog read on A1
- Optional buzzer on pwnPin for horn
- Arduino IDE
- Libraries:
- WiFiNINA
- ArduinoHttpClient
- WebSocketClient
- A WebSocket server (local Docker server or class server)
Important pins referenced in the sketch:
- IR sensor:
A2 - Color sensor read:
A1 - Color LEDs:
RED_LED=1BLUE_LED=2
- Motor driver PWM:
inputTriangle4(right forward)inputTriangle3(right backward)inputTriangle1(left forward)inputTriangle2(left backward)
- Motor enables:
triangle_34_entriangle_12_en
- Horn (buzzer):
pwnPin(pin 11) - Status or ack output: pin
12
Update the WiFi credentials near the top of the sketch:
const char* SSID = "";
const char* PASS = "";Configure the WebSocket target:
const char* WS_HOST = "";
const int WS_PORT = 8080;
const char* WS_PATH = "/";The robot identifies itself with:
String CLIENT_ID = "";Most outbound messages are sent as:
CLIENT_ID | payload
Incoming messages get cleaned by extractPayload() so the logic typically compares against simple payload strings like:
- IR
- SPEED
- TYPE
- PIVOT
- START
- STOP
- FORWARD
- BACKWARD
- LEFT
- RIGHT
- HONK
Example command:
docker run -p 8080:8080 gabrielsessions/ee31-serverThen set WS_HOST to your computer’s LAN IP (same WiFi network as the Arduino).
Do not use localhost or 127.0.0.1 because the Arduino is a different device.
The sketch includes a commented example for a class server. Swap the WS_HOST and WS_PORT constants if needed.
- Open Arduino IDE
- Install libraries:
- WiFiNINA
- ArduinoHttpClient
- WebSocketClient
- Select your board and port
- Upload the sketch
- Open Serial Monitor at 9600 baud to view debug output
After connecting, the robot enters a WebSocket driven calibration menu.
Menu prompt options:
- IR sets
IR_LIMIT - SPEED sets
NAV_SPEED - TYPE sets
NAV_TYPE - PIVOT sets
pivot_delay_90 - START exits calibration and begins navigation
Each calibration command opens a small loop that accepts:
- a numeric value
- CANCEL to keep the current setting
NAV_TYPE selects the main behavior:
| NAV_TYPE | Mode |
|---|---|
| 1 or 2 | Solo navigation (solo_nav) |
| 3 or 4 | Joint navigation (joint_nav) |
| 5 | Go Beyond remote control (gobeyond) |
| 9 | Milestone demo (milestone_demo) |
Solo navigation executes a route using:
Drives forward until it reaches a wall (which is known based on the IR sensor readings).
Drives forward until the color classifier returns targetColor.
Attempts to follow a colored lane and stops it reaches a wall.
Turning is controlled by pivot_delay_90, which you can tune via the calibration menu.
Joint navigation coordinates Bot 1 and Bot 2 through server messages.
Signals used:
- Bot 1 sends:
B1:START,B1:AT_RED,B1:ACK_AT_BLUE,B1:HOME - Bot 2 sends:
B2:START,B2:AT_BLUE,B2:HOME
Each bot waits for the other’s milestone message before proceeding.
Important: both robots must connect to the same WebSocket server and use the same message conventions.
Go Beyond mode continuously reads WebSocket messages and maps keywords to motion.
Recognized keywords:
- FORWARD
- BACKWARD
- LEFT
- RIGHT
- HONK
- STOP (exits Go Beyond mode)
If no recognized movement keyword is present, the robot defaults to stop.
The sketch maps colors as:
- 0 = red
- 1 = blue
- 2 = yellow
- 3 = black
Color classification happens in findColor() using red and blue readings gathered while toggling the LEDs.
Thresholds are currently hardcoded, so lighting and sensor placement matter a lot.
The control loop is basically:
- Connect to WiFi
- Connect to WebSocket
- Run calibration menu (WebSocket input)
- Run selected navigation mode
- Stop and print DONE
During motion routines, WebSocket messages are also polled so the robot can give and recieve signals.
- Confirm
WS_HOSTis reachable from the Arduino’s network - If running locally,
WS_HOSTmust be your laptop LAN IP, not localhost - Confirm the server is listening on the correct port
- Lighting changes will shift thresholds
- Adjust the hardcoded thresholds in
findColor() - Reposition LEDs, sensor distance, and sensor angle for cleaner separation
- Tune
pivot_delay_90using the calibration menu - Battery level and surface friction can change turn timing a lot