Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to control home or office appliances using voice recognition

By EG Projects May 24, 2021

Voice-controlled assistants that respond to human speech and commands are no longer a novelty. It’s estimated that one in every four adults in America owns a smart speaker, such as Google Home or Amazon’s Echo. These devices offer a point of communication between you and your connected devices, providing convenience and support by automating certain functions.

In this tutorial, we’ll cover how you can control home or office appliances using voice recognition and the Message Queuing Telemetry Transport (MQTT) protocol. MQTT is an OASIS standard messaging protocol for the Internet of things (IoT).

For this project, we use Google’s Speech API within Python’s programming language to ensure what’s spoke is understood and that the voice commands match specific conditions. We’ll also use the MQTT to send control signals to the appliance.

Components required

Tools

  • Arduino IDE
  • Python 2.7

Libraries

Circuit diagram
The board is connected to a light switch using a relay circuit. It’s also possible to use the Arduino UNO board instead of a customized one.

Technical considerations
We used Python 2.7 to write the code and our computer’s microphone to record what’s said for this project.

What’s ideal is the speech is easily converted to text in Python by using the Speech_recoginition library. The text is converted to the computer’s “voice” by using the ttysx library. And, Python’s paho-mqtt library supports the communication for the MQTT.

Block diagram

Note: The computer system receives speech via its microphone and converts it, so that it can properly recognize any commands. The computer sends signals to the MQTT with the support of a router, which is connected to an online broker. The control device is also connected to this same MQTT broker.

How it works

  • The control device, which is inside the board, first must be connected to one’s home or office Wi-Fi router. It will wait for any command signals on the “ts/light” topic.
  • When we begin the recognizer script, the device begins to “listen.” Anything spoken will be recorded and converted to text.
  • This speech is saved inside a string and that string is compared with a set of specific commands. If the commands match, control signals are sent to the MQTT. For example, if a speaker says “lights on,” the speech is converted into string. That string is, then, analyzed for the words “lights on.” When the words are found and matched, the device sends an “ON” signal to the MQTT broker.
  • Another device — the one that’s inside the switchboard socket — receives the command and turns the light on.

The code
The code can be divided into two parts.

1. Voice recognition
When the system is turned on, it creates the connection with the MQTT broker: “broker.hivemq.com”.

client.connect(mqtt_broker, mqtt_port, 60)

A function begins to record any words picked up by the microphone and converts them into text.

while 1:
    data = recordAudio()
data = r.recognize_google(audio)

A string of data (which includes the spoken words) is passed inside the “assti(data)” function, where the speech is analyzed for any specific commands.

if (“lights on” in data):
        send(“ON”)
        speak(“light is On!”);
        print “Light is on!”
    if (“lights off” in data):
        send(“OFF”)

If the condition is matched (meaning the words match the commands), a signal is sent using the “send(msg)” function to the MQTT.

def send(msg):
    publish.single(mqtt_publish_topic, msg, hostname=mqtt_broker)

2. Network communication
A common subscription is created and published in the ESP.

const char* topicSubscribe = “ts/light”;
const char* topicPublish = “ts/report”;

To access the network, we’re using the ESP8266 WiFi chip and ATmega328 is a single-chip microcontroller. Anything sent from the ATmega328 via the serial is directly published as a control signal to the “ts/light” topic.

if (Serial.available()) {
    String recivedData = Serial.readString();
    temp_str = recivedData;
    char temp[temp_str.length() + 2];
    temp_str.toCharArray(temp, temp_str.length() + 1);
    client.publish(topicPublish, temp);
  }

Note the code snippet of the ESP8266. Anything received over the MQTT is sent to the serial port from the ESP and to the ATmega328p.

void Received_data(char* topic, byte* payload, unsigned int length) {
  data_r_in_string = “”;
  for (int i = 0; i < length; i++) {

    data_r_in_string  =  String(data_r_in_string + (char)payload[i]);
    //Serial.print((char)payload[i]);
  }
  Serial.print(data_r_in_string);}

This is a short Python script that converts the voice-to-text. It’s possible to include additional commands or functionality, such as AI in the scripts. This would mean they would work as personal, virtual assistants.

 

You may also like:


  • What are the top development boards for AI and ML?

  • How does LoRa modulation enable long-range communication?

  • What are the top open-source software systems for home automation?

  • What are different types of biometric sensors?

  • What are different types of Artificial Intelligence ?

  • What is Artificial Intelligence, Machine Learning, Deep Learning, and Natural…

Filed Under: Electronic Projects
Tagged With: Arduino, python
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Voltage mode pushpull is a nonsense SMPS?
  • Input impedance matching network
  • High Side current sensing
  • The comparison of different Tcl script checkers
  • Reducing "shoot-through" in offline Full Bridge SMPS?

RSS Electro-Tech-Online.com Discussions

  • Is AI making embedded software developers more productive?
  • Back to the old BASIC days
  • Parts required for a personal project
  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe