Project tutorial
Voice Controlled K'nex Car

Voice Controlled K'nex Car © GPL3+

Use your voice to control your own K'nex vehicle using the Raspberry Pi, Arduino Uno, and Amazon's Alexa.

  • 10,420 views
  • 4 comments
  • 54 respects

Components and supplies

R8326274 01
Raspberry Pi 2 Model B
×1
A000066 iso both
Arduino UNO & Genuino UNO
×1
DC motor (generic)
Drives the Wheels. I used K'nex motors for easy connection to the motor shield.
×2
Servos (Tower Pro MG996R)
For Steering Control (I used Tower Pro MG945 in my car)
×1
Seeed Motor Shield
×1
11026 02
Jumper wires (generic)
×1
Assorted K'nex
×1
Portable Smart Phone Charger
×1
Wifi adapter
×1
A way to talk to Alexa (Seperate Raspberry Pi, Echo, ect.)
×1
A way to access the Alexa Mobile App
×1
Adafruit industries ada830 image 75px
4xAA battery holder
×1
8AA Battery Pack
×1
Internet connection
×1
HDMI cord
×1
Monitor
×1
Mouse
×1
Keyboard
×1
A 16 GB micro SD card
×1
Small breadboard
×1
Adafruit industries ada62 image 75px
USB-A to B Cable
×1
Adafruit industries ada592 image 75px
USB-A to Micro-USB Cable
×1

Apps and online services

About this project

Introduction

Imagine an old toy that you loved to play with. Now add the Raspberry Pi. What do you get?

This is how I came up with my idea for the Voice Controlled K'nex Car.

My project initially began as an investigation into artificial intelligence with the Raspberry Pi. After an hour of research I read about Alexa on Raspberry Pi's official blog. Further research led me to the "Internet of Voice Challenge" on Hackster. As I watched the introduction video, I could only imagine the infinite implementations.

That evening, I had only one question in mind: "How could I make an Internet of Things idea that was not only enjoyable to the end user, but also allowed the user to be creative in their own way?"

When I was younger, I collected K'nex sets and absolutely loved to build enormous roller coasters, ball machines, and even structures for electric train sets. This love of K'nex sparked my answer to my question: "What if I added the ability for Alexa to control a Raspberry Pi powered K'nex car?"

After several weeks of studying and development, I produced a working Alexa skill. As a 16 year old, this type of real world development was very instructive. I enjoyed every process from the initial development to the final certification of the Alexa skill to submitting my project.

How does my project work?

My project has 4 parts. As we go though each part, I will describe the part's processes and will give you a walk-through on how to construct each part. Please note that I have two creation methods, Simple and Advanced.

Simple is for those who what to make the car without going in depth into the code. Advanced is for those who want to add on to the project and make it their own.

Let's begin!

Part 1: The Alexa Skill

My Alexa skill was written in Node.js and is hosted on Amazon's Lambda web service. To open the skill, simply say "Alexa, open unofficial Raspberry Pi car." Alexa will send you a card on your Alexa app containing your session id. This id will need to be entered into the Raspberry Pi later on. By asking the skill for help or referencing the Voice User Interface Diagram provided below, the user should be able to navigate the skill with ease. When the user gives a command to the car, the request is sent through a PubNub virtual device. This is where the communication between the skill and the Raspberry Pi takes place.

How to set up:

Simple:

1.) Enable my published skill for use with your Alexa enabled device.

2.) You may now see if the skill is enabled by saying, "open unofficial raspberry pi car".

3.) After the skill is enabled, you can move on to the Arduino Uno set up. Remember to follow the Simple creation method.

Advanced:

1.) Go to PubNub.com and create a profile.

2.) Add a new device.

3.) Click on your newly added device.

4.) Make note of both the Publish Key and Subscribe Key.

5.) Create a AWS account.

6.) Navigate to the Lambda service.

7.) Create a new Lambda function.

8.) Skip the next screen

9.) Select the gray box and pick "Alexa Skills Kit"

10.) Download my Git repository here. Extract it and navigate to the AlexaSkill folder.

11.) Edit the "index.js" file and find the line that defines "iotCloud". Copy your publish key and subscribe key into their respective inputs.

*Note: If you do not want to have a randomly generated session ID, you can create a custom one by commenting out the line where "myChannel" is defined. You can then use the line above it as a template on how to define "myChannel" to a custom name. Remember this name, because you will need it when setting up the Raspberry Pi.

12.) Send it to a compressed zip folder.

13.) Give it a name and description. Choose the Upload Zip option as the code entry type.

14.) Navigate to your zip file and upload it to Lambda.

