I’m really starting to love my Arduino lately; After going through the basic tutorials and even making an LED cube, I was ready to tackle something much more complex. Luckily, speaking control over an Arduino project isn’t really as hard as I thought — here are three completely different approaches you can take.
Using OSX Automator and Speakable Items
One way to do this is to use the existing speech command utilities built into OSX; Setting up custom commands to run Automator actions is easy. (If you’re new to Automator, download our free PDF guide to automating your Mac!)
As for the Arduino code, we use a string buffer detailed in this Arduino forum thread — this allowed us to look up exact words in serial communication — without this I found type conversions between numbers , bytes and lines be problematic. Here is the complete Arduino code for listening to serial commands, although you will need to add your own commands and hardware to actually control the devices as this is beyond the scope of this Arduino project guide. If you are using relays, remember that they must withstand voltage 120-240V AC. Also, if you’re new to all of this, be sure to check out the Arduino manual for first turn.
Then download this Arduino-serial utility which allows you to communicate directly with the Arduino from the command line or a shell script. Place this at the root of your user directory, then open a terminal session and type:
сделать ардуино-сериал
compile the package for your system.
Using this utility is quite simple, but for our purposes, start by typing
ls /dev/tty.*
to find out what port your Arduino (USB) is on. Then, to send a command, use:
./arduino-serial -b 9600 -p /dev/tty.usbmodemfd13411 -s lightsOn
Replace /dev/tty.usb~ the exact name you found for your USB port connected to the Arduino. Refer to the original page for more usage examples, including getting the return value, but this will do for now.
One thing I found is that I had to «start» the Arduino by first sending the command with Arduino Serial Monitor and then everything worked fine. If anyone knows why this is so, I’d love to hear.