Introduction: "OK Google, Start My Car!", Remotely Controlling a Car With Google Assistant and Cloud IoT
Macchina is excited to show off one of our most-requested videos, a technology demo we call "OK Google, start my car!", which is a clever project that allows you to use Google Assistant and various IoT services to remotely start and stop a car using our M2 automotive interface with our SuperB wireless expansion module. The full project write-up, complete with all the links to the sample code, libraries, and triumphant demo video is on the Macchina web site at https://docs.macchina.cc/projects/ok_google_start...
A smartphone with Google Assistant
GM Vehicle (GM CAN messages provided, you'll need to find your own for non-GM vehicles)
Step 1: Background and Theory
- Voice commands will be given to either a smartphone or a Google Home device
- Voice data is passed to Google Assistant
- Google Assistant then triggers IFTTT with either an ON or OFF command
- IFTTT in turn updates Adafruit IO with the ON or OFF command
- SuperB receives the ON or OFF command and updates itself to reflect the new state
- M2 reads the ON/OFF state of SuperB and then starts or stops the car
Other than Google Assistant, IFTTT supports a huge number of triggers. (e.g. weather, connect/disconnect from Wi-Fi networks, time, etc.) For example, have your car warm up before leaving for work if the temperature is below a certain threshold.
Because the smartphone and SuperB are never directly connected, commands can be sent to the vehicle as long as both devices have an internet connection, regardless of the physical distance between them.
You'll need either a smartphone capable of accessing Google Assistant or a Google Home device. In either case, make sure you know the credentials of the Google account associated with the device.
If This then That (IFTTT)
If This then That will handle the exchange between Google Assistant and Adafruit IO, and adds the option to use a trigger other than a voice command. Make sure to link the same Google account used on your smartphone or Google Home.
Adafruit IO is an easy to use web service that can control internet enabled hardware (like M2 and SuperB). IO provides a virtual dashboard accessible through a web browser onto which all manner of gauges, sliders, buttons, and switches can be placed. For our purposes we'll have a dashboard with a simple ON/OFF switch, the state of which the SuperB will be able to read. What makes IO extremely useful is that these switches can be controlled by other web services like IFTTT, and not just through the web dashboard.
NOTE: Because Instructables does not allow images to be mixed with the project text this will be hard to follow, but if you step through the images you will see they are in order, so it isn't too hard to refer to them. For the unadulterated version go to our website at https://docs.macchina.cc/projects/ok_google_start_my_car
Step 1: Set up Adafruit IO
Create a new feed titled "LED_Control". (case-sensitive!)
Create a new dashboard with any title.
Navigate to the new dashboard and place a toggle switch linked to the "LED_Control" feed. Leave the block settings on their default settings.
There should now be a single toggle switch on the dashboard:
Find and record your username and key, which will be necessary later.
Step 2: Set Up and Test SuperB
Download the SuperB sketch here. (This sketch uses the Adafruit MQTT library which can be installed through the Arduino library manager) Update the sketch with your Adafruit IO and Wi-Fi credentials.
To flash SuperB with M2 follow the instructions here. Alternatively, if you have an XBEE USB adapter board you can flash SuperB using the instructions found here. Power on SuperB (either with an M2 or USB adapter board) and use the Adafruit IO dashboard to test the functionality.
Step 3: Set Up and Test IFTTT
Create a new applet with Google Assistant as the trigger (the "this").
Select Adafruit IO as the action (the "that"). Connect your Adafruit account to IFTTT if prompted. Select the "LED_Control" feed and enter "ON" (case-sensitive) as the data to save to the feed.
In the same style create another applet to turn the car off, sending "OFF" instead of "ON". With these 2 applets you should now be able to control the toggle switch on your IO dashboard via Google Assistant.
Great! At this point we can toggle a pin on SuperB using Google Assistant. The final step is to have M2 read the pin state and then perform an action on the car accordingly. If you're interested in using more than just one pin the SuperB pinout can be found here, and the pinout for the M2's XBee socket can be found here.
Step 4: Flash M2
Download the M2 sketch here.
Determine which version of M2 you have here. Comment out the V4 specific line in the readBatteryVoltage() function if you have V3 or earlier, otherwise leave the code as is.
The startCarSpecific() and stopCarSpecific() functions are pre-populated with GM specific CAN messages. You'll have to determine what CAN messages to send for other cars. (This may take some work to determine!)