Build an AI Voice Controlled Light Using Google Gemini AI, Whisper AI, Python & ESP32

Artificial Intelligence is changing the way we interact with technology. Until recently, most voice-controlled projects relied on fixed commands like “Turn on the light” or “Switch off the LED.” If you said anything different, the system usually failed to understand you.

But what if your project could actually understand what you mean instead of just recognizing specific words?

That’s exactly what we’ll build in this project.

In this tutorial, we’ll create an AI-powered voice-controlled light using Google Gemini AI, Whisper AI, Python, and an ESP32. Instead of looking for predefined commands, the system understands the intention behind your speech.

For example, if you say:

  • “It’s getting dark.”
  • “I can’t see anything.”

The AI understands that you want the light turned on.

Similarly, phrases like:

  • “Good night.”
  • “I’m going to sleep.”
  • “Please switch everything off.”

will automatically turn the light off without needing an exact command.

This makes the project feel much more natural and intelligent compared to traditional voice-controlled electronics.

Whether you’re a beginner exploring AI or an electronics enthusiast looking to combine software with hardware, this project is a great starting point.



Components Required

ComponentQuantity
ESP32 Development Board1
AC bulb1
Ac bulb holder and plug (wired)1
USB Cable1
5v Relay module1
Microphone1
Jumper Wires3

Software Required

Before starting, install the following software on your computer.

  • Python 3.x
  • Arduino IDE
  • Google Gemini API
  • Whisper AI
  • ESP32 Board Package

Commands required on Command Prompt (CMD)

Open Command Prompt by pressing the Windows+R then type CMD and hit enter.

python --version
pip install pyserial
pip install faster-whisper sounddevice numpy
pip install google-genai


Creating a Google Gemini API Key

To use Gemini AI, you’ll need a free API key.

  1. Visit Google AI Studio.
  2. Sign in with your Google account.
  3. Create a new API key.
  4. Copy the key.
  5. Replace:
API_KEY="YOUR_GEMINI_API_KEY"

with your own API key.

Keep your API key private and never share it publicly.


Circuit Connections

The hardware setup for this project is simple because all the AI processing happens on your computer, while the ESP32 is responsible for controlling the relay. The relay acts as an electrically isolated switch, allowing the low-voltage ESP32 to safely control a high-voltage AC bulb.

ESP32 to Relay Module Connections

ESP32 PinRelay Module Pin
GPIO 2IN 1
3v3VCC
GNDGND

The relay module receives the control signal from GPIO 2. Whenever the ESP32 receives the LIGHT_ON command from the Python application, it energizes the relay and turns the AC bulb ON. Similarly, when it receives the LIGHT_OFF command, the relay is de-energized, switching the bulb OFF.


How This Project Works

Let’s understand the complete workflow.

Step 1 – Record Voice

The Python program records your voice using the computer microphone.

For example:

“Good Night”


Step 2 – Whisper AI

Whisper AI converts your speech into text.

Good Night

Whisper is extremely accurate and supports multiple languages.


Step 3 – Google Gemini AI

Now the text is sent to Google Gemini.

Unlike traditional voice-controlled systems, Gemini does not search for keywords.

Instead, it understands the meaning of your sentence.

For example,

User says:

“I’m going to sleep.”

Gemini understands the user’s intention and replies:

LIGHT_OFF

Similarly,

User says:

“It’s too dark here.”

Gemini replies:

LIGHT_ON

This makes the project feel much smarter than normal voice assistants.


Step 4 – Serial Communication

Python sends the response to ESP32.

LIGHT_ON

or

LIGHT_OFF

through the USB serial port.


Step 5 – ESP32

The ESP32 receives the command and turns the LED ON or OFF.

That’s it!

The complete process takes only a few seconds.


Project Workflow

Microphone

↓

Whisper AI

↓

Text

↓

Google Gemini AI

↓

LIGHT_ON / LIGHT_OFF

↓

Python

↓

Serial Communication

↓

ESP32

↓

LED

Python Program

import sounddevice as sd
from faster_whisper import WhisperModel
from google import genai
import serial
import wave
import os
import time


API_KEY = "YOUR API KEY"

client = genai.Client(api_key=API_KEY)


esp = serial.Serial("COM4", 115200)
time.sleep(2)

print("Connected to ESP32")


