In this project, you’ll use the UNIHIKER board along with the UNIHIKER Carrier board to control an LED using voice commands. We’ll use a voice recognition module to capture and process voice commands, and then control the LED accordingly.
Components Needed- UNIHIKER Board
- UNIHIKER Carrier Board
- Voice Recognition Module
- USB Cable
Connect the UNIHIKER to the Carrier Board:Ensure the UNIHIKER board is securely connected to the Carrier Board. The Carrier Board should have the IR receiver and LED already integrated. đź”§
Power the Boards:Connect the UNIHIKER Carrier board to a power source using a USB cable. The UNIHIKER Board can be powered through the Carrier. ⚡
Connect the UNIHIKER Board to Your Computer:Use a USB Type-C cable to connect the UNIHIKER Carrier board to your computer. The board will boot up, and you should see the home screen.
Set Up the Programming Environment:Open the Mind+ IDE and select the python.
Next, click on the Blocks and open the extension tab.
Select the UNIHIKER.
Then select the connect to the remote terminal and connect with the UNIHIKER.
Install the PinPong Library:📦The PinPong library is essential for controlling the hardware components. You can install it using the following command in the terminal:
pip install pinpong
Connect the Voice Recognition Module to the UNIHIKER Board:Connect the voice recognition module to the UNIHIKER via the connector cable.
Configure the Voice Recognition Module:
First, we need to add the Voice Recognition libraries to the UNIHIKER and open the \\10.1.2.3\ file share point. Use root as username and dfrobot as a password.
Then copy the below GIT repo to the root directory.
Next, open the Mind+ IDE and navigate to the downloaded directory. And just run.
This Python code can read the Command ID from the Voice Recognition Module and print it on the console.
Follow the module’s documentation to set up and train voice commands. Typically, you’ll need to train it with specific commands like “LED ON” and “LED OFF”. Here I'm using the default id "Turn on the light" and "Turn off the light".
Step 3: Programming the LED with Voice Sensor:Configure the Carrier LED Board LED with Voice Sensor.:Navigate to the Mind+ IDE then open the voice recognition sensor python code.
First, add the librarian to control the carrier board.
from unihiker import GUI
from pinpong.board import Board,Pin,I2C,NeoPixel
from pinpong.extension.unihiker import *
Next, configure the LED and initialize the board.
Board().begin(1)
np1 = NeoPixel(Pin((Pin.P13)),3)
np1.brightness(128)
Create a function to check the command ID and on and off the LED.
def loop():
CMDID = DF2301Q.get_CMDID()
if CMDID != 0:
print("CMDID = %u\n" % CMDID)
u_gui.fill_circle(x=120, y=150, r=80, color="white")
u_gui.draw_text(text=CMDID,x=100,y=100,font_size=20, color="#0000FF")
if CMDID ==103:
np1.range_color(0,2,0x00FF04)
if CMDID ==104:
np1.range_color(0,2,0x000000)
time. Sleep(1)
Run the script in the UNIHIKER:Ensure all connections are secure and power run the Python script in the UNIHIKER board.
Test Voice Commands:Speak the trained voice commands (e.g., "Turn on the LIGHT” and “Turn off the LIGHT”) and observe the LED’s response.
Here is the complete Python script:
import sys
import time
from unihiker import GUI
from pinpong.board import Board,Pin,I2C,NeoPixel
from pinpong.extension.unihiker import *
u_gui=GUI()
# Add the library to the system path
sys.path.append('./lib')
from DFRobot_DF2301Q import DFRobot_DF2301Q_I2C, DF2301Q_I2C_ADDR
from DFRobot_DF2301Q_Commands import CommandWord
Board().begin(1)
np1 = NeoPixel(Pin((Pin.P13)),3)
np1.brightness(128)
# Create instance of the I2C device
DF2301Q = DFRobot_DF2301Q_I2C()
def setup():
DF2301Q.set_volume(15)
DF2301Q.set_mute_mode(0)
DF2301Q.set_wake_time(20)
print("wake_time = %u\n" % (DF2301Q.get_wake_time()))
DF2301Q.play_by_CMDID(CommandWord.HelloRobot) # Common word ID
def loop():
CMDID = DF2301Q.get_CMDID()
if CMDID != 0:
print("CMDID = %u\n" % CMDID)
u_gui.fill_circle(x=120, y=150, r=80, color="white")
u_gui.draw_text(text=CMDID,x=100,y=100,font_size=20, color="#0000FF")
if CMDID ==103:
np1.range_color(0,2,0x00FF04)
if CMDID ==104:
np1.range_color(0,2,0x000000)
time.sleep(1)
if __name__ == "__main__":
setup()
while True:
loop()
ConclusionYou’ve successfully created a voice-controlled LED using the UNIHIKER and UNIHIKER Carrier board! This project can be expanded to control multiple LEDs or other devices using voice commands. Happy tinkering!
If you have any questions or need further assistance, feel free to ask!
Comments
Please log in or sign up to comment.