15.) Choose an existing role for the handler and select "lambda_basic_execution".

16.) Hit next.

17.) Create function.

18.) Now, copy the ARN in the top right hand of the webpage. You will need this for the skill creation.

19.) Now go to Amazon's Developer dashboard. Go to Alexa -> Alexa Skills Kit and create a new skill.

20.) Give your skill a name and an invocation name.

21.) Add the custom slot types first (red), then get the intent schema and utterances and copy their contents into their respective text areas (yellow).

22.) Hit save and next. Enter you Lambda function's ARN and select Lambda function.

23.) Click next. Test the skill. You can either test from your device, or you can type in a command.

Congratulations! You created the skill! Now you can go to your Alexa-enabled device and open the the skill using its invocation name. If you want the published version, it's located here.

After the skill has been tested, you may move on to the Arduino Uno set up. Remember to follow the advanced creation method.

Part 2: The Arduino Uno

*Note: Please see attached schematic to properly wire the electronics.

The Arduino program is written in Arduino's IDE and outputs responses based upon what it receives through the serial communication link with the Raspberry Pi. The Arduino controls the color of the lights and drives the car.

How to set up:

For both simple and advanced:

1.) Attach the SeeedStudio motor shield to the top of the Arduino Uno. (Make sure you wired the motor(s) already.)

2.) Plug in your Arduino into any computer that has Arduino's IDE installed on it.

3.) Download the shield's dependencies. (Learn how to code for the shield here!)

4.) Copy the code from here and put it into a new empty file.

5.) Save and upload to the Arduino Uno.

*Note: I used a COMMON ANODE LED STRIP which had build-in resistors. Please look up how to connect your LED STRIP to your Arduino, before you attempt doing what the schematic says. If you will be using COMMON CATHODE LEDs, you will need to open the Arduino code and comment out the line that contains:

#define COMMON_ANODE

Congratulations! You now have the Arduino Uno ready! You can now move on to the Raspberry Pi setup. Remeber to follow the same path you followed for the Alexa skill creation. (Simple or Advanced)

Part 3: The Raspberry Pi

*Note: Please see attached schematic to properly wire the electronics.

The script on the Raspberry Pi that handles the processing of Alexa's requests is written in Python. When the python script is activated, it first prompts the user for their session id. This is the id that Alexa displayed on a card in the app. The user should now enter their session id and hit enter on their keyboard. When the script displays "CONNECTED", the user should now unplug their monitor and keyboard. This opens the link between the Arduino Uno and the Raspberry Pi, thus enabling the car's motors and lights.

This script also opens a communication link to a servo connected to pin 18 on the Raspberry Pi. This servo controls the turning mechanism in the car. The script uses PubNub to retrieve Alexa's requests and feeds these requests into a series of if statements. Depending on the command, the script will either send the command to the Arduino Uno through serial communication, tell the servo to turn the car, or return an unknown command error. (This error will never occur, because Alexa will sense the unknown command before she even sends the request. It is written only in the event of a change in the Alexa skill that would send a request that is not handled by the Python script.)

How to set up:

Simple:

1.) Download the Raspberry Pi K'nex Car Control image here.

2.) Unzip the file and flash the 16 gb sd card with the image.

3.) Plug the monitor (via HDMI), mouse, keyboard, Arduino Uno (via USB), and WiFi adapter (if applicable) into the Raspberry Pi.

4.) Power on the Raspberry Pi

5.) When the Raspberry Pi finishes booting, it will ask you to connect to WiFi.

6.) Open the Desktop to do this.

startx

7.) When the Raspberry Pi's Desktop appears, navigate to the connections menu in the top right of the screen.

8.) Pick your WiFi and enter you credentials.

9.) When you are connected, reboot the Raspberry Pi.

10.) After the reboot, you should see the following:

Congratulations! You now have the Raspberry Pi set up! You may move on to the car set up.

Advanced

1.) Flash the latest version of Raspbian onto your SD card.

2.) Plug the monitor (via HDMI), mouse, keyboard, Arduino Uno (via USB), and WiFi adapter (if applicable) into the Raspberry Pi.

4.) Power on the Raspberry Pi.

5.) When the Raspberry Pi finishes booting, connect to WiFi.

6.) Open a terminal window and type the following:

sudo raspi-config

8.) Find the change boot option and set it to boot to console with automatic login.

9.) Confirm your changes and reboot.

10.) When you Raspberry Pi boots back up, type the following two commands:

sudo apt-get update
sudo apt-get upgrade

This will take a little bit to complete.

11.) When the updates are complete, install PubNub's package for Python:

sudo pip install pubnub

12.) Clone into my repository:

sudo git clone https://github.com/AustinMathuw/VoiceControlledK-nexCar.git

13.) Navigate to the "RaspberryPiArduinoControl" folder:

cd VoiceControlledL-nexCar/RaspberryPiArduinoControl

14.) Edit "ArduinoControl.py"

nano ArduinoControl.py

15.) Find the line where "pubnub" is defined. Update the publish key and subscribe key to the keys from your pubnub device that you created earlier.

*Note: If you created a custom channel in the skill portion, find where "channel" is defined. Comment out this line and use the line below it as a template to set your own channel name. This name needs to be exactly the same as the one you set when creating the skill.

16.) When you are done editing "ArduinoControl.py", do the following: Press "Ctrl+x", then press "y", and finally, press "enter". You should now be back in the console.

17.) Start the "ArduinoControl.py" program.

sudo python ArduinoControl.py

18.) You should now be asked to enter your session ID. Open the Alexa skill on your Alexa-enabled device and navigate to you companion app to retrieve your session ID.

*Note: For those who used a specific channel name, you will not be prompted to enter your session ID and the program will immediately start listening to the incoming requests from Alexa.

19.) From now on, every time you want to run the script, all you have to do is be connected to the internet and type these commands:

cd
cd VoiceControlledL-nexCar/RaspberryPiArduinoControl
sudo python ArduinoControl.py

If you want to automate this process so that the script loads on boot, follow the optional steps below.

1.) Edit "/etc/profile"

sudo nano /etc/profile

2.) At the bottom of this file, add the following:

sudo chmod 777 /home/pi/VoiceControlledL-nexCar/RaspberryPiArduinoControl/ImageComplete
sudo ./home/pi/VoiceControlledL-nexCar/RaspberryPiArduinoControl/ImageComplete/startup.sh

3.) Press "Ctrl+x", then press "y", and finally, press "enter".

4.) Now every time the Raspberry Pi boots up, it will boot straight into the python script.

Congratulations! You now have the Raspberry Pi set up! You may move on to the car set up.

Part 4: The Car

This is the part in which user creativity comes into play. The user has the freedom to build their own vehicle. They do have to keep in mind that they will need to attach the servo to their turning mechanism and their drive motor to the main drive axle. Besides those constraints, the user is free to create their own car.

Below are instructions on how to build my car:

1.) Gather you materials. Use the picture below to help you find all of the necessary materials. (I used a Tower Pro MG945 Servo and hardware for the turning mechanism)

2.) Assemble the first layer. (Starting here, there will be a slide show for each section)

3.) Start to assemble the top layer.

4.) Put the motor power cables through the middle of the white piece toward the rear of the car. Secure the motor.

5.) Assemble the turning mechanism. (In image 4.4, make sure the servo clip is UNDER the K'nex price toward the rear of the car)

6.) Add some mount points for the electronics.

7.) Add the front axle and attach it to the servo. (We will use zip ties here)

8.) Set electronics on top of the car. (The 8xAA battery pack is placed behind the white bread board, the 4xAA battery pack is placed in front of the Arduino, and the portable smartphone charger is placed beside the Arduino and the 4xAA battery pack.)

You should now have a fully functioning car that can now be controlled by Alexa!

Additional Information

My project is not endorsed by K'nex or Arduino.

You can get the code from my GitHub.

Code

Voice Controlled K'nex Car
The location of all of my source code

Schematics

Voice Controlled K'nex Car
This is the schematic for the electronics on the car.
Wiring%20Schematics.fzz
Alexa Skill VUI
Voice User Interface for my Alexa skill.
Alexaskillvui

Comments

Similar projects you might like

Voice Controlled Car

Project tutorial by Yug_Ajmera

  • 10,306 views
  • 0 comments
  • 12 respects

Remote and Voice Controlled Smart Fan

Project tutorial by Paul Trebilcox-Ruiz

  • 4,050 views
  • 3 comments
  • 19 respects

Bolt Controlled Robot Car

Project tutorial by Team Bolt

  • 1,509 views
  • 1 comment
  • 13 respects

Voice Controlled RGB Lamp

Project tutorial by Pham Hoang Son

  • 2,859 views
  • 0 comments
  • 12 respects

RC Car to BT Car Controlled with Blynk

Project tutorial by Team Daxes Hacks

  • 3,602 views
  • 2 comments
  • 6 respects

Bluetooth Controlled Car

Project tutorial by JANAK13

  • 2,316 views
  • 7 comments
  • 15 respects
Add projectSign up / Login