Table of contents
Abstract
Halloween is designed to Scare using RDK X5 Kit and PIR motion detector with Voice assistance for interactive scare. Lighting sequence to scare, RGB LED is used to play according to horror sound played on Laptop based on activation command.
Project
In the current project Halloween is designed to Scare the people who enter into the vicinity.
Introduction:
The Voice-Controlled Halloween Scare System is an interactive security and entertainment project designed to create a spooky experience during Halloween celebrations. The system uses the RDK X5 development kit, a Passive Infrared (PIR) motion sensor, an RGB LED, and a laptop for voice recognition and audio playback.
The system operates using two voice commands: "Halloween start scaring" and "Halloween stop scaring." When the start command is spoken through the laptop microphone, the system activates motion monitoring using the PIR sensor. Whenever a person approaches the sensor, it detects movement and triggers a pre-recorded scary MP3 audio file played through the laptop speaker. The RGB LED also illuminates to provide a visual indication of the scare event.
When the stop command is spoken, the system immediately disables motion monitoring and stops the scare audio playback. The RGB LED is also switched off.
The RDK X5 acts as the main hardware controller, interfacing with the PIR sensor and RGB LED through its GPIO pins. Python programming in RDK Studio is used to control the hardware, process voice commands, and manage audio playback on the laptop.
This project demonstrates the integration of embedded systems, voice control, motion detection, GPIO interfacing, and multimedia applications.
Hardware setup
The hardware section consists of the RDK X5 development board, PIR motion sensor, RGB LED, jumper wires, and a USB Type-C connection.
RDK X5 development board
Components required
PIR motion sensor
Detects the movement of people within its sensing range. Its OUT signal is connected to RDK pin 15.
RGB LED (Common Anode)
Produces red, green, and blue light to indicate the system status. The three color channels are connected to pins 31, 36, and 37.
USB Type-C cable
Connects the RDK X5 to the laptop for development, programming, and communication.
Jumper wires
Used to connect the PIR sensor and RGB LED to the RDK X5 GPIO header.
Current-limiting resistors
Three suitable resistors, one for each RGB channel, protect the LED and GPIO interface.
Circuit design and connections
The RDK X5 has a 40-pin GPIO interface with 3.3 V logic levels. The following connections use the pin numbers you provided.
A. PIR sensor connection
| PIR sensor pin | RDK X5 connection |
| VCC | 5V |
| GND | GND |
| OUT | GPIO pin 15 |
The PIR sensor continuously monitors its surroundings when the system is activated. When a person moves within its detection range, the OUT pin changes its logic state.
B. RGB LED connections (common anode)
| RGB LED terminal | RDK X5 connection |
| Common anode (+) | 3.3V |
| Red | GPIO 31 |
| Green | GPIO 36 |
| Blue | GPIO 37 |
Important: A common-anode RGB LED is active LOW. Setting a channel LOW turns it on, while setting it HIGH turns it off. Use appropriate current-limiting resistors and preferably transistor drivers if needed to keep GPIO current within its ratings.
Circuit Connection diagram
The overall connections can be represented as:
LAPTOP
+-------------------+
| Microphone |
| Voice recognition |
| Scary MP3 audio |
| Laptop speaker |
+---------+---------+
|
USB Type-C
|
+---------v---------+
| RDK X5 |
| GPIO 15 <--------+---- PIR OUT
| GPIO 31 ---------+---- Red LED
| GPIO 36 ---------+---- Green LED
| GPIO 37 ---------+---- Blue LED
+-------------------+
The laptop handles voice recognition and audio playback, while the RDK X5 handles sensor monitoring and LED control.
Software development
The software is developed using Python in RDK Studio. The project has two main software functions:
1. Laptop-side Python program: Uses the laptop microphone for voice recognition and the laptop speaker for playing the scary MP3 audio.
2. RDK X5-side Python program: Uses the Hobot.GPIO library to monitor the PIR sensor and control the RGB LED.
Vosk offline speech recognition model:
The laptop-based system uses the Vosk offline speech recognition model to capture and recognize voice commands through the built-in microphone. When the user says “Halloween start scaring,” the software sends a START command to the RDK X5 board to activate the scare system. Similarly, when “Halloween stop scaring” is recognized, a STOP command is transmitted to the board, immediately stopping MP3 playback. When the RDK X5 detects motion, it sends a notification to the laptop, triggering playback of the scary MP3 audio file. This enables reliable, real-time voice-controlled operation without requiring an internet connection
Working principle:
Voice command: "Halloween start scaring"
Voice recognition on laptop
Send START command to RDK X5
PIR sensor starts monitoring motion
Motion detected
RGB LED illuminates and scary MP3 plays through laptop speaker
Voice command: "Halloween stop scaring"
Stop audio, disable monitoring and switch OFF RGB LED
Laptop Python Program:
The laptop program performs voice recognition and controls MP3 playback.
The main software operations are:
Capture voice through the laptop microphone.
Recognize the command "Halloween start scaring".
Send a START command to the RDK X5.
Recognize the command "Halloween stop scaring".
Send a STOP command to the RDK X5.
Play the scary MP3 file when the RDK reports motion detection.
Stop audio playback immediately when the STOP command is received.
Code for LAPTOP/PC:
import socket
import threading
import pygame
import speech_recognition as sr
import pyttsx3
import time
# ==========================================
# CONFIGURATION
# ==========================================
LAPTOP_IP = "0.0.0.0"
LAPTOP_PORT = 5001
RDK_IP = "192.168.128.10"
RDK_PORT = 5000
AUDIO_FILE = r"D:\HALLOWEEN_PROJECT\scare.mp3"
# ==========================================
# SHARED STATE
# ==========================================
audio_lock = threading.Lock()
running = True
# ==========================================
# AUDIO INITIALIZATION
# ==========================================
pygame.mixer.init()
pygame.mixer.music.load(AUDIO_FILE)
def start_scary_sound():
with audio_lock:
if not pygame.mixer.music.get_busy():
pygame.mixer.music.play(-1)
print("SCARY SOUND STARTED - LAPTOP SPEAKERS")
def stop_scary_sound():
with audio_lock:
pygame.mixer.music.stop()
print("SCARY SOUND STOPPED")
# ==========================================
# VOICE RESPONSE
# ==========================================
engine = pyttsx3.init()
engine.setProperty("rate", 160)
engine.setProperty("volume", 1.0)
speech_lock = threading.Lock()
def speak(message):
with speech_lock:
print("LAPTOP VOICE:", message)
engine.say(message)
engine.runAndWait()
# ==========================================
# SEND COMMAND TO RDK
# ==========================================
def send_command(command):
try:
client = socket.socket(
socket.AF_INET,
socket.SOCK_STREAM
)
client.settimeout(5)
client.connect((RDK_IP, RDK_PORT))
client.sendall(command.encode())
response = client.recv(1024).decode()
client.close()
print("RDK:", response)
return response
except Exception as e:
print("RDK CONNECTION ERROR:", e)
return None
# ==========================================
# RECEIVE EVENTS FROM RDK
# ==========================================
def event_server():
server = socket.socket(
socket.AF_INET,
socket.SOCK_STREAM
)
server.setsockopt(
socket.SOL_SOCKET,
socket.SO_REUSEADDR,
1
)
server.bind((LAPTOP_IP, LAPTOP_PORT))
server.listen(5)
print("LAPTOP EVENT SERVER READY")
print("WAITING FOR RDK EVENTS")
while running:
try:
conn, address = server.accept()
with conn:
event = conn.recv(1024).decode().strip()
print("RDK EVENT:", event)
if event == "MOTION_START":
start_scary_sound()
elif event == "AUDIO_STOP":
stop_scary_sound()
elif event == "SYSTEM_STOP":
stop_scary_sound()
conn.sendall(b"OK")
except Exception as e:
if running:
print("EVENT SERVER ERROR:", e)
# ==========================================
# VOICE RECOGNITION
# ==========================================
recognizer = sr.Recognizer()
microphone = sr.Microphone()
def voice_control():
global running
print("CALIBRATING MICROPHONE")
with microphone as source:
recognizer.adjust_for_ambient_noise(
source,
duration=2
)
print("MICROPHONE READY")
speak("Halloween voice control ready")
while running:
try:
print("\nSAY HALLOWEEN START OR HALLOWEEN STOP")
audio = recognizer.listen(
source,
timeout=None,
phrase_time_limit=4
)
command = recognizer.recognize_google(
audio
).lower()
print("YOU SAID:", command)
# --------------------------
# HALLOWEEN START
# --------------------------
if "halloween start" in command:
response = send_command("START")
if response == "STARTED":
speak("Halloween started")
# --------------------------
# HALLOWEEN STOP
# --------------------------
elif "halloween stop" in command:
response = send_command("STOP")
if response == "STOPPED":
stop_scary_sound()
speak("Halloween stopped")
except sr.UnknownValueError:
print("VOICE NOT RECOGNIZED")
except sr.RequestError as e:
print("GOOGLE SPEECH ERROR:", e)
time.sleep(1)
except Exception as e:
print("VOICE ERROR:", e)
# ==========================================
# MAIN
# ==========================================
try:
print("====================================")
print("WINDOWS HALLOWEEN CONTROLLER")
print("LAPTOP AUDIO + VOICE CONTROL")
print("====================================")
# Start RDK event receiver
threading.Thread(
target=event_server,
daemon=True
).start()
time.sleep(1)
# Start voice recognition
voice_control()
except KeyboardInterrupt:
print("LAPTOP CONTROLLER STOPPED")
finally:
running = False
stop_scary_sound()
pygame.mixer.quit()
print("LAPTOP CLEANUP COMPLETED")
RDK X5 Python programming
The following is the basic GPIO control portion of the RDK X5 program. It assumes the pin numbers are physical BOARD numbers.
Code for RDK X5 kit:
import socket
import time
import threading
import Hobot.GPIO as GPIO
# ------------------------------------
# CONFIGURATION
# ------------------------------------
LAPTOP_IP = "192.168.128.100"
PORT = 5000
PIR_PIN = 15
RED_PIN = 31
GREEN_PIN = 36
BLUE_PIN = 37
HALLOWEEN_ENABLED = False
# ------------------------------------
# GPIO CONFIGURATION
# ------------------------------------
GPIO.setmode(GPIO.BOARD)
GPIO.setwarnings(False)
GPIO.setup(PIR_PIN, GPIO.IN)
# Common anode RGB LED
# HIGH = OFF
# LOW = ON
GPIO.setup(RED_PIN, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(GREEN_PIN, GPIO.OUT, initial=GPIO.HIGH)
GPIO.setup(BLUE_PIN, GPIO.OUT, initial=GPIO.HIGH)
# ------------------------------------
# RGB LED CONTROL
# ------------------------------------
def rgb_control(state):
if state:
# Red ON
GPIO.output(RED_PIN, GPIO.LOW)
GPIO.output(GREEN_PIN, GPIO.HIGH)
GPIO.output(BLUE_PIN, GPIO.HIGH)
print("RGB: HALLOWEEN ON")
else:
# All LEDs OFF
GPIO.output(RED_PIN, GPIO.HIGH)
GPIO.output(GREEN_PIN, GPIO.HIGH)
GPIO.output(BLUE_PIN, GPIO.HIGH)
print("RGB: HALLOWEEN OFF")
# ------------------------------------
# CONNECT TO LAPTOP
# ------------------------------------
def connect_laptop():
while True:
try:
sock = socket.socket(
socket.AF_INET,
socket.SOCK_STREAM
)
sock.connect((LAPTOP_IP, PORT))
sock.settimeout(0.01)
print("Connected to laptop!")
return sock
except Exception as e:
print("Connecting to laptop...", e)
time.sleep(2)
# ------------------------------------
# PIR SENSOR
# ------------------------------------
def read_motion():
motion = GPIO.input(PIR_PIN)
return motion == GPIO.HIGH
# ------------------------------------
# MAIN APPLICATION
# ------------------------------------
def main():
global HALLOWEEN_ENABLED
sock = connect_laptop()
buffer = ""
triggered = False
print("RDK HALLOWEEN PIR SYSTEM READY")
try:
while True:
# ----------------------------
# RECEIVE LAPTOP COMMANDS
# ----------------------------
try:
data = sock.recv(1024)
if not data:
print("Laptop disconnected")
sock.close()
HALLOWEEN_ENABLED = False
triggered = False
rgb_control(False)
sock = connect_laptop()
continue
buffer += data.decode(
"utf-8", errors="ignore"
)
while "\n" in buffer:
command, buffer = buffer.split(
"\n", 1
)
command = command.strip()
if command == "START":
HALLOWEEN_ENABLED = True
triggered = False
print("HALLOWEEN STARTED")
sock.sendall(b"STARTED\n")
elif command == "STOP":
HALLOWEEN_ENABLED = False
if triggered:
sock.sendall(b"RESET\n")
triggered = False
rgb_control(False)
print("HALLOWEEN STOPPED")
sock.sendall(b"STOPPED\n")
except socket.timeout:
pass
except Exception as e:
print("Socket error:", e)
HALLOWEEN_ENABLED = False
triggered = False
rgb_control(False)
try:
sock.close()
except:
pass
sock = connect_laptop()
continue
# ----------------------------
# PIR MOTION MONITORING
# ----------------------------
if HALLOWEEN_ENABLED:
motion = read_motion()
if motion:
if not triggered:
print("PERSON DETECTED!")
rgb_control(True)
try:
sock.sendall(
b"TRIGGER\n"
)
triggered = True
except Exception as e:
print("Trigger error:", e)
else:
if triggered:
print("NO MOTION DETECTED")
rgb_control(False)
try:
sock.sendall(
b"RESET\n"
)
except Exception as e:
print("Reset error:", e)
triggered = False
else:
rgb_control(False)
time.sleep(0.05)
finally:
HALLOWEEN_ENABLED = False
rgb_control(False)
GPIO.cleanup()
sock.close()
if __name__ == "__main__":
main()
Project setup
Pumpkin is cut to make Halloween as shown below

The code is executed on both sides from laptop and RDK X5 kit by USB connection. The required components are interfaced to GPIO pins as shown below.

The arrangement are done to make Halloween scare and final setup is as shown below.
With White light

With Red light

System operation
The project works in the following sequence:
Connect the RDK X5 to the laptop and launch the Python programs.
The system waits for the voice activation command.
When the user says "Halloween start scaring", voice recognition activates the scare mode.
The RDK X5 begins monitoring the PIR sensor through GPIO pin 15.
When a person enters the detection area, the PIR sensor sends a signal to the RDK X5.
The RDK X5 activates the RGB LED and sends a motion notification to the laptop.
The laptop plays the scary MP3 audio through its speaker.
When the user says "Halloween stop scaring", the system disables motion monitoring, stops audio playback, and switches off the RGB LED.
Halloween pot used in the project.
During White light the video demo
During scare color the Halloween
Conclusion:
The Voice-Controlled Halloween Scare System successfully demonstrates the integration of voice recognition, motion detection, embedded GPIO control, RGB LED indication and audio playback. The RDK X5 acts as the main hardware controller, while the laptop handles voice commands and scary audio playback. By combining these technologies, the project provides an interactive Halloween experience in which motion detection and audio effects can be controlled through simple voice commands.
Attachments
References
RDK X5 Hardware Introduction – Board interfaces and GPIO overview.
https://developer.d-robotics.cc/rdk_doc/en/Quick_start/hardware_introduction/rdk_x5/
RDK 40-pin GPIO Pin Definition – Physical pin configuration.
https://d-robotics.github.io/rdk_x_doc/en/Basic_Application/01_40pin_user_sample/40pin_define/
Using GPIO with Python – Hobot.GPIO library, input/output operations and examples.
https://d-robotics.github.io/rdk_x_doc/en/Basic_Application/01_40pin_user_sample/gpio/
RDK Studio Documentation – Supported hardware and development environment.
https://d-robotics.github.io/rdk_studio_doc/en/product-intro/supported-hardware/
Vosk Official Website – Offline speech recognition documentation.
Vosk GitHub Repository – Source code, installation and implementation examples.
https://github.com/alphacep/vosk-api
Vosk Python Documentation – Python API for microphone-based voice recognition.
https://github.com/alphacep/vosk-api/tree/master/python