ESP32 Switch Control Using Servo (Voice Control Switch On/off Bot)

by Circuit Tickle in Circuits > Electronics

945 Views, 3 Favorites, 0 Comments

ESP32 Switch Control Using Servo (Voice Control Switch On/off Bot)

Home light control by voice | esp32 switch on/off robot
Home light control by voice | esp32 switch on/off robot

Hi Everyone,

In this post, we are going to see how to build the ESP32 switch controller using a servo that can be controlled by voice. This project will help control our home appliances (Light, Fan, etc.) without messing with the existing electrical switchboard. This project only required minimal components like ESP32 and Servo motor. The ESP32 will get voice commands from our smartphone via Bluetooth. The servo motor will turn the switch ON or OFF like we manually turn ON / OFF the switch. In this project, I am controlling my home light via voice. Check the Attached video to see the project in action.

Now let's see the required components and circuit connection of this project.

Supplies

  • ESP32
  • Servo Motor
  • Some connector wires
  • One Mobile charger to power the ESP32

Circuit Connection

The only circuit connection we need is connection between ESP32 and servo motor :

ESP32 ------------ Servo motor

VIN ----------------- VCC (Red pin)

GND ---------------- GND (Brown pin)

D12 ----------------- PWM pin (Orange pin)


Let's see the App required to send the voice commands from our smartphone to ESP32 via Bluetooth.

The Voice Control App

Following is the app I used to send the voice commands from our smartphone to ESP32 via Bluetooth :

https://play.google.com/store/apps/details?id=com.locominder.bluetoothvoicecontrol

This voice control app is very quick to get started and It has some example codes for both Arduino and ESP32. Next, let us see the project code.

Project Code

Capture.PNG

I used Arduino IDE to program ESP32. We need the ESP32Servo library needs to install in Arduino IDE to control the servo motor using ESP32. Check the attached image for the ESP32Servo library. After installing the library upload the following code to the ESP32 and the project will work like a charm. Check the project in action in the above video


#include "BluetoothSerial.h"
#include <ESP32Servo.h>
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif

#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Bluetooth not available or not enabled. It is only available for the ESP32 chip.
#endif

BluetoothSerial SerialBT;

Servo light_servo;

const int light_servo_pin = 12;

void setup()
{
  Serial.begin(115200);
  SerialBT.begin("ESP32Circuit"); //BLUETOOTH DEVICE NAME

  light_servo.attach(light_servo_pin);
  light_servo.write(133);  
}

void loop() {
  if (SerialBT.available()) {
   
    String value = SerialBT.readStringUntil('\n');
    value.toLowerCase();
    Serial.println(value);

    if(value == "light on")  
    {
       light_servo.write(70);
    }
    if(value == "light off")
    {
      light_servo.write(133);
    }
  }
 
}


Thank you for Reading and enjoy the project output !