Google Home

Learn how to connect the Arduino Cloud with Google Home™.

Introduction

This tutorial guides you on how to connect the Arduino Cloud to your Google Home™ allowing you to interact with your devices, simply through your Google Home Assistant: use voice commands, the Google Home app, or create new routines integrating Arduino solutions.

It requires your board to be compatible with the Arduino Cloud.

Goals

The goals of this tutorial are:

  • Create a Google Home compatible variable.
  • Control the built-in LED with Google Home.

Hardware & Software Needed

To familiarize yourself with the Arduino Cloud check out our getting started guide.

Cloud Setup

Before we start, make sure you have an Arduino Cloud compatible board.

Then, we need to configure a Thing in the Arduino Cloud consisting of one CloudSwitch variables called

led
. Follow the instructions below to do so.

Thing & Device Configuration

  1. Create a new Thing, by clicking on the "Create Thing" button.
  2. Click on the "Select Device" in the "Associated Devices" section of your Thing.
  3. Click on "Set Up New Device", and continue to set up your device.

If you need more information on how to set up your device check out our getting started guide.

Create Variables

The next step is to create a Cloud variable, which we will later interact with via Google Home.

  1. While in Thing configuration, click on "Add Variable" which will open a new window.
  2. Name your variable
    led
    , select
    Smart home
    , and select it to be of a
    Switch
    type.

Create Variable
Create Variable

  1. Click on "Add Variable" at the bottom of the window.
  2. Make sure the Smart Home Integration is set to Google Home.

Smart Home Integration
Smart Home Integration

Most Cloud variables are compatible with both Alexa and Google Home but there is an icon on the right side of the type that indicates the compatibility

Your Thing should look something like this when you are finished:

Finished Thing interface.
Finished Thing interface.

Learn more about how variables work in the Variables documentation

Upload Sketch

Navigate to the Sketch tab and upload the following sketch to your Arduino board.

1#include "thingProperties.h"
2
3void setup() {
4 // Initialize serial and wait for port to open:
5 Serial.begin(9600);
6 // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
7 delay(1500);
8
9 // Defined in thingProperties.h
10 initProperties();
11
12 // Connect to Arduino IoT Cloud
13 ArduinoCloud.begin(ArduinoIoTPreferredConnection);
14
15 /*
16 The following function allows you to obtain more information
17 related to the state of network and IoT Cloud connection and errors
18 the higher number the more granular information you’ll get.
19 The default is 0 (only errors).
20 Maximum is 4
21 */
22 setDebugMessageLevel(2);
23 ArduinoCloud.printDebugInfo();
24}
25
26void loop() {
27 ArduinoCloud.update();
28 digitalWrite(LED_BUILTIN, led);
29
30}
31
32
33/*
34 Since Led is READ_WRITE variable, onLedChange() is
35 executed every time a new value is received from IoT Cloud.
36*/
37void onLedChange() {
38 // Add your code here to act upon Led change
39}

Your board setup is now complete and you can continue to the Google Home app.

Detect Your Device with Google Home

  • Network Connection: Ensure the board is connected to the network.

  • Google Home App: Open the app, navigate to Devices, and click "Add Device."

  • Integration Method: Select "Works with Google Home" and then choose the "Arduino" action.

Setup Device
Setup Device

  • Device Pairing: Link your Arduino account if requested and proceed to add your devices (one for each variable) by associating them with a room.

Link Accounts
Link Accounts

Congratulations! Your device is now successfully configured to work with Google Home.

Suggest changes

The content on docs.arduino.cc is facilitated through a public GitHub repository. If you see anything wrong, you can edit this page here.

License

The Arduino documentation is licensed under the Creative Commons Attribution-Share Alike 4.0 license.