Smart Light Control with ESP32 and VC-02 Voice Module
Voice-controlled devices are no longer science fiction; they are part of our daily lives in the form of Alexa, Google Home, and Siri.
But what if you could build your own voice-controlled light system without needing the internet or cloud servers?
That’s exactly what we are going to do in this project. By combining the ESP32 microcontroller with the VC-02 voice recognition module, we will create a simple yet powerful smart light control system.
Key Idea: Unlike cloud-based assistants, the VC-02 works completely offline.
It can recognize pre-trained voice commands without Wi-Fi, making it ideal for student projects or areas with poor internet.
Step 1: Connecting the Components
- The VC-02 module communicates with the ESP32 using UART.
- Connect VC-02 TX → ESP32 RX
- Connect VC-02 RX → ESP32 TX
- Power the module with 3.3V or 5V (depending on version).
- For controlling the light, we use a Relay Module:
- Relay IN pin → GPIO23 of ESP32
- Relay VCC → 5V, GND → GND
- Connect the bulb through the relay just like wiring a switch.
Highlight: The relay acts as an electronic switch. The ESP32 controls it, but the actual power for the bulb comes through the relay.
Step 2: Training the VC-02
Before running the system, we need to train the VC-02.
Using the official configuration tool, record commands such as:
- “Light On” → ID 1
- “Light Off” → ID 2
When trained, the module sends these IDs to the ESP32 whenever it hears the phrase.
🎤 Highlight Button:
“Light On” → ID 1
“Light Off” → ID 2
Step 3: Writing the Code
In the Arduino IDE:
- Set up serial communication with the VC-02 at 9600 baud.
- In the
loop(), listen for command IDs. - If ESP32 receives
ID 1, turn the relay ON. - If ESP32 receives
ID 2, turn the relay OFF.
💡 Highlight: Your voice → VC-02 → ESP32 → Relay → Light Bulb.
A direct chain of control without internet!
Step 4: Testing
When you say:
- “Light On” → The bulb switches ON instantly.
- “Light Off” → The bulb switches OFF immediately.
Because the system is offline, there’s no cloud delay—response feels instant.
Extensions for Students
This project is just the beginning. You can:
- Control multiple relays (fans, TVs, appliances).
- Train more custom commands.
- Combine with Wi-Fi + MQTT for hybrid offline + online control.
#include <HardwareSerial.h>
HardwareSerial VC02(1); // Use UART1 for VC-02
#define RELAY_PIN 23
void setup() {
Serial.begin(115200);
VC02.begin(9600, SERIAL_8N1, 16, 17); // RX=16, TX=17
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);
Serial.println("Smart Light Control with VC-02 Ready...");
}
void loop() {
if (VC02.available()) {
int cmd = VC02.read(); // Read voice command ID
Serial.print("VC-02 Command ID: ");
Serial.println(cmd);
if (cmd == 1) { // "Light On"
digitalWrite(RELAY_PIN, HIGH);
Serial.println(" Light Turned ON");
}
else if (cmd == 2) { // "Light Off"
digitalWrite(RELAY_PIN, LOW);
Serial.println("Light Turned OFF");
}
}
}
Code Walkthrough
1. Include Required Library
#include <HardwareSerial.h>The HardwareSerial library lets the ESP32 use its extra UART ports to talk with external modules like the VC-02 voice recognition module.
2. Create Serial Object for VC-02
HardwareSerial VC02(1);We create a serial object named VC02 using UART1 of the ESP32. This reserves a dedicated serial channel for communication with the VC-02.
3. Define Relay Pin
#define RELAY_PIN 23We assign GPIO 23 to the relay module. Using a #define makes it easier to change the pin later without editing multiple lines of code.
4. Setup Function
void setup() {
Serial.begin(115200);
VC02.begin(9600, SERIAL_8N1, 16, 17);Serial.begin(115200)starts the USB serial connection for debugging.VC02.begin(9600, SERIAL_8N1, 16, 17)starts UART communication with the VC-02 at 9600 baud, using GPIO16 as RX and GPIO17 as TX.
5. Initialize Relay
pinMode(RELAY_PIN, OUTPUT);
digitalWrite(RELAY_PIN, LOW);- Set the relay pin as an output.
- Ensure the relay is OFF at startup by writing
LOW.
6. Debug Message
Serial.println("Smart Light Control with VC-02 Ready...");
}This message confirms on the Serial Monitor that the system is ready to process voice commands.
7. Main Loop — Check for Commands
if (VC02.available()) {
int cmd = VC02.read();VC02.available()checks if the module has sent a command.VC02.read()reads the command ID (e.g.,1for Light On,2for Light Off).
8. Turn Light On
if (cmd == 1) { // "Light On"
digitalWrite(RELAY_PIN, HIGH);
Serial.println("✅ Light Turned ON");
}If the received command ID is 1, the ESP32 sets the relay pin HIGH, turning the bulb on.
9. Turn Light Off
else if (cmd == 2) { // "Light Off"
digitalWrite(RELAY_PIN, LOW);
Serial.println("❌ Light Turned OFF");
}If the command ID is 2, the ESP32 sets the relay pin LOW, switching the bulb off.
Testing the Project
After uploading the code, open the Serial Monitor in Arduino IDE. When you say “Light On,” you should see:
VC-02 Command ID: 1
✅ Light Turned ONAnd when you say “Light Off”:
VC-02 Command ID: 2
❌ Light Turned OFFAt the same time, the bulb connected through the relay will turn on and off in response to your voice.
Why This Project is Useful
The real magic here is that everything happens offline. You don’t need Wi-Fi, a smartphone app, or the cloud. The ESP32 and VC-02 module handle everything locally. This makes the system fast, private, and ideal for low-cost smart home setups.
Once you understand this basic example, you can expand it to control multiple appliances by training more voice commands, or even integrate it with Wi-Fi and MQTT to create a hybrid voice + IoT system.