Skip to content
Free Delivery on Orders Above Rs 999/- Pan-India
Cash on Delivery Available for Orders above Rs.500/- and Upto Rs 3000/-
SAVE more when you BUY more. Upto 30% Off on BULK PURCHASE
GST Invoices for Your Business
Dedicated Technical Support Team
Safely Delivering Genuine Products PAN INDIA
Delivering to
Select Location ▾
Delivering to Select Location
▾

Controlling an LED with Two ESP32s Complete Guide

Controlling an LED with Two ESP32s Complete Guide
S
Written By Sumant Ghosh
📅 Updated on 14 Aug 2026
✨ Summarize with AI
✅ Prompt copied

Summary

Using two ESP32 microcontrollers to control an LED remotely is a fantastic way to demonstrate their communication capabilities. In this guide, we'll explore how to set up one ESP32 as a server to control an LED connected to a second ESP32 acting as a client. We'll cover both Wi-Fi and Bluetooth communication methods.

Episode EE03:

Controlling an LED with Two ESP32s

Read this blog ALL YOU NEED TO KNOW ABOUT ESP32

Components and Supplies

ESP32 NodeMCU Dev Board (CP2102, 30-Pin) – WiFi & BLE support. -Nodemcu ESP Board -RobocrazeESP32 NodeMCU Dev Board (CP2102, 30-Pin) – WiFi & BLE support. -Nodemcu ESP Board -Robocraze

    ESP32 30 Pin Development Board (CP2102) WiFi + BT

    ESP32 30 Pin Development Board (CP2102) WiFi + BT The ESP32 30 Pin Development Board is a versatile microcontroller board designed for IoT, home automation, robotics, wireless monitoring, and embedded system development. Powered by a dual-core ESP32 processor and equipped with built-in WiFi and...
    Rs 449/-
    Rs 449/-
    Rs 599/-
    Save Rs 150/-
    Resistor Box (150PC, 30 Values) – Comprehensive resistor kit. -Basic Components -RobocrazeResistor Box (150PC, 30 Values) – Comprehensive resistor kit. -Basic Components -Robocraze

    Resistor Box (150 Resistors and 30 Values)

    Resistor Kit Box (150 Resistors and 30 Values) If you're an electronics enthusiast or hobbyist, this assorted resistor kit is an essential addition to your toolkit. This comprehensive resistor set includes 150 high-quality 1/4 watt resistors with 30 unique values, ranging from 1Ω to...
    Rs 45/-
    Rs 45/-
    Rs 82/-
    Save Rs 37/-
    3mm Orange LED (Pack of 10) – Reliable LED for indicator & DIY projects - Electronic Components - Robocraze3mm Orange LED (Pack of 10) – Reliable LED for indicator & DIY projects - Electronic Components - Robocraze

    3mm Orange Led (Pack of 10)

    3mm Orange Led (Pack of 10) An Orange light-emitting diode (LED) is a semiconductor light source. LED's are used as indicator lamps in many devices and are increasingly used for other lighting. It looks like a white led and illuminate's blue light. When a...
    Rs 17/-
    Rs 17/-
    Rs 25/-
    Save Rs 8/-
    400 Tie Points Solderless Breadboard – Medium-sized breadboard for Arduino & projects. Electronic Components - Robocraze400 Tie Points Solderless Breadboard – Medium-sized breadboard for Arduino & projects. Electronic Components - Robocraze

      400 Point Solderless Breadboard (Half Breadboard)

      400 Point Solderless Breadboard (Half Breadboard) Looking for the best breadboard price without compromising on quality? This 400 point breadboard (commonly known as a half breadboard) is perfect for building and testing electronics, especially with Arduino and ESP32 projects. It’s made of strong plastic...
      Rs 39/-
      Rs 39/-
      Rs 69/-
      Save Rs 30/-
      1660 Tie-Point Solderless Breadboard – Large breadboard for circuit prototyping. Electronic Components - Robocraze1660 Tie-Point Solderless Breadboard – Large breadboard for circuit prototyping. Electronic Components - Robocraze

      1660 tie-point Solderless Breadboard

      1660 tie-point Solderless Breadboard The 1660 Points Solderless Breadboard is an excellent size with more than enough room for more advanced prototyping. There are two terminal strips with 1260 tie-points and 4 distribution strips with 400 tie-points.  The breadboards accept a variety of wire sizes from 20 to...
      Rs 676/-
      Rs 676/-
      Rs 699/-
      Save Rs 23/-
      3M USB to Micro USB Cable Black3M USB to Micro USB Cable Black – High-quality Arduino USB Cable for fast charging & data transfer. -Robocraze

        3M USB to Micro USB Cable Black

        3M USB to Micro USB Cable Black - (Compatible with Smart Phones, Tablets, Power Bank, Black) Tired of short cables that limit where you can use your devices? The 3M USB to Micro USB Cable in Black is here to help. It’s 3 meters...
        Rs 138/-
        Rs 138/-
        Rs 199/-
        Save Rs 61/-

        What You’ll Need

        Two ESP32 Boards: One for controlling the LED (Server) and one for sending control commands (Client).

        Do you know How to connect esp32 to wifi - Read now!

        Wi-Fi Communication (Client-Server Model):

        Setup ESP32 as a Server (LED Controller)

        1. Circuit Diagram

        The image shows the LED connected to the ESP32 via a resistor.

        • LED Anode (long leg) to GPIO 2 (or any other GPIO) on ESP32.
        • LED Cathode (short leg) to GND via a 220Ω resistor.
        Circuit Diagram for Controlling an LED with Two ESP32s

        2. Code for ESP32 Server:

        
        #include 
        
        // Replace with your network credentials
        const char* ssid = "YOUR_SSID";
        const char* password = "YOUR_PASSWORD";
        
        WiFiServer server(80);
        
        const int ledPin = 2; // LED connected to GPIO 2
        
        void setup() {
          Serial.begin(115200);
          WiFi.begin(ssid, password);
        
          while (WiFi.status() != WL_CONNECTED) {
            delay(500);
            Serial.print(".");
          }
          Serial.println("Connected to WiFi");
          server.begin();
          pinMode(ledPin, OUTPUT);
          digitalWrite(ledPin, LOW); // Make sure LED is off initially
        }
        
        void loop() {
          WiFiClient client = server.available();
          if (client) {
            String request = client.readStringUntil('\r');
            client.flush();
        
            if (request.indexOf("/LED_ON") != -1) {
              digitalWrite(ledPin, HIGH);
            }
            if (request.indexOf("/LED_OFF") != -1) {
              digitalWrite(ledPin, LOW);
            }
        
            client.print("HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n");
            client.print("\r\n\r\n");
            client.print("\r\n");
            client.print("\r\n");
            client.print("\r\n");
            client.print("\r\n\r\n");
            client.stop();
          }
        }
        

        3. Explanation:

        The ESP32 server listens for HTTP requests. When it receives a request containing /LED_ON or /LED_OFF, it controls the LED connected to GPIO 2 accordingly.

        4. Upload the Code and Test:

        • Upload the code to the ESP32 server.
        • Open the Serial Monitor to find the IP address of the ESP32.
        • Enter the IP address in a web browser. Use the provided links to control the LED.

        Learn how to build a Smart water quality monitoring system using ESP32

        Setup ESP32 as a Client (Control Sender)

        Code for ESP32 Client:

        
        #include 
        
        // Replace with your network credentials and server IP
        const char* ssid = "YOUR_SSID";
        const char* password = "YOUR_PASSWORD";
        const char* serverIP = "SERVER_IP_ADDRESS"; // Replace with the server's IP address
        
        void setup() {
          Serial.begin(115200);
          WiFi.begin(ssid, password);
        
          while (WiFi.status() != WL_CONNECTED) {
            delay(500);
            Serial.print(".");
          }
          Serial.println("Connected to WiFi");
        }
        
        void loop() {
          WiFiClient client;
          if (client.connect(serverIP, 80)) {
            client.println("GET /LED_ON HTTP/1.1");
            client.println("Host: " + String(serverIP));
            client.println("Connection: close");
            client.println();
        
            delay(10000); // Wait 10 seconds before sending another request
        
            client.println("GET /LED_OFF HTTP/1.1");
            client.println("Host: " + String(serverIP));
            client.println("Connection: close");
            client.println();
          }
          delay(10000); // Wait 10 seconds before reconnecting
        }
        

        Explanation:

        The ESP32 client sends HTTP GET requests to the server to turn the LED on and off periodically.

         

         

         

         

        Also read: How to interfaceDS18B20 Temperature Sensor with ESP32

        Conclusion

        Controlling an LED with two ESP32 boards can be achieved using various communication methods, including Wi-Fi and Bluetooth. By following the steps outlined above, you can set up a server-client model over Wi-Fi or use Bluetooth serial communication to control your LED. These methods can be extended to more complex applications and integrated into larger IoT systems. Happy experimenting!

         

         

        Please do check out other blog posts about Popular electronics

         

        Check out other related blog posts about Drones: Drone transmitter and receiver , Drone motors and Getting started with a Quadcopter

         

        Make sure you check out our wide range of products and collections (we offer some exciting deals!)

        Excerpt

        To interface Two ESP32 Boards One for controlling the LED and one for sending control commands you'll need LED, Resistor, Arduino IDE, Breadboard, Jumper Wires.
        Prev Post
        Next Post

        Leave a comment

        Please note, comments need to be approved before they are published.

        Thanks for subscribing!

        This email has been registered!

        Shop the look

        Choose Options

        Edit Option
        Back In Stock Notification

        Choose Options

        this is just a warning
        Login
        Shopping Cart
        0 items
        FREE SHIPPING!
        ₹100 OFF
        ₹200 OFF
        ₹999
        ₹2500
        ₹4900
        WhatsApp Chat Chat