Learning Goals 5 min
End-to-end: register a board as a Device, create a Thing, add two Properties (one read-only sensor, one read-write toggle), upload the auto-generated sketch, and watch the values update in real time. By the end of this lesson you will:
- Register a supported board (UNO R4 WiFi, MKR WiFi 1010, Nano 33 IoT, Nano ESP32) as an Arduino Cloud Device.
- Create a Thing, attach the device, and add two Properties.
- Upload the auto-generated sketch and confirm the sensor reading appears in the Property's value field within seconds.
Warm-Up 10 min
Have ready:
- A supported board (see L04-07 list). For this lesson we'll assume Nano ESP32.
- USB cable.
- A potentiometer on A0 (the "sensor") and an LED on D2 with a 220 Ω resistor (the "actuator").
- WiFi credentials for the network the board will use.
- Arduino account, signed into
create.arduino.cc.
Mental map of the steps
- Register the device — give the cloud an ID for this specific board.
- Create a Thing — name + add Properties.
- Configure network — enter WiFi SSID + password (stored as secrets).
- Auto-generate sketch — IoT Cloud writes thingProperties.h for you.
- Upload — via the web IDE or your local IDE.
- Watch the Property update.
New Concept · Walkthrough 25 min
Step 1 — Devices tab
In IoT Cloud → Devices → Add Device. Pick "Arduino board" (vs "Third-party device", which is for ESP8266 / non-Arduino ESP32). The wizard auto-detects boards plugged in via USB.
Pick your board model. The wizard installs the Arduino Cloud Agent (a small helper app), assigns a unique Device ID and a secret Device Key. Save these somewhere safe — the key is shown ONCE and never again.
Step 2 — Things tab
Things → Create Thing. Name it (e.g. "DeskMonitor"). Attach the Device you just registered.
Step 3 — Add Properties
- potValue: integer, READ permission, On Change update policy.
- ledOn: boolean, READWRITE permission, On Change.
Each Property has:
- Variable name (becomes a C++ variable in the sketch).
- Type (int, bool, float, String, or a domain type like Temperature).
- Permission: READ (sketch → cloud), WRITE (cloud → sketch), READWRITE (bidirectional).
- Update policy: On Change (push when value differs) or Periodically (push every N seconds).
Step 4 — Network
Click the Network field. Enter SSID + password. These become SECRET_SSID and SECRET_OPTIONAL_PASS — stored encrypted on the cloud side and injected into the sketch at upload time. Never visible in plain text in your codebase.
Step 5 — Sketch
The Sketch tab shows the auto-generated .ino. You can edit it in the browser or download it.
#include "thingProperties.h"
void setup() {
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
pinMode(2, OUTPUT);
}
void loop() {
ArduinoCloud.update();
potValue = analogRead(A0);
}
void onLedOnChange() {
digitalWrite(2, ledOn ? HIGH : LOW);
Serial.print("LED -> ");
Serial.println(ledOn ? "ON" : "OFF");
}Step 6 — Upload
From the web IDE: click Upload. Watch the build log + the board's status (Devices tab shows "online" / "offline").
From your local IDE: download the sketch + thingProperties.h, open as a normal Arduino project. The libraries (ArduinoIoTCloud + Arduino_ConnectionHandler) must be installed locally; auto-installed if you compile from the web IDE.
Step 7 — Watch the Property
In the Thing's Properties tab: potValue should update every second or so as you turn the pot. ledOn has a switch you can toggle; the LED on D2 should respond within ~1 s.
Worked Example · DeskMonitor in 15 minutes 25 min
Follow the §3 steps live. Verify everything works.
If it didn't work
| Symptom | Likely cause |
|---|---|
| Board not detected by wizard | Cloud Agent not running, or wrong USB driver. Reinstall Cloud Agent. |
| Upload starts but stalls | Web IDE compile timeout. Switch to local IDE for now. |
| Sketch uploaded but Property never updates | Either WiFi failed to connect (check serial monitor for "Connecting" loop) or ArduinoCloud.update() isn't being called. |
| LED doesn't respond to dashboard toggle | Callback function name doesn't match on<PropertyName>Change — check spelling. |
Add a third Property
Now add uptime (int, READ, Periodically every 10 s). Update in loop():
uptime = millis() / 1000;The IoT Cloud handles the periodic publishing — you don't need a millis() timer.
Watch the serial monitor
The Cloud library is chatty when setDebugMessageLevel(2) is set. You'll see:
Connecting to "your-wifi" Connected to WiFi Connecting to Arduino IoT Cloud Connected to Arduino IoT Cloud *** Tx properties (~1 s) *** *** Rx properties ***
If you see "Connecting" forever, the WiFi credentials are wrong or the network is unreachable.
Basic 5 min
Goal: Add a String property called status. In loop(), set it to "HIGH" if potValue > 512 else "LOW". Watch it update in the cloud.
1. Think first (on paper, no typing yet):
- Who changes
status— the sketch or the dashboard? So which permission does it need? - Where in
loop()ispotValueupdated? Shouldstatusbe set before or after that line? - Write the rule in plain English, one line per case.
2. Code it. Add the Property on the Thing's page first, so the IDE regenerates thingProperties.h. Then change your DeskMonitor loop().
3. Upload and observe. Open the Thing's Properties page and turn the knob slowly from one end to the other.
It works if: status shows LOW with the knob below halfway and HIGH above it, and changes within a second or two of crossing the middle.
Challenge 1 5 min
Goal: Add a Temperature property (float-derived). Wire a TMP36 (or any temperature sensor). Read it; assign to the property. The cloud will display it with °C units.
1. Think first (on paper, no typing yet):
- A TMP36 gives 0.5 V at 0 °C and adds 10 mV for every degree. What voltage should it give in a 25 °C room?
- Your board turns volts into a raw number. What are its top raw value and its reference voltage? (L04-01 Challenge 2.)
- Write the two steps on paper: raw number → volts → °C.
2. Code it. Add the Property on the Thing's page, wire the TMP36 to an analog pin and 3.3 V, then add the reading to your DeskMonitor loop().
3. Upload and observe. Watch the Properties page. Pinch the sensor between your fingers for 20 seconds.
It works if: the value reads a sensible room temperature (about 20–32 °C), rises by a few degrees while you pinch the sensor, and shows °C on the dashboard.
Challenge 2 5 min
Goal: Add a CloudColor property bound to an RGB LED. The dashboard's colour-picker widget should set the LED's colour live.
1. Think first (on paper, no typing yet):
- Which function runs when the dashboard changes the colour? What will it be called?
- An RGB LED needs three numbers, one per leg. How will you get three numbers out of one colour value? (Look up CloudColor in the IoT Cloud docs.)
- Which three pins can you use? They must all do PWM.
2. Code it. Add the CloudColor Property (READWRITE) on the Thing's page, wire the RGB LED with a resistor on each colour leg, then fill in the new callback in your DeskMonitor sketch.
3. Upload and observe. Add a Colour picker widget bound to the Property. Pick pure red, pure green, pure blue, then white.
It works if: picking red, green and blue on the dashboard turns the real LED red, green and blue, and white lights all three legs.
Challenge 3 · Fix three broken DeskMonitors 10 min
Three DeskMonitors each have one fault. Read the symptom and the code, then find the fault.
A — never gets online
Connecting to "DeskWifi" Connecting to "DeskWifi" Connecting to "DeskWifi"
The sketch is the same as Step 5. The board sits beside the router.
B — online, but potValue never moves
void loop() {
ArduinoCloud.update();
int potValue = analogRead(A0);
}C — the switch prints, but the LED barely glows
void setup() {
Serial.begin(9600);
delay(1500);
initProperties();
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
setDebugMessageLevel(2);
}
void onLedOnChange() {
digitalWrite(2, ledOn ? HIGH : LOW);
Serial.print("LED -> ");
Serial.println(ledOn ? "ON" : "OFF");
}The Serial Monitor shows LED -> ON, but the LED on D2 is only faintly lit.
Fix B and C in your own DeskMonitor and upload.
It works if potValue tracks the knob on the Properties page. The LED must turn fully on and off from the switch.
Recap 5 min
Setting up a Thing is: register device → create Thing → add properties → set WiFi → upload generated sketch. The hidden thingProperties.h file holds all the boilerplate (WiFi, device key, MQTT). Your .ino stays tiny — just sensor reads and callback bodies. Tomorrow we visualise the properties with dashboard widgets.
- Cloud Agent
- Small helper app on your computer that lets the web IDE upload to USB-connected boards.
- Device ID / Device Key
- Unique per-device credentials used to authenticate the board to the cloud. The Key is shown once at registration.
- Update policy
- How / when a property pushes. "On Change" = whenever value differs. "Periodically" = every N seconds regardless.
- Permission
- READ = device pushes only. WRITE = cloud pushes only. READWRITE = both directions.
- Callback (on<Name>Change)
- Function called when a READWRITE property is updated from the cloud. Name must match the property:
onLedOnChange()forledOn. - Secret
- Sensitive value (WiFi password, API key) stored in the cloud's secrets manager, never visible in shared sketches.
- thingProperties.h
- Auto-generated header with property declarations, WiFi setup, and the initProperties() function.
Extra Mission 5 min
Part 1 — Design a desk gadget with three Properties
Design a desk gadget that adds one sensor and one output to DeskMonitor. Try a too-hot warning or a "busy" light. Plan it on paper.
Your design must include:
- The gadget's one job.
- At least three Properties, each with type, permission and update policy.
- The pin for every part.
- What the Serial Monitor should print when it works.
Part 2 — Make it
Add your Properties to the DeskMonitor Thing, wire the parts and finish the sketch. Get it working end to end.
Bring back next class: the sketch, plus screenshots of the Properties page and the Serial Monitor.