# Control an LED With Your Voice using Watson and Raspberry Pi

## Overview

https://youtu.be/Wvnh7ie3D6o

In this lesson, you will learn how to connect&nbsp;a Raspberry Pi to&nbsp;[Watson Speech to Text](https://www.ibm.com/watson/developercloud/speech-to-text.html)&nbsp;and change the color of a LED through speech.

For example, you may say "Turn the light green" to change the color of the LED to green.

![](https://cdn-learn.adafruit.com/assets/assets/000/040/298/medium800/leds_Screen_Shot_2017-03-19_at_5.51.28_PM.png?1489960316)

# Control an LED With Your Voice using Watson and Raspberry Pi

## Parts

## What's in the Kit
### Part: Raspberry Pi 3
quantity: 1
Raspberry Pi 3
[Raspberry Pi 3](https://www.adafruit.com/products/3055)

### Part: Mini USB Microphone
quantity: 1
So TJ Bot can hear you
[Mini USB Microphone](https://www.adafruit.com/product/3367)

### Part: NeoPixel RGB LED
quantity: 1
TJ's indicator light
[NeoPixel RGB LED](https://www.adafruit.com/product/1734)

### Part: Female/female jumper wires
quantity: 1
To connect LED to the Pi
[Female/female jumper wires](https://www.adafruit.com/product/1951)

### Part: Female/male jumper wires
quantity: 1
To connect micro servo to the Pi
[Female/male jumper wires](https://www.adafruit.com/product/1953)

### Part: Micro servo motor
quantity: 1
TJ's arm motor
[Micro servo motor](https://www.adafruit.com/product/169)

### Part: 16GB SD card
quantity: 1
Pre-loaded with NOOBS 2.1 
[16GB SD card](https://www.adafruit.com/product/1583)

### Part: Mini USB speaker
quantity: 1
So TJ Bot can speak back to you
[Mini USB speaker](https://www.adafruit.com/product/3369)

### Part: 5V power supply
quantity: 1
Power cable for the Pi
[5V power supply](https://www.adafruit.com/product/1995)

![](https://cdn-learn.adafruit.com/assets/assets/000/040/276/medium800/leds_imgj.jpg?1489941528)

# Control an LED With Your Voice using Watson and Raspberry Pi

## Prepare Your Pi

Start with a working Raspberry Pi with Raspbian or NooBs. You may need to [burn the SD card,](../../../../adafruit-raspberry-pi-lesson-1-preparing-and-sd-card-for-your-raspberry-pi) then log in ([ssh is recommended](https://www.raspberrypi.org/documentation/remote-access/ssh/)) or use an HDMI monitor + keyboard. Then [set up WiFi](../../../../adafruits-raspberry-pi-lesson-3-network-setup/)or connect an Ethernet cable for networking so you can connect to the internet

### 

Raspberry Pi is a small linux computer that we use to connect to Watson and control TJBot's hardware. Similar to any other computer, you need a monitor, mouse, and keyboard.&nbsp;

If you have a TV around, you can connect your Pi to your TV via a HDMI cable.

In most of the Pi kits, the SD card is already preloaded with an image of the Raspberry Pi Operating System (OS). You need to put the SD card in the Pi, turn the Pi ON and follow the instructions on screen to complete the installation of the operating system. If you have problems setting up your Pi, you can troubleshoot&nbsp;[here](https://www.raspberrypi.org/learning/hardware-guide/).

### 

[Here is an easy way to get your Pi connected to wifi](https://www.raspberrypi.org/documentation/configuration/wireless/). If it doesn't work, you need to set it up from the command line.

Open a terminal and type the following command to edit the configuration file with your wifi information:

```
sudo nano /etc/wpa_supplicant/wpa_supplicant.conf
```

Go to the bottom of the file and add the following:&nbsp;

```
network={ 
    ssid="Name_of_your_wifi_network"
    psk="Your_wifi_password"
}
```

Now save the file by pressing&nbsp;Ctrl+X&nbsp;then&nbsp;Y, then press&nbsp;Enter. Open a browser and check if your Pi is connected to the Internet. If you have problems, troubleshoot&nbsp;[here](https://www.raspberrypi.org/documentation/configuration/wireless/wireless-cli.md).

# Update and Download

You should begin by making sure your Pi OS is up to date. Updating the OS may take about 45 min to an hour depending on your internet speed. You just need to stay patient and finish this step. The rest of the steps are much&nbsp;quicker!

For updating the OS, open a terminal&nbsp;and execute the following commands:

```
sudo apt-get update
sudo apt-get dist-upgrade
```

Now install the latest version of Node.js and npm (Node Package Manager). You need these packages later to run your code.&nbsp;

```
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

sudo apt-get install alsa-base alsa-utils libasound2-dev
```
# Control an LED With Your Voice using Watson and Raspberry Pi

## Assemble TJBot

Here are two&nbsp;quick videos of how to fold the bot. The detailed folding instructions are available on instructable:&nbsp;[Build TJBot out of Cardboard](https://www.instructables.com/id/Build-TJ-Bot-Out-of-Cardboard/)

https://youtu.be/bLt3Cf2Ui3o

https://youtu.be/k928MQmD0oc

Once your TJBot is ready, get ready to connect your LED to the Pi Pins.

Danger: 

![](https://cdn-learn.adafruit.com/assets/assets/000/040/277/medium800/leds_led.png?1489942866)

Connect the GND to GND pin on the Pi (see the picture). Then connect 'Data in', the 4th leg from the flat side, to the Pi's GPIO pin. Lastly, connect the third leg from the flat side to the 3.3V on the Pi.

![](https://cdn-learn.adafruit.com/assets/assets/000/042/869/medium800/leds_pi.png?1498075764)

# Control an LED With Your Voice using Watson and Raspberry Pi

## Download the Source Code and Install Dependencies

The source code is available at [github](https://github.com/ibmtjbot/tjbot/tree/master/recipes/conversation). Download or clone the code and execute the following commands from a terminal to install its dependencies..

```
sudo apt-get install git
[git clone https://github.com/ibmtjbot/tjbot.git](https://github.com/ibmtjbot/tjbot.git)cd tjbot/recipes/speech_to_text
npm install
```
### 

[Here are the instructions](https://help.github.com/articles/cloning-a-repository/)&nbsp;for how to clone a repository from github if you have not done that before.

# Control an LED With Your Voice using Watson and Raspberry Pi

## Update Your Bluemix Credentials

In this step, we help you get API access to the Watson Speech to Text. Let's start with&nbsp;[creating a Speech to Text instance on Bluemix&nbsp;](https://console.ng.bluemix.net/catalog/services/speech-to-text)(If you don't have a Bluemix account, follow&nbsp;[the instructions](https://developer.ibm.com/predictiveanalytics/wp-content/uploads/sites/48/2015/09/Getting-Started-with-Watson-Services-on-Bluemix.pdf)&nbsp;to create a free trial).

You may leave the default values and select 'Create'.

&nbsp;

![](https://cdn-learn.adafruit.com/assets/assets/000/040/280/medium800/leds_bluemix3.png?1489943418)

Almost done! You just need to copy your credentials to the clipboard.&nbsp;  
Click on 'Service Credentials' on the left menu and copy your credentials into the clipboard.

![](https://cdn-learn.adafruit.com/assets/assets/000/040/281/medium800/leds_bluemix4.png?1489943475)

Now make a copy of the default config file:

```
cd tjbot/recipes/speech_to_text
cp config.default.js config.js
```

Open **config.js** file using your favorite text editor and update it with your username and password.

![](https://cdn-learn.adafruit.com/assets/assets/000/041/326/medium800/leds_api.jpg?1493405440)

### 

No worries, it's super easy!! All you need to do it [to watch this&nbsp;video.](https://youtu.be/s7wmiS2mSXY)&nbsp;It's one of my favorite videos to explain what an API is!

### 

So you've updated the config file and it still doesn't work! No worries.

Most people mix up username and password and paste password instead of username.

Make sure you copy and paste 'username' and 'password' in the right fields. This should solve your problem.

# Control an LED With Your Voice using Watson and Raspberry Pi

## Run the Code and Speak to TJBot

Congradulations! You are almost done! Now it's the time to have some serious fun!

Run this command from the terminal:

```
sudo node stt.js
```

You should be able to&nbsp;speak&nbsp;to TJBot and ask him&nbsp;to change the color of the LED.&nbsp;

Say "Turn the light blue" to change the light to blue. You can try other colors: yellow, green, orange, purple, magenta, red, blue, aqua, white). You can either say "Turn the light on" or "Turn the light off"!

Enjoy! Don't forget to share a picture/video of your setup&nbsp;#TJBot! :-)

### 

You can either run one of the available recipes or create your own. My favorite recipe is to connect TJBot to twitter and have him understand emotions. Here&nbsp;are a set of simple things you can do&nbsp;with TJBot!&nbsp;[https://www.instructables.com/howto/tjbot/](https://www.instructables.com/howto/tjbot/)

TJBot is open source and we'd love to see what you can make with it. If you have created your own recipe, I&nbsp;would love to include it as a&nbsp;[featured recipe!](https://github.com/ibmtjbot/tjbot/tree/master/featured)

I&nbsp;cannot wait to see what you build with TJBot!

### 

No worries, you&nbsp;can easily fix it.

You may test your LED setup to make sure the connections are correct and the library is properly installed. When you run the test module, it should turn your LED on.

```
cd tjbot/bootstrap/tests 
npm install 
sudo node test.led.js
```

If the LED does not light up, you can try moving the power from 3.3 to 5 volts, by moving the jumper wire one pin to the right (pin 2). If neither the 3.3v or 5v pins work, you will need a 1N4001 diode. The diode is inserted between the power pin of the LED (the shorter of the two middle pins) and the 5v pin on the Raspberry Pi. Make sure the cathode (striped end) is facing the LED. If you have problems with the setup, please refer to Adafruit's Neopixel on Raspberry Pi guide to troubleshoot.

The LED library uses the PWM module (GPIO 18) to drive the data line of the LEDs. This conflicts with the built-in audio hardware, which uses the same pin to drive the audio output. Depending on your configuration of Raspbian, the sound drivers may be more aggressive in taking away control of GPIO 18 from other processes. If your LED shows random colors instead of the expected color, use this trick to fix it.

```
cd tjbot/bootstrap
```

```
sudo cp tjbot-blacklist-snd.conf /etc/modprobe.d/ sudo update-initramfs -u
```

Reboot and confirm no "snd" modules are running by executing the command "lsmod".

```
lsmod
```

&nbsp;

### 

When you speak with TJBot, it records your voice command (audio) through the microphone and sends it to "Watson Speech to Text" to convert the audio to text. Sometimes, when the environment is noisy, TJBot has a hard time differentiating your voice from the background noise. If you have a better quality microphone, please feel free to use it. Otherwise, we recommend speaking clearly in a relatively quiet space.

Also if you have accent, TJBot may have a hard time understanding you. TJbot&nbsp;gets better everyday. So hopefully one day your TJBot friend&nbsp;will be able to understand %100 of what you say!


## Featured Products

### IBM TJBot – A Watson Maker Kit

[IBM TJBot – A Watson Maker Kit](https://www.adafruit.com/product/3462)
[Discontinued - **you can grab&nbsp;** Google AIY Voice Kit for Raspberry Pi V2](https://www.adafruit.com/product/4080)**[instead](https://www.adafruit.com/product/4080)!&nbsp;**

Say hello to your new little friend –&nbsp;it might just say...

No Longer Stocked
[Buy Now](https://www.adafruit.com/product/3462)
[Related Guides to the Product](https://learn.adafruit.com/products/3462/guides)

## Related Guides

- [Raspberry Pi I2C Clock Stretching Fixes](https://learn.adafruit.com/raspberry-pi-i2c-clock-stretching-fixes.md)
- [3D Printed Glowing Mace Prop](https://learn.adafruit.com/3d-printed-glowing-mace-prop.md)
- [Glowing Birthday Number Crown](https://learn.adafruit.com/glowing-birthday-number-crown.md)
- [Glowing Bottle Castle and Capacitive Touch Piano](https://learn.adafruit.com/glowing-bottle-castle-and-capacitive-touch-piano.md)
- [Raspberry Pi Azure IoT Hub Dashboard with CircuitPython](https://learn.adafruit.com/raspberry-pi-iot-dashboard-with-azure-and-circuitpython.md)
- [Raspberry Pi Video Looper 2](https://learn.adafruit.com/raspberry-pi-video-looper-2.md)
- [What's in the Box86? More gaming possibilities on Pi!](https://learn.adafruit.com/box86-gaming-on-arm-raspberry-pi.md)
- [IRIS LED and Prop Guards](https://learn.adafruit.com/iris-leds-prop-guards.md)
- [LED Friendship Bracelet](https://learn.adafruit.com/nautical-led-bracelet.md)
- [reef-pi Guide 5: Light Controller](https://learn.adafruit.com/reef-pi-lighting-controller.md)
- [Getting Started with Raspberry Pi Pico and CircuitPython](https://learn.adafruit.com/getting-started-with-raspberry-pi-pico-circuitpython.md)
- [Simon Game for PyRuler and CircuitPython](https://learn.adafruit.com/simon-game-with-pyruler-and-circuitpython.md)
- [Working with I2C Devices](https://learn.adafruit.com/working-with-i2c-devices.md)
- [RPi Stock Alert Alarm](https://learn.adafruit.com/rpi-stock-alert-alarm.md)
- [Quickstart - Raspberry Pi RP2040 with BLE and CircuitPython](https://learn.adafruit.com/quickstart-raspberry-pi-rp2040-with-ble-and-circuitpython.md)
