Examples
This page provides complete, ready-to-use sketches for common Autobot configurations. Each example demonstrates a different drive type and feature set.
Installation
- Download
AutOBot Library. - Place the file in your Arduino project folder.
- Include it at the top of your sketch:
#include "AutOBot.h" // if you want to use the library without AI
#include "AutOBotAI.h" // if you want to use the library with AI
Differential Drive (2-Wheel)
Differential With Raspberry Pi
#include <AutOBot.h>
#include <AutOBotAI.h>
AutOBot myBot;
AutOBotAI myAI;
void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, myAI.rx, myAI.tx); // RX, TX for AI comms
myBot.begin(DRIVE_DIFFERENTIAL, 0);
myAI.begin(Serial, myBot);
}
void loop() {
myAI.handle();
}
Differential Without Raspberry Pi
A minimal sketch that drives the robot forward without any AI features.
#include <AutOBot.h>
AutOBot myBot;
void setup() {
myBot.begin(DRIVE_DIFFERENTIAL, 0);
}
void loop() {
myBot.drive(0, 100, 0);
}
Mecanum Drive (4-Wheel)
Mecanum With Raspberry Pi
#include <AutOBot.h>
#include <AutOBotAI.h>
AutOBot myBot;
AutOBotAI myAI;
void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, myAI.rx, myAI.tx); // RX, TX for AI comms
myBot.begin(DRIVE_MECANUM, 0);
myAI.begin(Serial, myBot);
myAI.requestHuman(50, 0.5, 30000, 5000);
}
void loop() {
myAI.handle();
}
Timed AI Sequence
This example demonstrates how to chain multiple AI modes using timers:
- Phase 1 — Follow a human for 10 seconds.
- Phase 2 — Follow a line for 15 seconds.
- Phase 3 — Stop.
#include <AutOBot.h>
#include <AutOBotAI.h>
AutOBot myBot;
AutOBotAI myAI;
unsigned long startTime;
bool phaseLineStarted = false;
bool phaseStopStarted = false;
void setup() {
Serial.begin(115200);
Serial.println("ESP32 Ready (AutOBot Mode)");
Serial2.begin(115200, SERIAL_8N1, myAI.rx, myAI.tx);
myBot.begin(DRIVE_MECANUM, 0);
// Bind AI module with Serial2 and robot
myAI.begin(Serial2, myBot);
// ── Phase 1: Human Tracking (10s) ────────────
Serial.println("PHASE 1: Human Tracking (10s)");
myAI.requestHuman(30, 0.6, 30000, 5000);
startTime = millis();
}
void loop() {
// Always process incoming AI data
myAI.handle();
unsigned long elapsed = millis() - startTime;
// ── After 10s → Line Tracking ───────────────
if (!phaseLineStarted && elapsed > 10000) {
Serial.println("PHASE 2: Line Tracking (15s)");
myAI.requestLine(30, 0.8, 100, "black", 0, 0, 0);
phaseLineStarted = true;
}
// ── After 25s → Stop ────────────────────────
if (!phaseStopStarted && elapsed > 25000) {
Serial.println("PHASE 3: Sequence complete. Stopping.");
myAI.requestStop();
phaseStopStarted = true;
}
}
Mecanum Without Raspberry Pi
A minimal Mecanum sketch that drives the robot forward without AI.
#include <AutOBot.h>
AutOBot myBot;
void setup() {
myBot.begin(DRIVE_MECANUM, 0);
}
void loop() {
myBot.drive(0, 100, 0);
}
AI Mode Quick Reference
You can call these functions anywhere in your loop() — inside if, else, while, timers, or conditional blocks.
Line Tracking
myAI.requestLine(30, 0.8, 100, "black");
The robot will begin following a line. See the API Reference for full parameter details.
Human Tracking
myAI.requestHuman(30, 0.6, 30000, 5000);
The robot will begin following a detected human. See the API Reference for full parameter details.