Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Print Service
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Print Service
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Robotics & DIY

Swarm Robotics: Multiple Arduino Bots Communicating Guide

Swarm Robotics: Multiple Arduino Bots Communicating Guide

March 11, 2026 /Posted byJayesh Jain / 2

Swarm robotics — coordinating multiple Arduino-based robots to work together as a collective — is one of the most exciting frontiers in DIY robotics. Inspired by the collective behaviour of ants, bees, and fish schools, swarm robots can achieve tasks that a single robot cannot: area coverage, object manipulation, and fault-tolerant operation where the failure of one unit doesn’t stop the mission. This guide covers the communication protocols, hardware requirements, and Arduino code for building your first multi-robot swarm system.

Table of Contents

  • Swarm Robotics Concepts
  • Communication Options for Swarm Robots
  • Hardware Design for Each Robot Unit
  • ESP-NOW Protocol for Swarm Communication
  • Swarm Algorithms: Flocking and Coverage
  • Complete Arduino/ESP32 Swarm Code
  • Recommended Products
  • Frequently Asked Questions

Swarm Robotics Concepts

Swarm robotics is characterised by three fundamental principles:

  • Decentralisation: No single robot is the “master”. All robots are equal peers that react to local information — proximity to neighbours, obstacle detection, and received messages.
  • Local interaction: Each robot only communicates with its nearest neighbours, not with all robots in the swarm. Global coordination emerges from these local interactions.
  • Scalability: Adding more robots to the swarm should improve performance without requiring changes to the existing robots’ firmware.

Classic swarm behaviours include:

  • Aggregation: Robots move toward each other until clustered
  • Dispersion: Robots spread out to maximise coverage area
  • Flocking: Robots move in coordinated direction while maintaining separation (Boids algorithm)
  • Foraging: Robots search an area and return “food” (objects) to a nest location
  • Task allocation: Robots self-assign to different tasks based on need and capability

Communication Options for Swarm Robots

Protocol Range Latency Cost Best For
ESP-NOW (ESP32) 100–200m <5ms ₹250/unit Indoor swarms, fast coordination
nRF24L01 (2.4 GHz) 100m <10ms ₹80/unit Arduino-based swarms
IR (Infrared) 0.5–2m <1ms ₹10/unit Local neighbour detection
Bluetooth (BLE) 10–30m 10–100ms ₹200/unit Centralised monitoring
LoRa 1–5 km 50–500ms ₹400/unit Outdoor search/coverage

ESP-NOW is the recommended protocol for swarm robotics projects because it provides low-latency peer-to-peer WiFi communication without requiring a router or access point. Each ESP32 can broadcast to all peers simultaneously or send targeted messages to specific MAC addresses — ideal for swarm coordination where broadcast is the dominant communication pattern.

Hardware Design for Each Robot Unit

A minimal swarm robot unit for a 3-bot educational swarm:

  • ESP32 DevKit V1 (WiFi + dual-core = communication + control)
  • L298N motor driver or TB6612FNG dual H-bridge
  • 2× DC gear motors with wheels
  • HC-SR04 ultrasonic sensor (front obstacle detection)
  • 2× IR proximity sensors (left/right neighbour detection)
  • LiPo 7.4V 1000mAh battery + LM2596 5V step-down for ESP32
  • Chassis: 3D-printed or acrylic cut frame, ~15×10 cm

Estimated cost per robot: ₹800–₹1,200. A 3-robot swarm can be built for ₹2,400–₹3,600 — a very accessible entry point for swarm robotics experimentation.

ESP-NOW Protocol for Swarm Communication

ESP-NOW allows ESP32s to communicate directly without WiFi infrastructure at up to 250 bytes per packet and under 5 ms latency. Setting up ESP-NOW for a swarm:

#include <esp_now.h>
#include <WiFi.h>

