Skip to content

Commit bdfe428

Browse files
committed
add code
1 parent d27011b commit bdfe428

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

content/arduino-cloud/01.guides/09.google-home/google-home.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,57 @@ Your Thing should look something like this when you are finished:
5959

6060
***Learn more about how variables work in the [Variables documentation](/arduino-cloud/cloud-interface/variables)***
6161

62+
### Upload Sketch
63+
64+
Upload the following sketch to your Arduino board.
65+
66+
```arduino
67+
68+
69+
#include "thingProperties.h"
70+
71+
void setup() {
72+
// Initialize serial and wait for port to open:
73+
Serial.begin(9600);
74+
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
75+
delay(1500);
76+
77+
// Defined in thingProperties.h
78+
initProperties();
79+
80+
// Connect to Arduino IoT Cloud
81+
ArduinoCloud.begin(ArduinoIoTPreferredConnection, false, "mqtts-sa.iot.oniudra.cc");
82+
83+
/*
84+
The following function allows you to obtain more information
85+
related to the state of network and IoT Cloud connection and errors
86+
the higher number the more granular information you’ll get.
87+
The default is 0 (only errors).
88+
Maximum is 4
89+
*/
90+
setDebugMessageLevel(2);
91+
ArduinoCloud.printDebugInfo();
92+
}
93+
94+
void loop() {
95+
ArduinoCloud.update();
96+
digitalWrite(LED_BUILTIN, led);
97+
98+
}
99+
100+
101+
/*
102+
Since Led is READ_WRITE variable, onLedChange() is
103+
executed every time a new value is received from IoT Cloud.
104+
*/
105+
void onLedChange() {
106+
// Add your code here to act upon Led change
107+
}
108+
109+
```
110+
111+
Your board setup is now complete and you can continue to the Google Home app.
112+
62113
#### Detect Your Device with Google Home
63114

64115
1. **Network Connection:** Ensure the board is connected to the network.

0 commit comments

Comments
 (0)