✨ Use RCAPP and get 5% off 👇
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

Controlling an LED with Two ESP32s Complete Guide

Controlling an LED with Two ESP32s Complete Guide
S
Written By Sumant Ghosh
📅 Updated on 02 Oct 2024
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 Node MCU Development Board with Wifi and Bluetooth (CP2102 Driver, 30 PIN)

    ESP32 (CP2102 Driver, 30 Pin) WiFi + Bluetooth NodeMCU-32 Development Board) Looking to supercharge your IoT projects? The ESP32 NodeMCU Development Board with Wi-Fi and Bluetooth (CP2102) is your go-to solution. This NodeMCU ESP32 development board is widely considered the best ESP32 board for...
    Rs 383/-
    Rs 383/-
    Rs 597/-
    Save Rs 214/-
    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 Box (150 Resistors and 30 Values) If you're an electronics enthusiast or hobbyist, the Resistor Box is an essential addition to your toolkit. This comprehensive kit includes 150 high-quality resistors with 30 unique values, ranging from 1E to 1M ohms. These versatile components...
      Rs 45/-
      Rs 45/-
      Rs 84/-
      Save Rs 39/-
      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 Tie Points Solderless Breadboard

          400 Tie Points Solderless Breadboard The 400 Tie Point solderless breadboard is perfect for building and testing electronics, especially with Arduino projects. It’s made of strong plastic with metal clips that hold wires securely. With 400 points, you can quickly set up circuits without...
          Rs 35/-
          Rs 35/-
          Rs 59/-
          Save Rs 24/-
          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 429/-
            Rs 429/-
            Rs 699/-
            Save Rs 270/-
            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 133/-
              Rs 133/-
              Rs 199/-
              Save Rs 66/-

              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
              Compare
              Product SKU Description Collection Availability Product Type Other Details

              Choose Options

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