print("Loading AI model...")
model = WhisperModel("base", device="cpu", compute_type="int8")
print("AI model loaded successfully!")


SYSTEM_PROMPT = """
You are an AI controller for a room light.

Rules:
1. If the user wants the light ON, reply exactly:
LIGHT_ON

2. If the user wants the light OFF, reply exactly:
LIGHT_OFF

3. If you are not sure, reply exactly:
UNKNOWN

Examples:

User: It's dark here.
Assistant: LIGHT_ON

User: I can't see anything.
Assistant: LIGHT_ON

User: Turn on the light.
Assistant: LIGHT_ON

User: Please switch off the light.
Assistant: LIGHT_OFF

User: Good Morning.
Assistant: LIGHT_OFF

Return ONLY one word."""

duration = 3
sample_rate = 16000

print("\n🎤 AI Voice Light Controller Ready!")

while True:

    user = input("\nPress ENTER to Speak (or type exit): ")

    if user.lower() == "exit":
        break


    print("Listening...")

    audio = sd.rec(
        int(duration * sample_rate),
        samplerate=sample_rate,
        channels=1,
        dtype="int16"
    )

    sd.wait()

    print("Processing Voice...")

    filename = "temp.wav"

    with wave.open(filename, "wb") as wf:
        wf.setnchannels(1)
        wf.setsampwidth(2)
        wf.setframerate(sample_rate)
        wf.writeframes(audio.tobytes())

    segments, _ = model.transcribe(filename, language="en")

    whisper_result = ""

    for segment in segments:
        whisper_result += segment.text.strip() + " "

    whisper_result = whisper_result.strip()

    if os.path.exists(filename):
        os.remove(filename)

    if whisper_result == "":
        print("No speech detected.")
        continue

    print("\nYou Said:", whisper_result)


    response = client.models.generate_content(
        model="gemini-3.5-flash-lite",
        contents=whisper_result,
        config={
            "system_instruction": SYSTEM_PROMPT,
            "temperature": 0
        }
    )

    reply = response.text.strip()

    print("Gemini:", reply)

    if reply == "LIGHT_ON":
        esp.write(b"LIGHT_ON\n")
        print("LED ON Command Sent")

    elif reply == "LIGHT_OFF":
        esp.write(b"LIGHT_OFF\n")
        print("LED OFF Command Sent")

    else:
        print("Unknown command. Nothing sent.")

ESP32 Arduino Code

const int LED_PIN = 2;

void setup() {
  Serial.begin(115200);

  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);

  Serial.println("Gemini Light Ready");
}

void loop() {
  if (Serial.available()) {
    String cmd = Serial.readStringUntil('\n');
    cmd.trim();

    if (cmd == "LIGHT_ON") {
      digitalWrite(LED_PIN, HIGH);
      Serial.println("LED ON");
    }

    else if (cmd == "LIGHT_OFF") {
      digitalWrite(LED_PIN, LOW);
      Serial.println("LED OFF");
    }

    else {
      Serial.println("Unknown Command");
    }
  }
}

Why Use Gemini AI Instead of Normal Voice Commands?

Most voice-controlled electronics projects rely on fixed commands.

For example,

Turn On Light

works,

but

It's dark here.

does not.

Gemini AI solves this problem by understanding human language instead of simply matching words.

This makes your electronics project much smarter and much closer to how modern AI assistants work.


Example Voice Commands

Try speaking naturally.

To Turn ON

  • It’s dark.
  • I can’t see anything.
  • Please light up the room.
  • Turn on the light.
  • Make the room brighter.

To Turn OFF

  • Good Night.
  • I’m going to sleep.
  • Switch everything off.
  • Turn off the light.
  • No more light.

Notice how the AI understands different ways of expressing the same intention.

Conclusion

Building an AI-powered voice-controlled light is an excellent way to explore how artificial intelligence can enhance traditional electronics projects. By combining Whisper AI for speech recognition, Google Gemini AI for natural language understanding, Python for processing, and an ESP32 for hardware control, we’ve created a smart lighting system that responds to the meaning of what you say rather than just fixed commands.

This project is also a strong foundation for more advanced ideas such as AI home automation, smart appliances, and intelligent IoT systems. As you continue experimenting, you can expand it to control multiple devices, integrate wireless communication, or even build your own AI-powered home assistant.

More Articles & Posts