Building a $12 Multi-Robot Swarm: ESP32 BLE Mesh for STEAM Education in Emerging Markets
Building a $12 Multi-Robot Swarm: ESP32 BLE Mesh for STEAM Education in Emerging Markets What if a classroom of 30 kids could each control a robot in a coordinated swarm - for less than the cost of a single LEGO Mindstorms kit? At LearnOBots, we've been teaching robotics to kids across Pakistan since 2014. One question never goes away: "How do we make this affordable enough for every child?" The answer might be hiding in a $4 chip already sitting on our workbenches - the ESP32 - and a protocol most educators have never heard of: Bluetooth Mesh. This article is a practical, tested guide to building multi-robot swarms using ESP32 BLE mesh networking, designed specifically for classrooms in Pakistan and other emerging markets where budget constraints make traditional robotics platforms impossible. Why Swarm Robotics Matters for STEAM Education Traditional robotics education follows a pattern: one expensive kit per team of 4-5 students, one robot at a time, limited curriculum depth. It teaches individual robot programming but misses something fundamental about modern robotics - robots increasingly work together, not alone. Swarm robotics - where multiple robots coordinate to achieve shared goals - mirrors what students see in nature (ant colonies, flocking birds) and in real-world applications (warehouse robots, agricultural monitoring fleets, search-and-rescue drones). Teaching swarm concepts develops: - Distributed thinking - understanding systems where no single agent has full control - Network awareness - how messages propagate, degrade, and recover - Emergent behavior - how simple local rules produce complex group outcomes - Fault tolerance - what happens when one node fails These are the skills our students at LearnOBots will need in a world where autonomous systems increasingly operate in coordinated fleets, not isolation. The Hardware: ESP32 as a Swarm Node Why ESP32 (Not Raspberry Pi or Arduino) | Factor | ESP32 | Arduino Uno | Raspberry Pi Zero | |---|---|---|---| | Cost (PKR) | ~1,100 ($4) | ~2,500 ($9) | ~6,000 ($22) | | Built-in wireless | Wi-Fi + BLE | None | Wi-Fi only | | Power draw | ~40mA active | ~15mA | ~150mA | | Mesh support | BLE Mesh native | No | No | | PWM channels | 16 | 6 | Hardware-dependent | The ESP32's built-in BLE radio is the game-changer. Unlike Arduino (no wireless) or Raspberry Pi (power-hungry, no BLE mesh stack), the ESP32 supports Bluetooth Mesh networking natively through Espressif's ESP-BLE-MESH implementation in ESP-IDF. This means: no extra modules, no shields, no wires between robots. Each robot is a self-contained node in a mesh network, relaying messages for other robots automatically. Bill of Materials (Per Robot) - ESP32 DevKit - PKR 1,100 ($4) - [OLX Pakistan or local electronics markets] - L298N motor driver - PKR 350 ($1.30) - controls two DC motors - 2ร geared DC motors + wheels - PKR 600 ($2.20) - surplus from old toys or local vendors - 3.7V 18650 Li-ion battery - PKR 250 ($0.90) - recycled from old laptop batteries - Chassis (3D printed or laser-cut) - PKR 200 ($0.75) - or repurpose cardboard - Ultrasonic sensor (HC-SR04) - PKR 150 ($0.55) - for obstacle avoidance - Jumper wires + misc - PKR 100 ($0.40) Total per robot: ~PKR 2,750 ($10.10) A class set of 10 robots: PKR 27,500 (~$101). Compare that to a single LEGO Mindstorms EV3 kit at PKR 65,000 ($240). You get 10 swarm-capable robots for less than half the price of one kit that only builds one robot at a time. The Protocol: BLE Mesh vs ESP-NOW Espressif offers two wireless approaches for multi-robot communication. I've tested both in classroom settings - here's what we learned. BLE Mesh (ESP-BLE-MESH) Bluetooth Mesh is a formal standard (Bluetooth SIG). It creates a true many-to-many network where every node can relay messages. Key properties: - Managed flooding - messages propagate through the network via relay nodes; no routing tables needed - Up to 32,767 nodes per network (theoretical; we've tested up to 12 reliably) - Message reliability - built-in retransmission and acknowledgment - Model-based architecture - Generic OnOff, Sensor, Vendor models for custom data - Low power - relay nodes consume only marginally more power Best for: Structured classroom activities where you need reliable message delivery, group coordination, and formal network topology lessons. ESP-NOW ESP-NOW is Espressif's proprietary connectionless protocol. It's simpler and faster: - Direct peer-to-peer - no mesh relay, direct device-to-device - Maximum 20 encrypted peers per device (250 total with broadcast) - Ultra-low latency - sub-millisecond - No router needed - direct 802.11 frames - Simpler code - esp_now_send() with a MAC address Best for: Fast, simple activities where robots are within direct range and you want minimal setup overhead. Our Recommendation for Classrooms Start with ESP-NOW for the first few sessions - it's simpler to set up and lets students see results quickly. Move to BLE Mesh when you want to teach network topology, message relay, and multi-hop communication. The progression itself is a lesson: "Why do we need mesh? What happens when Robot C is between Robot A and Robot B and they can't hear each other directly?" Building the Swarm: A Classroom-Tested Architecture Network Topology Teacher Controller (Mobile/ESP32) | โโโ Robot 1 (Node 0x0001) | โโโ Relay to Robot 3 | โโโ Robot 2 (Node 0x0002) | โโโ Relay to Robot 4, Robot 5 | โโโ Robot 3 (Node 0x0003) โโโ Relay to Robot 6 In BLE Mesh, any node can be configured as a relay node (forwards messages for others) or a low-power node (sleeps, only wakes to check messages). For classrooms, make all robots relay nodes - it teaches the concept without the complexity of power management. Firmware Architecture Each robot runs the same firmware with a role byte that determines behavior: // swarm_robot.c - Core structure for each node #include "esp_ble_mesh_defs.h" #include "esp_ble_mesh_networking.h" #define ROLE_FOLLOWER 0x01 #define ROLE_LEADER 0x02 #define ROLE_RELAY_ONLY 0x03 typedef struct { uint8_t node_id; // Unique per robot uint8_t role; // Follower, Leader, Relay uint16_t target_x; // Target position (cm from origin) uint16_t target_y; int16_t current_speed; // -255 to 255 uint8_t battery_pct; // For power awareness lessons uint8_t neighbors; // Bitmask of known peers } swarm_node_t; // Vendor model opcode for swarm commands #define SWARM_CMD_SET_TARGET 0xC0 #define SWARM_CMD_REPORT_POS 0xC1 #define SWARM_CMD_EMERGENCY_STOP 0xC2 // Each robot processes incoming mesh messages static void handle_swarm_command(esp_ble_mesh_model_t model, uint32_t opcode, void payload) { switch (opcode) { case SWARM_CMD_SET_TARGET: update_target((uint16_t)payload, (uint16_t)(payload + 2)); break; case SWARM_CMD_EMERGENCY_STOP: motor_brake(); led_pulse_red(); break; case SWARM_CMD_REPORT_POS: broadcast_position(); break; } } The Teacher's Controller The teacher (or a student acting as "swarm commander") sends commands from an ESP32 with a simple joystick or rotary encoder: # teacher_controller.py - Runs on teacher's ESP32 or Python-capable device import struct import bluetooth_mesh # Hypothetical Python BLE Mesh binding class SwarmController: def init(self, network_key, app_key): self.mesh = bluetooth_mesh.Mesh(network_key, app_key) def set_formation(self, node_ids, formation_type): """Send formation commands to all robots""" positions = self.calculate_formation(formation_type, len(node_ids)) for node_id, pos in zip(node_ids, positions): msg = struct.pack('<BHH', node_id, pos[0], pos[1]) self.mesh.send(SWARM_CMD_SET_TARGET, msg) def calculate_formation(self, formation_type, n_robots): """Return list of (x, y) positions in cm""" if formation_type == "circle": radius = 50 # 50cm radius return [(int(radius * math.cos(2pii/n)), int(radius * math.sin(2pii/n))) for i in range(n_robots)] elif formation_type == "line": spacing = 20 # 20cm between robots return [(-spacing*(n-1)/2 + spacing*i, 0) for i in range(n_robots)] elif formation_type == "grid": cols = int(math.ceil(math.sqrt(n_robots))) return [((i % cols) * 25, (i // cols) * 25) for i in range(n_robots)] Three Classroom Activities (Tested with LearnOBots Students) Activity 1: "Follow the Leader" (Ages 10-12) Concept: One robot leads, others follow at a fixed distance using ultrasonic sensors. Setup: Program one robot as LEADER (drives a preset path), others as FOLLOWERS (maintain 20cm distance using HC-SR04). No mesh needed - just direct sensor following. Lesson: Basic feedback control, sensor calibration, the idea of autonomous behavior. What students learn: Why does the follower sometimes crash into the leader? (Sensor lag.) Why does the train of followers "accordion" when the leader stops? (Each follower responds with a delay.) This naturally introduces control theory without calling it that. Activity 2: "Swarm Foraging" (Ages 13-15) Concept: Robots search a designated area for "food" tokens (colored objects) and bring them to a home base. Multiple robots must coordinate to not visit the same area. Setup: Use BLE Mesh. Each robot broadcasts its current grid position every 2 seconds via SWARM_CMD_REPORT_POS . When a robot finds a token, it broadcasts a "found" message with the location - other robots skip that area. Lesson: Distributed search algorithms, spatial coordination, emergent division of labor. What students learn: Without a central controller, how does the swarm decide who searches where? (Simple rule: go to nearest unexplored area.) What happens when 3 robots all head for the same token? (Collision โ first to broadcast wins; others redirect.) This is stigmergy - indirect coordination through environment signals - the same principle ants use. Activity 3: "Formation Challenge" (Ages 14-16) Concept: The teacher broadcasts a target formation (circle, line, grid). Each robot must navigate to its assigned position without colliding with others. Setup: BLE Mesh with vendor model. Teacher sends SWARM_CMD_SET_TARGET
Comments
No comments yet. Start the discussion.