Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • 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
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • 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 Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

Log in to leave a comment:

Lost your password?

Don't have an account? Register here

Submit a Guest Post

submit a guest post

EE TECH TOOLBOX

“ee
Tech Toolbox: Wide Bandgap Semiconductors
Moving from silicon to GaN or SiC feels like a whole new ballgame, doesn’t it? It isn’t just about faster switching; it’s about managing the layout parasitics and thermal realities that come with that speed. This month’s Tech Toolbox features a curated eBook that tackles these design hurdles head-on.

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 feed: EDABOARD.com Discussions. EDABOARD.com Discussions.

  • 【Smart Clock, Unlimited Frequencies on Demand】
  • voltage amplifier for a signal generator
  • Stream Deck plugins for KiCad 10, Windows and Mac
  • Flyback converter working incorrectly
  • ECAL cable position strategy usage

RSS feed: Electro-Tech-Online.com Discussions Electro-Tech-Online.com Discussions

  • Electronics and PIC Programming Assembler Update
  • Merit A-2900 universal audio output transformer
  • PIC code for 2.42" I2C OLED Display?
  • Want Thermal Camera with Fixed Thermal Span option
  • Samsung C21RJAN ceramic hob BUZZER got quieter

Featured Tutorials

LoRa and LoRaWAN: A Complete Guide to Wireless Communication

  • Best practices for securing LoRa networks
    Best practices for securing LoRa networks
  • Understanding LoRa architecture: nodes, gateways, and servers
    Understanding LoRa architecture: nodes, gateways, and servers
  • Revolutionizing RF: LoRa applications and advantages
    Revolutionizing RF: LoRa applications and advantages
  • How to build a LoRa gateway using Raspberry Pi
    How to build a LoRa gateway using Raspberry Pi
  • How LoRa enables long-range communication
    How LoRa enables long-range communication
  • How communication works between two LoRa end-node devices
    How communication works between two LoRa end-node devices
More Tutorials >

Recent Articles

  • Nuvoton and Qt Group add MCU HMI support
  • MicroStrain by HBK adds compact inertial sensors
  • Allegro MicroSystems expands 48V adas portfolio
  • SemiQ previews 1700 V SiC module
  • pSemi adds wideband RF switch

EE ENGINEERING TRAINING DAYS

engineering
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • 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 © 2026 Arrowfly 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 Arrowfly
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Complete Sensor Guide
      • Engineering Deep Dives
      • AI
      • ARDUINO Compatible Coding
      • Audio Electronics
      • Battery Management
      • Beginners Electronics Series
      • Brainwave
      • Digital electronics (DE)
      • Electric Vehicles
      • EMI/EMC/RFI
      • EVs
      • Hardware Filters
      • IoT tutorials
      • LoRa/LoRaWAN
      • Power Tutorials
      • Protocol
      • Python
      • RPI Python Programming
      • Sensors
      • USB
      • Thermal management
      • Verilog
      • 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
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Tech Terms
    • Webinars & Digital Events
  • Resources
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • White Papers
  • Guest Post Guidelines
  • Advertisers
    • Advertise
    • PR Submissions
    • Eblast Submissions
  • Subscribe