// Swarm message structure
typedef struct {
  uint8_t  robotID;    // Sender's robot ID (0-7)
  int16_t  posX;       // Estimated X position (cm)
  int16_t  posY;       // Estimated Y position (cm)
  uint8_t  state;      // 0=idle, 1=moving, 2=obstacle, 3=task
  uint8_t  heading;    // 0-359 degrees
  uint8_t  taskID;     // Current task assignment
} SwarmMsg;

// Broadcast address: sends to ALL ESP32 peers simultaneously
uint8_t broadcastAddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

SwarmMsg myState;
SwarmMsg neighbourStates[8];  // Track up to 8 neighbours

void OnDataSent(const uint8_t* mac, esp_now_send_status_t status) {
  // Message sent callback — use for reliability tracking
}

void OnDataRecv(const uint8_t* mac, const uint8_t* data, int len) {
  SwarmMsg received;
  memcpy(&received, data, sizeof(received));

  // Store neighbour state
  if (received.robotID < 8) {
    neighbourStates[received.robotID] = received;
  }
}

void initESPNow() {
  WiFi.mode(WIFI_STA);
  if (esp_now_init() != ESP_OK) {
    Serial.println("ESP-NOW init failed!");
    return;
  }
  esp_now_register_send_cb(OnDataSent);
  esp_now_register_recv_cb(OnDataRecv);

  // Register broadcast peer
  esp_now_peer_info_t peerInfo = {};
  memcpy(peerInfo.peer_addr, broadcastAddr, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;
  esp_now_add_peer(&peerInfo);
}

void broadcastState() {
  esp_now_send(broadcastAddr, (uint8_t*)&myState, sizeof(myState));
}

Swarm Algorithms: Flocking and Coverage

Reynolds Boids Algorithm (Flocking)

The Boids algorithm creates natural-looking flock movement from three simple rules applied to each robot:

  1. Separation: Steer away from nearby robots to avoid crowding
  2. Alignment: Steer toward the average heading of nearby robots
  3. Cohesion: Steer toward the average position of nearby robots

Each force vector is calculated from the neighbour states received via ESP-NOW, weighted, and summed to produce a target heading for the robot’s motors.

Random Walk Coverage

For area coverage (e.g., floor sweeping, mine detection), each robot follows a modified random walk that ensures no region is revisited: move straight until an obstacle is detected, then turn by a random angle. Coordination via ESP-NOW ensures robots spread out by repelling from known robot positions.

Complete Arduino/ESP32 Swarm Code

#include <esp_now.h>
#include <WiFi.h>

// Motor control pins
#define MOTOR_L_FWD  25
#define MOTOR_L_BWD  26
#define MOTOR_R_FWD  27
#define MOTOR_R_BWD  14
#define MOTOR_SPEED  150  // 0-255 PWM

// Ultrasonic sensor
#define TRIG_PIN 32
#define ECHO_PIN 33

// Configuration
#define ROBOT_ID     0    // Change for each robot: 0, 1, 2
#define OBSTACLE_CM  20   // Stop if obstacle within 20 cm
#define BROADCAST_MS 200  // Broadcast state every 200ms

typedef struct {
  uint8_t robotID;
  int16_t posX, posY;
  uint8_t state;
  uint8_t heading;
} SwarmMsg;

uint8_t broadcastAddr[] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
SwarmMsg myState = {ROBOT_ID, 0, 0, 0, 0};
SwarmMsg peers[8];

void setMotors(int leftSpeed, int rightSpeed) {
  // Positive = forward, negative = backward
  analogWrite(MOTOR_L_FWD, max(0, leftSpeed));
  analogWrite(MOTOR_L_BWD, max(0, -leftSpeed));
  analogWrite(MOTOR_R_FWD, max(0, rightSpeed));
  analogWrite(MOTOR_R_BWD, max(0, -rightSpeed));
}

float getDistance() {
  digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2);
  digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10);
  digitalWrite(TRIG_PIN, LOW);
  return pulseIn(ECHO_PIN, HIGH) * 0.0343 / 2.0;
}

void OnDataRecv(const uint8_t* mac, const uint8_t* data, int len) {
  SwarmMsg msg;
  memcpy(&msg, data, sizeof(msg));
  if (msg.robotID < 8) peers[msg.robotID] = msg;
}

void setup() {
  Serial.begin(115200);

  // Motor pins
  pinMode(MOTOR_L_FWD, OUTPUT); pinMode(MOTOR_L_BWD, OUTPUT);
  pinMode(MOTOR_R_FWD, OUTPUT); pinMode(MOTOR_R_BWD, OUTPUT);
  // Ultrasonic
  pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT);

  // ESP-NOW
  WiFi.mode(WIFI_STA);
  esp_now_init();
  esp_now_register_recv_cb(OnDataRecv);

  esp_now_peer_info_t peer = {};
  memcpy(peer.peer_addr, broadcastAddr, 6);
  esp_now_add_peer(&peer);
}

void loop() {
  static unsigned long lastBroadcast = 0;
  static int turnDir = 1;
  static int moveCount = 0;

  float dist = getDistance();

  if (dist > 0 && dist < OBSTACLE_CM) {
    // Obstacle detected — stop and turn
    setMotors(0, 0);
    delay(200);
    // Turn away from obstacle
    setMotors(-MOTOR_SPEED * turnDir, MOTOR_SPEED * turnDir);
    delay(random(300, 700));
    turnDir *= -1;  // Alternate turn direction
    myState.state = 2;
  } else {
    // No obstacle — move forward
    setMotors(MOTOR_SPEED, MOTOR_SPEED);
    myState.state = 1;
    moveCount++;

    // Random direction change every 50-100 moves (avoid straight-line bias)
    if (moveCount > random(50, 100)) {
      setMotors(-MOTOR_SPEED, MOTOR_SPEED);
      delay(random(200, 500));
      moveCount = 0;
    }
  }

  // Broadcast state to swarm
  if (millis() - lastBroadcast > BROADCAST_MS) {
    lastBroadcast = millis();
    esp_now_send(broadcastAddr, (uint8_t*)&myState, sizeof(myState));
  }

  delay(20);
}

Recommended Products

Waveshare General Driver Board for Robots (ESP32-based)

Waveshare’s robot driver board integrates an ESP32, dual H-bridge motor drivers, servo headers, and sensor ports on a single PCB — the perfect foundation for a swarm robot unit. The onboard ESP32 handles both motor control and ESP-NOW swarm communication without any additional hardware.

View Product

ACEBOTT ESP8266 Quadruped Bionic Spider Robot Kit

This pre-built spider robot kit is an excellent starting point for swarm robotics — add ESP-NOW communication to multiple units and programme them for coordinated walking behaviours. The quadruped form factor avoids wheel slippage issues on uneven surfaces common in swarm deployment environments.

View Product

Waveshare AlphaBot2 Robot Building Kit for Raspberry Pi

The AlphaBot2 chassis includes a motor driver, IR sensors, and a camera interface — a complete mobile robot platform for swarm experiments. Add a Raspberry Pi and use ROS2 with ESP-NOW gateways for a hybrid swarm where Pi units handle high-level coordination and ESP32 units handle reactive behaviours.

View Product

Waveshare ESP32 Servo Driver Expansion Board

For servo-based swarm robots (hexapods, wheeled platforms with servo steering), this ESP32-based 16-channel servo driver provides enough outputs for complex motion while maintaining WiFi connectivity for ESP-NOW swarm communication. Built-in WiFi eliminates the need for external communication modules.

View Product

Frequently Asked Questions

How many robots does a swarm need to be useful?

Swarm behaviours start to emerge with as few as 3 robots. For research purposes, meaningful statistical results require 10+ units. For educational demonstrations, 3–5 robots clearly show collective behaviour. The power of swarm robotics — redundancy, parallelism, and emergent coordination — becomes obvious with 5+ units.

Can Arduino Uno robots form a swarm without ESP32?

