---
title: How to Build a Voice‑Controlled Smart Light Switch with Raspberry Pi for Under $30
siteUrl: https://logzly.com/techdiyhub
author: techdiyhub (Tech DIY Hub)
date: 2026-06-20T14:04:58.986505
tags: [raspberrypi, smarthome, diy]
url: https://logzly.com/techdiyhub/how-to-build-a-voicecontrolled-smart-light-switch-with-raspberry-pi-for-under-30
---


**Disclosure: We are reader supported, and earn affiliate commissions when you buy through us.**


Ever walked into a dark room and fumbled for the switch while your phone is glued to your hand?  That moment is the perfect excuse to give your lights a brain – and you don’t need a fancy hub or a pricey subscription.  With a [Raspberry Pi](https://www.amazon.com/s?k=Raspberry+Pi&tag=organizationtip101-20), a few cheap parts, and a dash of code, you can talk to your lights for less than a coffee run.  Let’s get into it.

If you’re craving more DIY IoT fun, take a look at our guide on how to **[build a Wi‑Fi plant‑watering system with ESP32](/techdiyhub/build-a-wifi-plantwatering-system-with-esp32-complete-diy-guide)** – another low‑cost, voice‑enabled project you can tackle with similar hardware.

## What You’ll Need (and Why It’s Cheap)

| Part | Approx. Cost | Why It Matters |
|------|--------------|----------------|
| Raspberry Pi Zero W | $10 | Small, Wi‑Fi ready, and cheap enough for a hobby project. |
| Micro‑USB [power supply](https://www.amazon.com/s?k=power+supply&tag=organizationtip101-20) (5 V, 2 A) | $5 | Keeps the Pi happy and stable. |
| 2‑channel relay board | $6 | Acts as a safe switch for the mains voltage. |
| Mini‑breadboard + jumper wires | $3 | Makes wiring tidy without solder. |
| Micro‑[SD card](https://www.amazon.com/s?k=SD+card&tag=organizationtip101-20) (8 GB) | $4 | Holds the OS and your code. |
| Optional: USB microphone | $2 | Improves voice pickup if you don’t want to use the Pi’s built‑in audio. |

Total: **under $30** – and you end up with a reusable kit for future projects.

If you want to keep your wiring neat inside a project enclosure, our **[3D‑printed cable management solutions](/techdiyhub/print-your-own-cable-management-solutions-3d-printed-desk-organizers-for-makers)** are a perfect match for the mini‑breadboard layout.

## Step 1 – Get the Pi Ready

### Install Raspberry Pi OS

1. Download the Raspberry Pi Imager from the official site.  
2. Choose “Raspberry Pi OS Lite” – it’s a minimal Linux without a desktop, perfect for headless setups.  
3. Flash the image onto the micro‑SD card and pop it into the Pi.

### Enable Wi‑Fi and SSH

After the first boot, open the `boot` partition on your computer and add an empty file named `ssh`.  Then create a file called `wpa_supplicant.conf` with your Wi‑Fi credentials:

```
country=US
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
network={
    ssid="YourNetwork"
    psk="YourPassword"
    key_mgmt=WPA-PSK
}
```

Plug the Pi into power, wait a minute, then SSH into it (`ssh pi@raspberrypi.local`).  Default password is `raspberry` – change it right away with `passwd`.

## Step 2 – Wire the Relay Safely

**Warning:** You’re dealing with mains voltage (120 V or 230 V).  If you’re not comfortable, ask a [qualified electrician](https://www.amazon.com/s?k=qualified+electrician&tag=organizationtip101-20) to double‑check your work.

1. Connect the Pi’s 5 V pin to the relay board’s VCC, and a ground pin to GND.  
2. Use two GPIO pins (e.g., GPIO17 and GPIO27) for the relay control wires.  
3. On the relay side, wire the live (hot) wire from your [wall switch](https://www.amazon.com/s?k=wall+switch&tag=organizationtip101-20) to the “COM” terminal, and the “NO” (normally open) terminal to the [light fixture](https://www.amazon.com/s?k=light+fixture&tag=organizationtip101-20).  When the relay is energized, the circuit closes and the light turns on.

The relay board isolates the Pi from high voltage, so you’re safe as long as the board’s casing stays intact.

## Step 3 – Install [the Voice](https://www.amazon.com/s?k=The+Voice&tag=organizationtip101-20) Engine

### Choose Between [Google Assistant](https://www.amazon.com/s?k=Google+Assistant&tag=organizationtip101-20) and Open‑Source

For a $30 build, the simplest route is an open‑source speech‑to‑text engine like **Vosk**.  It runs locally, no internet needed, and works well on a Pi Zero.

```bash
sudo apt update
sudo apt install python3-pip python3-venv
python3 -m venv venv
source venv/bin/activate
pip install vosk sounddevice
```

Download a small English model (about 50 MB) from the Vosk website and unzip it.

### Test the Mic

If you’re using a USB mic, plug it in and run:

```bash
arecord -l
```

You should see the device listed.  A quick test:

```bash
python - <<EOF
import sounddevice as sd, vosk, json, queue
model = vosk.Model("model")
q = queue.Queue()
def callback(indata, frames, time, status):
    q.put(bytes(indata))
with sd.RawInputStream(samplerate=16000, blocksize=8000, device=1, dtype='int16',
                       channels=1, callback=callback):
    rec = vosk.KaldiRecognizer(model, 16000)
    while True:
        data = q.get()
        if rec.AcceptWaveform(data):
            print(json.loads(rec.Result())['text'])
EOF
```

Speak “turn on the light” – you should see the text printed.

## Step 4 – Write the Control Script

Create a file called `smart_switch.py`:

```python
import RPi.GPIO as GPIO
import json
import vosk, sounddevice as sd, queue

# Pin setup
GPIO.setmode(GPIO.BCM)
LIGHT_PIN = 17
GPIO.setup(LIGHT_PIN, GPIO.OUT)
GPIO.output(LIGHT_PIN, GPIO.LOW)   # start off

# Vosk setup
model = vosk.Model("model")
q = queue.Queue()
def audio_callback(indata, frames, time, status):
    q.put(bytes(indata))

def listen():
    with sd.RawInputStream(samplerate=16000, blocksize=8000,
                           device=1, dtype='int16', channels=1,
                           callback=audio_callback):
        recognizer = vosk.KaldiRecognizer(model, 16000)
        while True:
            data = q.get()
            if recognizer.AcceptWaveform(data):
                result = json.loads(recognizer.Result())
                text = result.get("text", "")
                if "turn on" in text and "light" in text:
                    GPIO.output(LIGHT_PIN, GPIO.HIGH)
                    print("Light ON")
                elif "turn off" in text and "light" in text:
                    GPIO.output(LIGHT_PIN, GPIO.LOW)
                    print("Light OFF")
                elif "exit" in text:
                    break

if __name__ == "__main__":
    try:
        listen()
    finally:
        GPIO.cleanup()
```

This script does three things:

1. Listens to the microphone continuously.  
2. Sends audio to Vosk, which returns plain text.  
3. Looks for the phrases “turn on the light” or “turn off the light” and toggles the GPIO pin accordingly.

Run it with `python3 smart_switch.py`.  You should be able to command your lamp by voice.

## Step 5 – Make It Run on Boot

You probably don’t want to SSH in every night to start the script.  Add a systemd service:

```bash
sudo nano /etc/systemd/system/smartlight.service
```

Paste:

```
[Unit]
Description=Voice controlled [smart light](https://www.amazon.com/s?k=smart+light&tag=organizationtip101-20)
After=network.target

[Service]
ExecStart=/usr/bin/python3 /home/pi/smart_switch.py
WorkingDirectory=/home/pi
StandardOutput=inherit
StandardError=inherit
Restart=always
User=pi

[Install]
WantedBy=multi-user.target
```

Enable and start:

```bash
sudo systemctl daemon-reload
sudo systemctl enable smartlight.service
sudo systemctl start smartlight.service
```

Now the Pi will launch the voice listener automatically after power‑up.

## Tuning Tips and Personal Tweaks

- **Mic placement:** I taped the USB mic inside a small 3D‑printed housing mounted near the ceiling.  The higher you place it, the less it picks up kitchen chatter.  
- **Noise filtering:** Adding a simple high‑pass filter in the code (`if len(text) < 3: continue`) reduces false triggers from background hum.  
- **[Multiple lights](https://www.amazon.com/s?k=multiple+lights&tag=organizationtip101-20):** Use the second relay channel and add a second GPIO pin.  Extend the phrase list to “turn on the [desk lamp](https://www.amazon.com/s?k=desk+lamp&tag=organizationtip101-20)” and map it accordingly.  
- **Power savings:** The Pi Zero draws about 120 mA at idle.  If you want a truly low‑[power switch](https://www.amazon.com/s?k=power+switch&tag=organizationtip101-20), consider a microcontroller like the ESP‑32, but you’ll lose the easy Vosk integration.

For a similar voice‑controlled project, see how to **[build a Wi‑Fi plant‑watering system with ESP32](/techdiyhub/build-a-wifi-plantwatering-system-with-esp32-complete-diy-guide)** – the same principles of local [speech processing](https://www.amazon.com/s?k=speech+processing&tag=organizationtip101-20) apply.

## Why This Project Rocks

- **Cost:** Most commercial [smart switches](https://www.amazon.com/s?k=smart+switches&tag=organizationtip101-20) start at $50 and lock you into a [cloud service](https://www.amazon.com/s?k=cloud+service&tag=organizationtip101-20).  Here you own the hardware and the code.  
- **Privacy:** All voice processing stays on the Pi, so no data is sent to the internet.  
- **Learning:** You get hands‑on with Linux, GPIO, and [speech recognition](https://www.amazon.com/s?k=Speech+recognition&tag=organizationtip101-20) – skills that pay off in any maker project.

I built this for the hallway light in my apartment.  The first time I said “turn on the light” and the bulb flickered to life, I felt like a sci‑fi director shouting commands at a set.  The best part?  The whole thing fits inside a tiny project box that I printed on my Prusa.  It’s a modest upgrade, but it turned a dull hallway into a little showcase of what a few dollars and a bit of curiosity can do.

If you run into hiccups, the Tech DIY Hub community on Discord is a great place to swap snippets and troubleshoot.  Remember, the magic isn’t in the [price tag](https://www.amazon.com/s?k=price+tag&tag=organizationtip101-20) – it’s in the joy of making something that actually works for you.
