Control the LED using Whatsapp message with ESP32


  • We can program ESP32 for controlling an LED using Whatsapp messaging remotely.
  • Messages contain light on / light off commands that instruct the ESP32 to control the LED's state, such as turning it on or off. 
  • Based on the received command, ESP32 will Turn ON/ Turn OFF the LED.



  • Before we start, need to know we can not receive messages directly from WhatsApp.
  • To receive the message we need an API that acts as a mediator between esp32 and WhatsApp to receive the message.
  • So we will take the help of ThingESP which is an API that receives the message from WhatsApp to esp32 and take the actions according to program or script.
  • To know more about ThingESP visit the below link


Now Let’s start and set it up.

Step 1

Open the ThinkESP website from below link and click on login button


If you have already account the login your acc or create a new account.


Now click on Project on the left side menu and click on Add New Projects


Now give the name for your project and project credentials and click on submit button.


Now you will aget the link for Twillo, Copy this link and paste on notepad.


Now open the second website which is twillo and click on login button to login or sign up.


After that click on console and click on Create New Account

Give the name for account and create it.

Now enter your phone number and verify it.

Now do the seetings as sown below and click on Get Started with Twillo


Now go to left side menu and click on Messaging-> Try it out -> Send a WhatsApp message.


You will get a pop-up message click on confirm


Now go to Secondbox settings tab and paste the link which we have copied from ThigESP site and save it.


Now scroll down and get this Whatsapp number and save it on your phone and send the message to join is-duck


LED Interfacing Diagram with ESP32

LED Interfacing Diagram with ESP32

Install required libraries 

Install the library which is ThingESP library for the above example. We need to install the ThingESP library using the Arduino Library Manager.

  • Open the Arduino IDE
  • Navigate to Sketch  Include Library  Manage Libraries…
  • The library Manager window will pop up. Now enter ThingESP into the search box, and click Install on the ThingESP option to install version 1.3.0 or higher. As shown below image.


Control the LED using WhatsApp message

Let’s control the LED from WhatsApp using the ESP32 and Arduino IDE.

Before uploading the code make sure you have added your user name,  project title, project credential, and Chat ID as follows.

ThingESP32 thing("User Name", "Project Title", "Project Credential");

Also, make sure you have added your SSID and Password

thing.SetWiFi("SSID", "PASS");


WhatsApp controlled LED code for ESP32

#include <WiFi.h>
#include <ThingESP.h>

ThingESP32 thing("User Name", "Project Title", "Project Credential");

int LIGHT = 23;

unsigned long previousMillis = 0;
const long INTERVAL = 6000; 

void setup()
  pinMode(LIGHT, OUTPUT);
  thing.SetWiFi("SSID", "PASS");

String HandleResponse(String query)
  if (query == "light on") {
    digitalWrite(LIGHT, 1);
    return "Done: Light Turned ON";

  else if (query == "light off") {
    digitalWrite(LIGHT, 0);
    return "Done: Light Turned OFF";

  else if (query == "light status")
    return digitalRead(LIGHT) ? "LIGHT is OFF" : "LIGHT is ON";
  else return "Your query was invalid..";

void loop()


Output on Serial Monitor



Components Used

WiFi Development Tools - 802.11 ESP32 General Development Kit, embeds ESP32-WROOM-32E, 4MB flash.
LED 3mm
LED 3mm


ESP32_WhatsApp_Controlled_LED Download