Build a Waving Robot Using Watson Services - TJBot Edition




Introduction: Build a Waving Robot Using Watson Services - TJBot Edition

About: Developer, Designer, Researcher

This instructable guides you through connecting a servo motor to your TJBot (or any Pi) and making your robot "wave", and "dance to a song" based on voice commands. You will use

  1. Watson Speech to Text to convert your voice to text,
  2. Watson Text to Speech to "read" out a response.
  3. Some Nodejs code (github).

Hint: Its super cute when this little guy speaks, waves and "dances" to music.

This instructable is based on the recently launched IBM TJBot robot, here are some links and background information to view before you start:

  1. What is the IBM TJBot Robot ?

    IBM TJBot is a DIY kit that allows you to build your own programmable cardboard robot powered by IBM Watson Services. It consists of a cardboard cutout (which can be 3D printed or laser cut), Raspberry Pi and a variety of add-ons – including a RGB LED light, a microphone, a servo motor, and a camera.

  2. How can you get it ?

    You can lasercut it from cardboard or 3D print it. See more here.
  3. Are there Other TJBot Instructables?

    Yes! Infact, TJBot has a few other instructables, head over to the TJBot instructables page.
  4. Why is it a good project ?

    Well, one cool aspect of this is that you can easily hook it up to a variety of IBM Watson Services and implement neat use cases (like the use case here). Examples of some Watson services you can use are speech to text, text to speech, vision recognition, natural language classification, sentiment/emotion analysis ... etc. Learn more about IBM Watson Services here.

Step 1: Parts

Step 2: Set Up Your Pi

If you have used Raspberry Pi before, install Node.js and go to the next step. Otherwise, follow the instructions to set up your Pi.

  • Getting Started with Your Pi
    Raspberry Pi is similar to a full computer, which means you need a monitor, mouse, and keyboard for it. 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. 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 here.
  • Connect Your Pi to the Internet
    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:


Now save the file by pressing Ctrl+X then Y, then press Enter. Open a browser and check if your Pi is connected to the Internet. If you have problems, troubleshoot here.

  • Install Packages
    Open a terminal application on the Pi and execute the following commands to install the latest version of Node.js and npm (Node Package Manager). You need these packages later to run your code.
sudo apt-get update  
sudo apt-get dist-upgrade
curl -sL | sudo -E bash -
sudo apt-get install -y nodejs

Step 3: Step 3: Prepare the Kit

Assemble TJBot. Detailed instructions are available from another instructable here.

Once your TJBot is ready, plug in your USB microphone, servo motor and get ready to connect your LED to the Pi Pins.

It's very important to make sure you connect the RGB LED to the right pins, otherwise you may damage your LED or the Pi. ALWAYS start with the GND pin. GND is the longest leg of your LED. The LED has a flat side. The GND is the second leg from the flat side. Again if you are unsure, DO NOT connect the LED to the Pi.

Step 4: About Servo Motors and Pulse Width Modulation (PWM)

Servo motors are used in remote control vehicles and robotics. Most servo motors are not continuous;
that is, they cannot rotate all the way around but rather just over an angle of about 180 degrees.The position of the servo motor is set by the length of a pulse. The servo expects to receive a pulse at least every 20 milliseconds. If that pulse is high for 1 millisecond, the servo angle will be zero; if it is 1.5 milliseconds, it will be at its center position; and if it is 2 milliseconds, it will be at 180 degrees. Depending on the library you chose to use in generation your pulse width modulation signal, there are various ways to control your servo by setting a duty cycle which determines the pulse frequency.

On a raspberry Pi, PWM is available on a dedicated hardware pin GPIO Pin (GPIO18, Pin 12). Sometimes, when you have multiple devices that need PWM (e.g. LEDs), you can have software PWM made available on any other pin. In this instructable, we use the dedicated hardware PWM pin for our RGB LED, and use software PWM for the servo.

Wiring Your Servo Motor

Your servo motor has three wires - Power, Ground and Data in. In this recipe I use the Tower Pro servo motor and the wires are as follows - Red (Power), Brown (Ground), Yellow (Data in).

For this recipe, a software PWM library is used to control the servo motor, and I wire my setup as follows.

  • Red (+5v, Pin 2)
  • Brown (Ground, Pin 14)
  • Yellow (Data in, Pin 26, GPIO7 )

Note: In the code, you can always change the pins used.

Step 5: Download Sample Code

The source code is available at GitHub.
Download the code and execute the following commands from a terminal to install its dependencies as well as the ALSA package for audio recording.