Yes — use nRF24L01 2.4 GHz radio modules (₹80 each) with Arduino Uno. The nRF24L01 supports multicast (broadcast to all units) and point-to-point messaging. Latency is higher than ESP-NOW (~10 ms vs ~5 ms) but adequate for swarm coordination where decisions are made at 100 ms timescales.

How do swarm robots localise themselves without GPS?

Indoor localisation options: (1) Wheel odometry — count motor encoder pulses to estimate position from last known location. (2) IR landmark beacons — fixed beacons at known positions emit IR codes that robots detect and triangulate. (3) UWB (Ultra-Wideband) ranging — modules like the DWM1000 provide 10–30 cm ranging accuracy. For outdoor swarms, GPS modules (NEO-6M, ~₹350) provide 2–5 metre accuracy.

Can swarm robots avoid deadlock when multiple bots block each other?

Deadlock avoidance in robot swarms uses randomness as a resolution strategy: if a robot detects a peer blocking its path and waits longer than a timeout (e.g., 2 seconds), it turns by a random angle and tries a new direction. Pure deterministic avoidance causes symmetric deadlocks; randomness breaks symmetry reliably.

What is the difference between multi-robot systems and swarm robotics?

Multi-robot systems typically have a central coordinator that assigns tasks and monitors all robots. Swarm robotics is fully decentralised — each robot makes decisions based only on local sensor data and neighbour communication, with no global coordinator. Swarms are more fault-tolerant (no single point of failure) but harder to programme for complex tasks.

Start your swarm robotics journey today. Browse ESP32 boards, robot kits, and servo motors at zbotic.in/robotics-diy — fast delivery across India.
Tags: Arduino, ESP-NOW, ESP32, flocking algorithm, India, multi-robot, robotics diy, swarm robotics
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Rainwater Harvesting Monitor: ...
blog rainwater harvesting monitor tank level with ultrasonic 599661
blog color detection and sorting robot using opencv and arduino 599663
Color Detection and Sorting Ro...

Related posts

Svg%3E
Read more

Caterpillar Track Robot: Tank-Drive Build for All Terrain

April 1, 2026 0
When wheels lose grip on sand, gravel, grass, or loose surfaces, caterpillar tracks keep moving. A tank-track robot distributes its... Continue reading
Svg%3E
Read more

RC Car to Robot: Convert a Toy Car into an Autonomous Robot

April 1, 2026 0
That old RC toy car gathering dust can be transformed into an Arduino-controlled autonomous robot with just a few electronic... Continue reading
Svg%3E
Read more

Robotic Arm Kit India: Best Options for Students and Hobbyists

April 1, 2026 0
If you are a student or hobbyist looking to get into robotics, a robotic arm kit is one of the... Continue reading
Svg%3E
Read more

Sumo Robot: Competition Build Guide India

April 1, 2026 0
Sumo robot competitions are among the most exciting events in Indian robotics, pitting small autonomous robots against each other in... Continue reading
Svg%3E
Read more

Robot Arm Build: 6-DOF Servo Arm with Arduino Control

April 1, 2026 0
Building a 6-DOF robot arm with servo motors and Arduino is one of the most rewarding robotics projects you can... Continue reading

2 comments

  • Avatar of Forrest

    Forrest

    March 18, 2026 - 12:23 am

    Hi.
    I am very interested in swarm robot cars. Do you have any videos of them running or other demonstrations? Any information would be greatly appreciated!
    Thank you in advance!

    Reply
  • Avatar of Shubham S

    Shubham S

    March 27, 2026 - 2:01 pm

    Hi Forrest,
    Thank you for your interest in swarm robot cars!
    You can check out this demonstration video here: https://www.youtube.com/watch?v=llM_cTODA28 (Copy Link)
    It showcases how the swarm robots operate in real-time. Let us know if you’d like more details or have any questions-we’d be happy to help!

    Reply

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Technical Supports Email: [email protected]
For Sales / Enquiries Email: [email protected]

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now