In this tutorial, you'll learn how to control a servo using your voice! I will be using the PyCharm IDE for this project, but any other method of coding with Python should work. Any servo with 0-180 degrees of rotation will work. I use an Arduino Mega 2560, but any Arduino should work.Intro
IntroIn this tutorial, you'll learn how to control a servo using your voice! I will be using the PyCharm IDE for this project, but any other method of coding with Python should work. Any servo with 0-180 degrees of rotation will work. I use an Arduino Mega 2560, but any Arduino should work.
Wiring the ServoThe red wire on the servo should connect to the 5V pin on your Arduino, and the black (sometimes brown) one will go to the ground pin (GND). The yellow (sometimes orange) wire should go into digital pin 9.
Arduino CodeOpen up a new sketch and go to File>Examples>Firmata>StandardFirmata . Then upload the sketch to your Arduino. Firmata is a special feature that allows your Arduino to communicate with software on your device, like Python. This will setup Firmata so that we can control the servo using Python.
Python CodeAt the bottom of the page is the Python code for speech recognition. Copy and paste it into whatever code editor you are using. Again, I am using PyCharm.
This code will access your computers microphone to listen for voices. Using a pretrained speech recognition model, it can discern words. Our code collects the audio in real time, extracts the words and converts it into text, checks if the word was a number, and if it was, it will make the servo angle move to the number spoken.
Final ResultPlug in your Arduino to your computer, with the servo wired up and the Arduino code uploaded. Then, run the Python code. Say a number between 0 to 180 and watch the servo move to the desired position!
Comments
Please log in or sign up to comment.