git clone
npm install
sudo apt-get install alsa-base alsa-utils

Step 6: Update Bluemix Credentials

In this step, you get API access to the Watson services used in this recipe

Watson Speech to Text.

Let's start with creating a Speech to Text instance on Bluemix: (If you don't have a Bluemix account, follow the instructions to create a free trial account).

You can leave the default values and select 'Create'

Now go to 'Sevice Credentials' on the left menu and copy your credentials into clipboard.

You need to update config.js within your project with your Speech to Text credentials.

Watson Text to Speech

The last stop is the Watson Text to Speech.
You need to use the exact same thing you did with the other two services. You may leave all the default values and select 'create'.

Copy your credentials and add them to config.js.

Step 7: Test Your Servo

Before running the main code (voice + wave + dance etc), you may test your LED setup and your Servo motor to make sure the connections are correct and the library is properly installed. When you run the test module, it should turn your LED to different colors and wave your robot arm at intervals.

    sudo node wave_test.js

If the LED does not light up, you can try moving the power from 3.3 to 5 volts. 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.

If your robot arm does not respond, kindly confirm you have connected it correctly. See the PIN diagram here for more information on raspberry pi PINS.

Step 8: Run the Code

Start the application. (Note: you need sudo access)

    sudo node wave.js     

Then you should be able to speak to the microphone. Sample utterances are

  • Can you raise your arm ?
  • Can you introduce yourself ?
  • What is your name ?
  • Can you dance ?

Step 9: Whats Next ?

There are a few things you can do .. and ways to take your robot forward!

  • Use Watson Conversation to improve intent detection. Leverage machine learning capabilities within Watson conversation to better match intents even when recognized text is not accurate.
  • Animate robot interactions using arm movements + lights (e.g wave when your robot speaks or laughs etc)
  • Correlate additional data to robot arm movements ... e.g control your robot arm using an app, a wearable/smartwatch etc.
First Time Authors Contest 2016

Participated in the
First Time Authors Contest 2016

