IoT Smart Mobile Robot (Raspberry Pi) - Complete IoT system with telemetry, autonomous navigation, and Flask web application for remote monitoring and control.
Our robot follows a black line using IR sensors, avoids objects in its path with an ultrasonic sensor, and sends all its live data to a cloud dashboard on Adafruit IO.
Organized codebase with modular structure: hardware interfaces, server modules, telemetry utilities, Flask web app, and database sync.
- Mir Faiyazur Rahman โ Software + Testing
- Aarush Patel โ Hardware + Testing
- Course: 420-N55: IoT - Design and Prototyping of Connected Devices
- Institution: Champlain College Saint-Lambert
- Semester: Fall 2025
| Resource | Link |
|---|---|
| Flask Web App | https://swiftrover.onrender.com |
| Adafruit IO Dashboard | https://io.adafruit.com/AarushP06/feeds |
| Neon.com Database | https://console.neon.tech |
| Video Demo | https://www.youtube.com/shorts/C6nwZ4KSzSc |
YouTube: https://www.youtube.com/shorts/C6nwZ4KSzSc
For this project, we successfully built a robot that meets the core requirements. What worked really well was our modular command_listener.py script, which handles all the sensor readings and motor controls in one place. Using a config.json file was also a good decision, as it kept our API keys and pins out of the main code.
The most difficult part was calibrating the line-following algorithm to work consistently across different lighting conditions. We spent a lot of time adjusting PID parameters and motor speeds to find the right balance. Another challenge was setting up the MQTT telemetry system to reliably publish sensor data without exceeding Adafruit IO's rate limits.
If we had more time, we would improve the line-following algorithm with better PID tuning and add more sophisticated obstacle avoidance.
- Raspberry Pi 4B or Pi 5
- Freenove 4WD Robot Car Kit
- HC-SR04 Ultrasonic Sensor (Sensor 1)
- 3-Channel IR Line Sensors (Sensor 2)
- Raspberry Pi Camera Module (Sensor 3 - optional)
- Pan/Tilt Servo Mount
- WS281X LED Strip (optional)
- Buzzer (optional)
- Raspberry Pi OS (64-bit)
- Python 3.9+
- Git
# Update system
sudo apt update && sudo apt upgrade -y
# Install required system packages
sudo apt install -y \
python3-venv \
python3-pip \
python3-smbus \
python3-spidev \
python3-rpi.gpio \
python3-opencv \
git
# Enable interfaces (run raspi-config if needed)
sudo raspi-config
# Enable: SPI, I2C, Camera (if needed)cd ~
git clone https://github.com/AarushP06/SwiftRover.git
cd SwiftRover# Create virtual environment
python3 -m venv .venv
# Activate virtual environment
source .venv/bin/activate
# Upgrade pip
pip install --upgrade pip
# Install Python dependencies
pip install -r requirements.txt
# Install additional hardware packages
pip install smbus smbus2 spidev RPi.GPIO numpy opencv-python# Create config from sample
cp config/adafruit.sample.json config/adafruit.json
# Edit with your credentials
nano config/adafruit.jsonFill in your Adafruit IO credentials:
{
"adafruit": {
"username": "YOUR_AIO_USERNAME",
"key": "YOUR_AIO_KEY",
"feeds": {
"ultrasonic_cm": "ultra-distance",
"ir_left": "line-ir-left",
"ir_center": "line-ir-center",
"ir_right": "line-ir-right",
"line_state": "line-state",
"camera_status": "cam-status",
"camera_thumb": "cam-thumb",
"motor_control": "motor-control",
"led_control": "led-control",
"buzzer_control": "buzzer-control",
"line_tracking": "line-tracking",
"obstacle_avoidance": "obstacle-avoidance"
}
},
"capturing_interval": 5,
"flushing_interval": 10,
"sync_interval": 300
}export DATABASE_URL="postgresql://user:password@host/database?sslmode=require"cd ~/SwiftRover
source .venv/bin/activate
python3 src/command_listener.pyNote: Run telemetry with system Python (outside venv) for camera support:
cd ~/SwiftRover
# Make sure you're NOT in venv (deactivate if needed)
deactivate 2>/dev/null || true
export DATABASE_URL="your_neon_database_url"
cd src/telemetry
python3 telemetry_runner.pyWhy outside venv? The camera requires python3-libcamera (system package) which is only accessible outside the virtual environment. Command listener can run in venv, but telemetry needs system Python for camera support.
cd ~/SwiftRover/src
python3 car_tui.pyControls:
W/S/A/D- Forward/Backward/Left/RightSPACE- StopL/K- Start/Stop Line TrackingO/P- Start/Stop Obstacle AvoidanceU- Toggle UltrasonicT- Toggle LEDsB- BuzzerQ- Quit
paho-mqtt>=1.6,<3.0
python-dateutil>=2.8.0
gpiozero>=1.6.0
Flask>=3.0.0
requests>=2.31.0
psycopg2-binary>=2.9.0
numpy>=1.24.0
# Install via apt
sudo apt install python3-smbus python3-spidev python3-rpi.gpio
# Or via pip (in venv)
pip install smbus smbus2 spidev RPi.GPIO- Dashboard: Real-time sensor data display with live camera feed
- Sensor Data: Historical data charts with date selection
- Control Car: Motor controls (Forward, Backward, Left, Right, Stop)
- Line Tracking: Start/Stop autonomous line following
- Obstacle Avoidance: Start/Stop autonomous navigation
- Device Control: LED and Buzzer on/off
- Camera Feed: Live camera thumbnail display (Sensor 3) with click-to-zoom
pip install Flask requests psycopg2-binary
python app.py
# Access at http://localhost:5000- Push code to GitHub
- Create Web Service on Render.com
- Set environment variables:
AIO_USERNAME- Adafruit IO usernameAIO_KEY- Adafruit IO keyAIO_FEEDS- JSON string of feed mappingsDATABASE_URL- Neon.com PostgreSQL URL
See RENDER_DEPLOYMENT.md for detailed deployment instructions.
Sensor 1: Ultrasonic Distance
| Feed Name | Description | Values |
|---|---|---|
ultra-distance |
Ultrasonic distance | 0-400 cm |
Sensor 2: Infrared Line Sensors
| Feed Name | Description | Values |
|---|---|---|
line-ir-left |
IR Left sensor | 0 or 1 |
line-ir-center |
IR Center sensor | 0 or 1 |
line-ir-right |
IR Right sensor | 0 or 1 |
line-state |
Combined line state | L, M, R, LM, etc. |
Sensor 3: Camera Feed
| Feed Name | Description | Values |
|---|---|---|
cam-motion |
Camera thumbnail (base64 image) | JPEG image data (base64 encoded) |
cam-status |
Camera status | online/offline |
Note: The cam-motion feed contains the camera thumbnail as a base64-encoded JPEG image. The Flask web application automatically detects and displays this as a live camera feed on the dashboard.
| Feed Name | Description | Commands |
|---|---|---|
motor-control |
Motor commands | forward, backward, left, right, stop |
led-control |
LED commands | on, off |
buzzer-control |
Buzzer commands | on, off |
line-tracking |
Line tracking | start, stop |
obstacle-avoidance |
Obstacle avoidance | start, stop |
- Create account at https://neon.tech
- Create new project
- Copy connection string
- Set as environment variable:
export DATABASE_URL="postgresql://user:pass@host/db?sslmode=require"CREATE TABLE sensor_data (
id SERIAL PRIMARY KEY,
timestamp TIMESTAMP,
ultrasonic_cm REAL,
ir_left INTEGER,
ir_center INTEGER,
ir_right INTEGER,
line_state TEXT
);SwiftRover/
โโโ app.py # Flask web application
โโโ requirements.txt # Python dependencies
โโโ config/
โ โโโ adafruit.sample.json # Config template
โ โโโ adafruit.json # Your config (git-ignored)
โ โโโ neon.sample.json # Neon DB config template
โ โโโ neon.json # Neon DB config (git-ignored)
โโโ templates/ # Flask HTML templates
โ โโโ base.html
โ โโโ home.html
โ โโโ about.html
โ โโโ sensor_data.html
โ โโโ control_car.html
โ โโโ line_tracking.html
โ โโโ obstacle_avoidance.html
โโโ static/
โ โโโ css/style.css # Custom styling
โ โโโ js/main.js
โโโ src/
โ โโโ hardware/ # Hardware drivers
โ โ โโโ motor.py
โ โ โโโ ultrasonic.py
โ โ โโโ infrared.py
โ โ โโโ servo.py
โ โ โโโ buzzer.py
โ โ โโโ led.py
โ โ โโโ camera.py
โ โ โโโ spi_ledpixel.py
โ โโโ telemetry/ # Telemetry modules
โ โ โโโ telemetry.py
โ โ โโโ telemetry_runner.py
โ โ โโโ telemetry_daemon.py
โ โ โโโ ultra_cache_writer.py
โ โโโ command_listener.py # MQTT command receiver
โ โโโ line_follow.py # Line tracking algorithm
โ โโโ obstacle_navigator.py # Obstacle avoidance
โ โโโ car_tui.py # Terminal UI
โ โโโ database_sync.py # DB sync module
โโโ scripts/ # Shell scripts
โ โโโ run_telemetry.sh
โ โโโ tail_today.sh
โโโ db/ # Local SQLite (git-ignored)
# Kill any Python processes using GPIO
sudo pkill -9 python
sudo pkill -9 python3
# Reset GPIO
python3 -c "import RPi.GPIO as GPIO; GPIO.setwarnings(False); GPIO.setmode(GPIO.BCM); GPIO.cleanup()"# Ensure venv is activated
source .venv/bin/activate
# Reinstall dependencies
pip install -r requirements.txt
pip install smbus smbus2 spidev RPi.GPIO numpy- Check Adafruit IO key is valid
- Check internet connection
- Verify config/adafruit.json has correct credentials
- Verify DATABASE_URL is correct
- Check Neon.com project is active
- Ensure
.c-2is in hostname (pooler URL)
- Verify IR sensors are properly connected
- Check sensor readings in debug mode
- Adjust
--invert-steerand--invert-driveflags if needed - See
DEVELOPMENT_LOG.mdfor known issues and fixes
- Ensure ultrasonic sensor is properly mounted
- Check pan/tilt servos are calibrated
- Verify sensor readings in debug output
This project was created for educational purposes at Champlain College Saint-Lambert.
SwiftRover - IoT Smart Robot Car ยฉ 2025