Skip to content

jpizzzel/Junior-Design-Project

Repository files navigation

EE31 Final Project

Prod_v3 is the final version and holds: Solo Nav • Joint Nav • Calibration • Go Beyond


Overview

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.


What You Need

Hardware

  • 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

Software

  • Arduino IDE
  • Libraries:
    • WiFiNINA
    • ArduinoHttpClient
    • WebSocketClient
  • A WebSocket server (local Docker server or class server)

Pin Map

Important pins referenced in the sketch:

  • IR sensor: A2
  • Color sensor read: A1
  • Color LEDs:
    • RED_LED = 1
    • BLUE_LED = 2
  • Motor driver PWM:
    • inputTriangle4 (right forward)
    • inputTriangle3 (right backward)
    • inputTriangle1 (left forward)
    • inputTriangle2 (left backward)
  • Motor enables:
    • triangle_34_en
    • triangle_12_en
  • Horn (buzzer): pwnPin (pin 11)
  • Status or ack output: pin 12

WiFi Setup

Update the WiFi credentials near the top of the sketch:

const char* SSID = "";
const char* PASS = "";

WebSocket Setup

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 = "";

Message Format

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

Running the WebSocket Server

Option A: Local server via Docker

Example command:

docker run -p 8080:8080 gabrielsessions/ee31-server

Then 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.

Option B: Class server

The sketch includes a commented example for a class server. Swap the WS_HOST and WS_PORT constants if needed.


Build and Upload

  1. Open Arduino IDE
  2. Install libraries:
    • WiFiNINA
    • ArduinoHttpClient
    • WebSocketClient
  3. Select your board and port
  4. Upload the sketch
  5. Open Serial Monitor at 9600 baud to view debug output

Calibration Menu

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

Navigation Modes

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

Solo navigation executes a route using:

goForwardUntilWall()

Drives forward until it reaches a wall (which is known based on the IR sensor readings).

goForwardUntilColor(targetColor)

Drives forward until the color classifier returns targetColor.

followColorUntilWall(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 (Two Robots)

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 (Remote Control)

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.


Color Codes

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.


How It Works (High Level)

The control loop is basically:

  1. Connect to WiFi
  2. Connect to WebSocket
  3. Run calibration menu (WebSocket input)
  4. Run selected navigation mode
  5. Stop and print DONE

During motion routines, WebSocket messages are also polled so the robot can give and recieve signals.


Troubleshooting

WebSocket will not connect

  • Confirm WS_HOST is reachable from the Arduino’s network
  • If running locally, WS_HOST must be your laptop LAN IP, not localhost
  • Confirm the server is listening on the correct port

Color detection is unstable

  • Lighting changes will shift thresholds
  • Adjust the hardcoded thresholds in findColor()
  • Reposition LEDs, sensor distance, and sensor angle for cleaner separation

Turns are inaccurate

  • Tune pivot_delay_90 using the calibration menu
  • Battery level and surface friction can change turn timing a lot
Made for EE31, By: Paul, Michael, Jonah, and Daniel

About

EE31 Junior Design Project

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages