Smart Home Voice Recognition Control System You Must Try with micro:bit
With the continuous advancement of technology, smart home systems have become an integral part of people's lives. They connect various devices, enabling home automation, intelligence, and convenience. To facilitate easier interaction with smart homes, this project will utilize micro:bit and AI voice recognition module, along with actuators such as LED lights, fans, and servo motors. With the assistance of the MakeCode programming platform, we will create a smart home AI voice control system. Users can effortlessly control household devices with simple voice commands, enhancing the system with more powerful interaction and control capabilities.
Task Objective
Control the LED light, fan, and servo individually by using voice control commands: "Turn on the lights/turn off the lights," "Turn on the fan/turn off the fan," and "Open the window/close the window.
Materials List
Software Preparation
Programming Software:Microsoft MakeCode for micro:bit
Voice Recognition Plugin:https://github.com/DFRobot/pxt-DFRobot_voiceRecognition.git
Hands-on Practice
To control household appliances through voice commands, the process involves first putting the voice recognition module into a state of voice recognition, and then issuing the corresponding control commands to activate the actuators for the desired operations. Therefore, we can divide this project into the following two tasks to accomplish:
Task Description 1:AI Voice Wake-up
Wake up the voice recognition module using the wake-up phrase "Hello robot." After successful wake-up, the module will automatically enter the state of voice recognition.
Task Description 2:AI Voice Control System
Once the module enters the state of voice recognition, you can control the LED light, fan, and servo motor by speaking the corresponding voice control commands such as "turn on the light/turn off the light," "turn on the fan/turn off the fan," and "open the window/close the window".
Task Description 1:AI Voice Wake-up
1. Hardware Connection
Connect the voice recognition module to the 5V I2C interface on the expansion board. Set the communication switch on the module to the I2C position, and set the speaker switch to the SPK1 position.
2. Software Preparation
Create a new project: Copy the MakeCode URL "Microsoft MakeCode for micro:bit," open it in your browser, click on "New Project," modify the project name to "Smart Home Voice Control System," and then click "Create".
Add Plugin: After successfully creating the project, enter the programming interface. Click on "Extensions" in the Blocks area, enter the plugin link "https://github.com/DFRobot/pxt-DFRobot_voiceRecognition.git " in the search bar, click "Search," find the "voiceRecognition" plugin and click on it to complete the plugin addition.
2. program coding
After connecting the voice recognition module to the I2C interface, how can you use it? Firstly, in the "on start" program, use the command "Voice Recognition setup I2C mode address 0x64" to initialize the voice recognition module.
The module comes with a built-in speaker that can be used for voice interaction. Therefore, use the "set volume" command to set the speaker's playback volume to 4.
Use the "set wake time" command to set the voice recognition module's standby duration to 20 seconds.
How can you wake up the voice recognition module? Use the "play" command and use the "wake-up words" command in the corresponding ID. Select "Hello robot" so that you can wake up the voice recognition module with the wake-up word "Hello robot".
Finally, under the "More" section in the voice recognition command area, select the "set mute mode off" command to disable the mute mode of the voice recognition module.
The complete program is as follows:
Complete program link:https://makecode.microbit.org/_ejmE3AJ4gVbz
3. Running the Program
Connect the micro:bit to your computer using a USB cable, then click the "Download" button. After successful program download, insert the micro:bit into the expansion board, and then provide power to the expansion board using a USB cable. You will hear "Welcome to use the voice recognition module".
At this point, we can wake up the voice recognition module using the wake-up words "Hello robot". The ASB indicator light on the module will illuminate. If there is no conversation for more than 20 seconds, the voice recognition module will go offline automatically, and the ASB indicator light on the module will turn off. The complete dialogue is as follows:
Note: After 20 seconds, the voice recognition module will go offline. You can wake up the voice recognition module again using the wake-up command.
Task Description 2:AI Voice Control System
The voice recognition module utilizes a brand-new offline voice recognition chip, which includes 121 commonly used fixed command words for us to use. Now, let's use these built-in command phrases as audio commands.
1. Hardware Connection
2. program coding
To complete this program based on Task 1, how can we utilize the fixed command phrases? Within the "Forever" command, use the "identify once and save the results" instruction to recognize and save the words spoken to the voice recognition module.
Next, use conditional statements "if...then" and the "recognized it?" instruction to determine if audio commands have been detected. Once a voice command word is recognized, you'll need to use conditional statements to check if the recognition result matches any of the fixed command phrases. Utilize the comparison operator "=" to compare the "get the result" instruction with the "fixed command words open window ID" instruction.
Using the same approach, apply the following method to evaluate the remaining five fixed command phrases.
Finally, below the conditional checks for the fixed command phrases, use the "servo write pin P1 to" command to set the corresponding degree for the servo motor; use the "digital write pin P0 to" command to set the state of the LED light; use the "digital write pin P2 to" command to set the state of the fan. The complete program is as follows:
Complete program link:https://makecode.microbit.org/_DbKH0m0e0Hae
3. Running the Program
Click on "Download." After the program has been successfully downloaded, disconnect the USB cable from the micro:bit and provide power to the expansion board. Next, you can wake up the voice recognition module by saying the wake-up word "Hello robot". Then, use the voice command words to control the servo, fan, and LED light.
Knowledge background
1. Understanding Sound Waves.
We can produce sound, hear sound, and perhaps you've even laid your hand on a speaker to feel the vibrations after sound is emitted. If not, you can lightly place your hand on your throat while speaking to feel these vibrations. Fast or slow, strong or weak, these vibrations create sound. Did you know that sound can be "seen"? All we need to do is capture the variations in the speed and strength of these vibrations, and we can visualize sound. Nowadays, many devices store sound like this—take, for example, the built-in voice recorders in computers and phones. These are all representations of sound waves obtained through certain processes.
1. Introduction to Voice Recognition Module
During human-to-human communication, we quickly comprehend the meanings of simple commands because our brains rapidly process sound information. However, in the process of human-machine interaction, machines cannot directly understand the meaning of natural language. Professionals need to transform our voice into a series of processes involving code, numbers, and signals to create a signal that machines can recognize. This technology, which enables machines to recognize human language, is called voice recognition technology.
The project employs a voice recognition module that can recognize speech without requiring an internet connection. This module incorporates a new offline voice recognition chip, containing 121 built-in fixed command words. It also includes a new self-learning feature for command phrases, which can be learned from various sounds such as whistling, finger snapping, or a cat's meow, extending support for up to 17 custom command words. The module employs dual-microphone sound collection for enhanced noise resistance and extended recognition distance. Equipped with an onboard speaker and an external speaker interface, the module provides real-time voice feedback on recognition results.
Note: The built-in fixed command words and module features can be viewed by clicking on the voice recognition module for more information.
Challenge Yourself
In this project, we have successfully demonstrated the control of the fan, LED light, and servo motor by using fixed command phrases. Now, let's take it a step further. Give it a try and use the fixed command phrases "Play music/Stop playing" as audio commands to control the buzzer on the expansion board!
If you are interested in other micro:bit voice control projects, you can click to view:micro:bit Vehicle Voice Control System