Be the First to Share


    • Pets Challenge

      Pets Challenge
    • Tinkercad to Fusion 360 Challenge

      Tinkercad to Fusion 360 Challenge
    • Build a Tool Contest

      Build a Tool Contest



    4 years ago


    how can i add Raspberry pi Camera to this little buddy maybe to Recognise object or take pictures using IBM Visualization service


    4 years ago

    Hi everyone i have manage to setup the TJBOT the only problem is i'm limited to ask TJ question he only answer three or two question after he throws an error below:

    === Watson Speech to Text : An Error has occurred =====

    You may have exceeded your payload quota.

    Error: Session timed out.

    Press <ctrl>+C to exit.

    I wanted to add more intent in Conversation.

    finale how can i setup TJ to run/execute the script automatically when i turn on my Raspberry without typing on cmd manually


    4 years ago

    Building this little guy has been a ton of fun so far! Sadly, I have a problem regarding Audio Output whenever he dances. The music simply doesn't play. Everything seems fine and I can talk with TJBot using other functions like conversation.js. Just music seems to be his weakness right now. I'm using a USB-speaker, if that's relevant.


    5 years ago

    Hi, I found that I also needed M/F jumper wires when using the listed servo. I used these from Amazon:

    Veewon Flexible 20cm Multicolored 40 Pin Male to Female Breadboard Jumper Wires Ribbon Cable Wire (Male to Female)


    Reply 5 years ago

    Thanks for sharing these!


    5 years ago

    Help, I ran into the following problem:
    $sudo node wave.js

    [../deps/mpg123/src/output/alsa.c:165] error: cannot open device default

    node: pcm_params.c:2286: snd_pcm_hw_refine: Assertion `pcm && params' failed.

    2017-05-16 14:49:14 sigHandler: Unhandled signal 6, terminating


    5 years ago


    I'm having some issues....

    I tried running the test wave and I got an error about pigpio..I then tried installing that and got another error...any ideas>


    pi@raspberrypi:~/tjwave $ sudo node wavetest.js


    throw err;


    Error: Cannot find module 'pigpio'

    at Function.Module._resolveFilename (module.js:469:15)

    at Function.Module._load (module.js:417:25)

    at Module.require (module.js:497:17)

    at require (internal/module.js:20:19)

    at Object.<anonymous> (/home/pi/tjwave/wavetest.js:16:29)

    at Module._compile (module.js:570:32)

    at Object.Module._extensions..js (module.js:579:10)

    at Module.load (module.js:487:32)

    at tryModuleLoad (module.js:446:12)

    at Function.Module._load (module.js:438:3)

    pi@raspberrypi:~/tjwave $ npm install pi-gpio

    tjwave@1.0.0 /home/pi/tjwave

    └── pi-gpio@0.0.8

    npm WARN tjwave@1.0.0 No repository field.

    pi@raspberrypi:~/tjwave $ sudo node wave_test.js


    throw err;



    Reply 5 years ago

    Hi ...
    The right way to install pigpio (and all other dependencies) would be to run
    npm install ... in your home directory. Have you been able to do this ?


    Reply 5 years ago

    Thank you. I didnt realize I was missing dependencies. I got the arm to move and the led to light up with test..but when I run the main code I get auth errors..I put my credentials in config,js...any ideas?

    pi@raspberrypi:~/tjwave $ sudo node wave.js


    throw new Error('Argument error: username and password are required unless use_unauthenticated is set');


    Error: Argument error: username and password are required unless use_unauthenticated is set

    at SpeechToTextV1.BaseService.initCredentials (/home/pi/node_modules/watson-developer-cloud/lib/base_service.js:78:15)

    at SpeechToTextV1.BaseService (/home/pi/node_modules/watson-developer-cloud/lib/base_service.js:45:18)

    at new SpeechToTextV1 (/home/pi/node_modules/watson-developer-cloud/speech-to-text/v1.js:64:15)

    at Object.value (/home/pi/node_modules/watson-developer-cloud/index.js:92:16)

    at Object.<anonymous> (/home/pi/tjwave/wave.js:26:29)

    at Module._compile (module.js:570:32)

    at Object.Module._extensions..js (module.js:579:10)

    at Module.load (module.js:487:32)

    at tryModuleLoad (module.js:446:12)


    Reply 5 years ago

    Glad you could get the arm and LED moving!
    The error you see suggests that your credentials have not been entered into config.js or you may have entered it into a config.js file in a different directory.

    Please ensure that your credentials are in the file exactly named config.js and not config.default.js or config.sample.js. Also ensure that you have config.js in the correct folder. This should work out well.



    Reply 5 years ago

    Thanks for the prompt responses! I'm still having the same issue:( I hate to keep bothering you...but I've come so far. I can verify that the config file is in the tj wave directory:

    pi@raspberrypi:~/tjwave $ ls

    config.js node_modules photos wave_conversation.js workspace.json

    dance.js output.wav wave.js

    images package.json sounds wavetest.js


    I think there may be something within the config file that I'm doing wrong. I have added my my STT username and PW but left the STT customization with Xs (untouched).

    I have set the TTS PW and username fine. I added the Watson Conv PW and username but left the workspace field with X's (untouched) I left the vision api credentials with Xs (untouched).

    Do you see any issue in my description?


    Reply 5 years ago

    From your description, all appears to be ok!
    I just looked through the config.default.js file, and see there are some case difference (error on my part ... missed that in a recent change). Its possible that in our config file the variable name case might be slightly difference from whats used in wave.js. Specifically ... should be exports.STTPassword and not exports.STTpassword.... sorry about this ...
    Please give it a try and let me know ....
    Also feel free to reach out on or open an issue directly on the github repository ... .

    I look forward to seeing what you build .. post on twitter (#tjbot)

    exports.STTPassword = ''; // Speech to text password
    exports.STTUsername = ''; // Speech to text username
    exports.STTCustomizationid = '' // Speech to text Customization id (if you are using a customized language model)

    //Credentials for Watson Text to Speech service

    exports.TTSPassword = ''; // Text to speech password
    exports.TTSUsername = '';

    // Credentials for Watson Conversation service
    exports.ConPassword = ''; // conversation service password
    exports.ConUsername = ''; // conversation service username
    exports.ConWorkspace = ''; // Conversation workspace id

    // Credentials for Vision Api
    exports.VisionKey = '';
    exports.VisionVersion = '2016-05-19';

    exports.version = 'v1';


    Reply 5 years ago

    THANKS! That fixed it! I have my bot dancing! I have a question about adjusting the volume of TJ's voice against the music (hard to hear his voice). Should I send an e-mail to the address your provided? or should I use github?

    DIY Hacks and How Tos

    Cool robot! Do you have any more info about the rest of the robot.


    Reply 5 years ago


    Thanks! More info on tjbot can be found here .. .

    There are also some really nice instructables on it too