This project enables voice control of LEDs connected to an Arduino board using Python's speech_recognition, pyttsx3, and PyFirmata2 libraries. Users can turn specific LEDs on or off using voice commands.
- Python 3.x: Installed.
- speech_recognition: Install using
pip install SpeechRecognition. - pyttsx3: Install using
pip install pyttsx3. - PyFirmata2: Install using
pip install pyfirmata2. - Arduino IDE: Installed and configured.
- Arduino Board (e.g., Arduino Uno): Connected to your computer.
- LEDs (Red, Green, Blue, Yellow): Connected to the Arduino.
- 220 Ohm Resistors (4): For current limiting with the LEDs.
- Microphone: Connected to your computer.
- Internet Connection: Required for voice recognition.
-
LED Connections:
- Connect the anode (longer leg) of the red LED to digital pin 6 of the Arduino.
- Connect the anode of the green LED to digital pin 5 of the Arduino.
- Connect the anode of the blue LED to digital pin 7 of the Arduino.
- Connect the anode of the yellow LED to digital pin 8 of the Arduino.
- Connect the cathode (shorter leg) of each LED to ground (GND) through a 220 Ohm resistor.
-
Arduino Connection:
- Connect the Arduino board to your computer using a USB cable.
Here's the circuit diagram for this project:
(The circuit diagram should visually represent the connections described in the Hardware Setup section.)
-
Upload StandardFirmata:
- Open the Arduino IDE.
- Go to
File > Examples > Firmata > StandardFirmata. - Upload the
StandardFirmatasketch to your Arduino board.
-
Install Python Libraries:
- Open a terminal or command prompt.
- Run the following commands:
pip install SpeechRecognition pip install pyttsx3 pip install pyfirmata2
-
Run the Python Script:
- Save the Python code (e.g.,
voice_led_control.py) in a directory. - Open a terminal or command prompt.
- Navigate to the directory where you saved the script.
- Run the script using
python voice_led_control.py.
- Save the Python code (e.g.,
speech_recognition: Captures and recognizes voice commands.pyttsx3: Provides text-to-speech feedback.PyFirmata2: Establishes serial communication with the Arduino board to control the LEDs.takeCommand(): Listens for and recognizes voice commands.speak(text): Converts text to speech.- Main Loop:
- Continuously listens for voice commands.
- Parses commands and controls LEDs accordingly.
- LED Control:
- Uses
pyfirmata2to control digital pins based on voice commands.
- Uses
- Voice Commands:
- "on the red light"
- "on the green light"
- "on the blue light"
- "on the yellow light"
- "light off"
- "thank you" (to exit)
- Error Handling: Includes a
try...exceptblock to catch and print errors.
-
Set Port Number:
- Modify the
portvariable in the script to match your Arduino's serial port (e.g., "COM3", "/dev/ttyACM0").
- Modify the
-
Run the Script:
- Execute the Python script.
-
Give Commands:
- Speak the commands listed in the Code Explanation section to control the LEDs.
- Microphone Permissions: Ensure your OS allows the script to access your microphone.
- Internet Connection: An active internet connection is essential for voice recognition.
- Voice Recognition Accuracy: Accuracy depends on microphone quality and background noise.
- Arduino Pin Configuration: Ensure the pin numbers in your Python code match your hardware setup.
- Firmata: Make sure
StandardFirmatais uploaded to your Arduino.
- Add more voice commands for other actions or LED patterns.
- Modify the text-to-speech voice and rate.
- Integrate with other sensors or actuators.
- Add a GUI for visual feedback.
- Implement a more robust error handling system.
- Improve voice recognition accuracy.
- Add features to control more complex LED animations.
Kritish Mohapatra
MicroPython | ESP32 | Embedded Systems | IoT Projects
GitHub: [https://github.com/kritishmohapatra]
