Entertain humans and pets alike with paper planes launched by your voice.
In this project we will take a look at a combination of some old and new technologies to achieve something even older, entertainment. Maybe I won't have the timeline right but the technologies used in this projects are listed from the oldest to the newest below:
- Paper Planes
- Paper Plane Launcher
- Arduino
- Alexa Smart Home Skill
See full video here.
DemoThis is me launching a paper plane using the technology stack previously mentioned
Paper PlanesI'm using this simple model for the paper plane because it's sleek, easy to make and flies very well. I'm using paper rectangles of 6.5 x 8 cm and the instructions are shown below (taken from here)
Here's an animation showing how the plane is built
The Roof, the Bump and the Base
To launch a paper plane we use two motors to move two wheels separated by a small distance. The body of the plane passes between the wheels and it gets pushed as if we have launched the plane ourselves. I built something similar to what is shown in this video and added some structure so that I didn't have to use my hands to make the planes take off.
The two components are a small base and a roof with a "bump". Both components support the plane in position while it passes through the motors to get the push required to make it fly. I made a video describing the structure and you can see it in action below
To create the whole structure I used cardboard and stick tape only. I started adding small rectangles of cardboard between the motors until I found the right number that separated them just enough to allow the planes to pass through while having a good contact with the wheels.
Once the two motors were joint together, I started adding the roof and the base following a similar principleho using the same small pieces of cardboard and stick tape.
See the video of me talking about the motors' front view.
The Platform
Besides the motors we also have a platform so that we can launch several planes without using our hands. The platform holds the plains in queue to be launched. It is connected to the motors by stick tape and the vibration of the motors plus the angle of the platform help the planes to move down so that the motors can push them through.
I also made a video describing the Platform and its workings.
To create the Platform you need two sheets of carton or cardboard. You don't need exact measures but make sure to start with big pieces so that you can trim them down until you find what works better. The final shape of the Platform mimicking the plane's shape was the result of trial and error as well as the height of the supporting structure.
Now that we have a whole take-off platform let's wire the motors to make our planes fly.
ArduinoThe Circuits
I chose the Arduino MKR1000 because it already has WiFi support and good specs compared to other editions. The electronics of the whole system was taken from the Adafruit site where they show how to control DC Motors with an Arduino Uno R3. My circuit replicates almost exactly theirs differing in the amount of motors. In the code I removed the user input and variable speed features because the motors where going to be started by Alexa and they were going to run at full speed always.
Here's the layout, schematics and PCB of the circuit I shared in Fritzing.
There is an important warning on the Arduino Store Website
Warning: Unlike most Arduino & Genuino boards, the MKR1000 runs at 3.3V. The maximum voltage that the I/O pins can tolerate is 3.3V. Applying voltages higher than 3.3V to any I/O pin could damage the board. While output to 5V digital devices is possible, bidirectional communication with 5V devices needs proper level shifting.
That's why I power the circuit using the VCC pin that outputs 3.3v. Maybe You can use the 5V pin but I lack electronics knowledge as well as tools and I didn't want to burn my Arduino. I tested it several times, left the motors on for several minutes and everything is working fine, however bear in mind that I didn't take any precautions to protect the Arduino.
The Code
The software side of the Arduino is quite simple as it acts like a remote switch turning on or off based on an incoming message. It can be seen in here
void messageReceived(String &topic, String &payload) {
Serial.println("Received " + topic + ": " + payload);
// Set value to 1 if we receive "ON". Set it to 0 otherwise
int value = payload == "ON" ? HIGH : LOW;
// Turn on/off built-in led
digitalWrite(led, value);
// Turn on/off motors
int speed = 255 * value;
analogWrite(motorPin, speed);
}
The other part is the configuration to connect to the WiFi and to the MQTT server. You can take a look at the full code in here.
To send/receive messages I used the shiftr.io service that provided me with the infrastructure and the code to listen to messages broadcasted to a specific topic. There you have namespaces which are like isolated projects. Inside a namespace you have tokens (key/secret pairs) that are used to authenticate against the mqtt host. Here's how you connect to your namespace
client.connect(shiftrClientId, shiftrUsername, shiftrPassword)
The clientId is the name of this node in the mqtt network, in the case of the Arduino is "MKR1000" while for the lambda is "lambda". (More about the lambda later)
There is also a topic in the configuration of the mqtt connection. The topic is used to send and receive messages under a namespace; the Arduino subscribes to the /launch topic so that it can receive a notification to control the motors.
client.subscribe(shiftrTopic);
The whole configuration is shown below
// MQTT Configuration
const char shiftrHostname[] = "broker.shiftr.io";
const char shiftrUsername[] = SECRET_SHIFTR_USERNAME;
const char shiftrPassword[] = SECRET_SHIFTR_PASSWORD;
const char shiftrClientId[] = "MKR1000";
const char shiftrTopic[] = "/launcher";
And this is what we see in the monitor view of the arduino
Ok, so that's all from the Arduino side. Now let's take a look to the Alexa side
AlexaAs you may already guess we use Alexa to turn on/off our Paper Plane Launcher. Alexa can't place the planes in position to take-off so that duty is on your side; once it's done, you can simply say
Alexa, turn on Paper Plane Launcher
And after a few seconds your planes will be feeling the air in their wings. Take a look at this 1 min demo where I show how I turn on and off the Paper Plane Launcher with my voice
So, what do you need to do in the Alexa side?
You need to create your developer account, create the smart home skill and create a lambda to handle the directives. The following steps will help you to build you own back-end.
- 2. Make sure you complete the 5 steps before developing a Smart Home Skill
- 3. Read about Managing Device Discovery for Your Alexa Smart Home Skill but do not use that code. The reason is that the whole payload format changed from the v2 to v3 and that code is out of date. You can take a look at the code I wrote to handle v3 directives.
- 4. Add tests events to the lambda. Again, do not use the code in the article because it is outdated. You can find the structure for the v3 payload in this repo.
- 5. Test your skill.
I wish to tell you it was easy, but it wasn't. Those 5 steps are the result of many hours figuring out how to make everything work together. I think that I spent most of my time trying to make the outdated code work; you won't have that issue if you clone my repository and start from there.
Let's dive into the lambda code to better understand how it works.
Lambda
The whole code is divided in 3 files. The handler (index.js), which receives the event, the responseBuilder which builds the object that Alexa expects as a response and the broadcaster to tell the Arduino through mqtt/shiftr.io that it's time to be turned on/off.
We create a response using the responseBuilder and succeed immediately if the event is not a PowerControl event. The reason is that in the case of Discovery or ReportState, we don't need to interact with the Arduino and we can just simply reply to Alexa right away.
const response = responseBuilder.buildResponseToEvent(event)
if (!responseBuilder.isPowerControlRequest(event)) {
return context.succeed(response)
}
If, on the other hand, the event is a PowerControl one we need to send the message to the Arduino so that it can turn on/off. This is done with the help of the broadcaster as shown below
const value = responseBuilder.getPowerValue(event)
broadcaster.send(value)
.then(() => context.succeed(response))
We also inform Alexa about errors in case we have one
const type = responseBuilder.ERROR_TYPES.INTERNAL_ERROR
const response = responseBuilder.buildErrorResponse(event, type, error)
context.succeed(response)
In here we create the different responses based on the incoming event. To do so, I first identify the request type and build one reply or another. This builder can create Discovery, ReportState, Error, and PowerControl responses. They all work the same with small differences in structure. Don't forget to take a look to the tests.
It has a simple task: send a message to a topic. The broadcaster connects to the host and publishes a value to the given topic; in that way we tell the Arduino to start/stop the motors of our launcher. The username and password are the same we use in the Arduino but instead of having a secret file we configure environment variables that can be read like this
const { SHIFTR_USERNAME, SHIFTR_PASSWORD } = process.env
and then used like this
var client = mqtt.connect(`mqtt://${SHIFTR_USERNAME}:${SHIFTR_PASSWORD}@${HOST}`, { clientId: CLIENT_ID })
To configure environment variables in your lambda scroll down to that section and set the values
Then, as soon as the message is sent we disconnect from the server because there's nothing else to do and because otherwise the lambda will keep on running until it's execution time has finished. Not disconnecting could cause unnecessary costs.
client.publish(TOPIC, value, error => {
client.end()
...
})
If you want to test the broadcaster locally, you need to set the environment variables in the npm script like shown below
...
"test": "SHIFTR_USERNAME=123 SHIFTR_PASSWORD=abc jest"
...
I also included some extra scripts that will help you with your lambda development. Those were added in the package.json
You can deploy your lambda just by running
npm run deploy
To do so, you need first to have configured the aws cli and also you need to change the --function-name in the update-lambda npm script.
Running the deploy command will copy all files in the src folder and the node_modules folder to a build folder. It will then zip the build folder and execute the aws lambda command that will update the function's code. Since the name of the zip file is build.zip you need to make sure the handler in the lambda is set to build.handler as shown below.
And that covers our lambda code to handle Alexa directives.
DiagramsLet's see some diagrams to have a better understanding of how the pieces work together
VUI Diagram
The Voice-User-Interaction in this case is very simple because we are using the Smart Home Skill to control the paper plane launcher as a switch
Cloud Components
The communication between the parts happens as described in the image below
Building a semi-automated voice-activated paper plane launcher had a lot of obstacles in different fields. We started with our bare hands making small planes out paper, cutting and sticking together pieces of cardboard to build a launcher to then connect its motors to an unprotected circuit controlled by an Arduino that listens to messages in a /launcher mqtt topic where a lambda function posts values each time Alexa hears you saying the right words. (Phew...)
The mixture of feelings is rich in variety but the prominent one is satisfaction. There's also a lot of gratitude and I want to create a section to give thanks.
Special Thanks
I created this project to participate in The Alexa and Arduino Smart Home Challenge, however the first idea was a completely different one and there were different people helping me with each idea.
- For the Paper Plane Launcher
Christine Gaulis: For the hours of conversations and support in this project in both ideas.
Ivan Mottier from ZigoBot: Who took the time to listen to my broken french and provided me with the right components to build the paper plane launcher.
- For the sound detector (asking Alexa if the water tap was open)
From the Hackuarium Lab:
Rachel Aronoff: For connecting me with the lab and some of its members. Also for showing me her project about the DNA in the cells from the cheeks and her fluor detector.
Vanessa Lorenzo: For her help while we were in the lab, for showing me her own experiments and telling me about the music making using microorganisms.
Luc Patiny: For his time explaining me the different ways I could process the sound in order to find the information I was looking for. Also for sharing with me his experience in Cali, Colombia, my own city. He also shared with me very useful resources like C.H.I.P and the ml.js libraries
Christian Zufferey: Who by his own initiative contacted me through Vanessa Lorenzo to propose that I use a method he used back in 2007 to compare websites so that I could identify objects through the sound.
And finally, from this repo in github to
Alexandre Storelli: Who helped me by answering to my questions about audio signatures.
----------------------
I hope you can learn something from what I shared here and have a lot of fun while doing it. If you build a Paper Plane Launcher or something similar please let me know.
Comments