By Kevin McAleer, 8 Minutes
Page last updated November 24, 2026

Now for the moment that makes Wi-Fi worth having: the buddy tells your phone whether the door is open, from anywhere in the world. This is status buddy stage 4, and it finishes the Connect section.
Kev’s Wi-Fi episode has the reasons. There are plenty of services (Adafruit IO, ThingsBoard, Home Assistant Cloud), but Arduino Cloud has:
It works like this:
flowchart LR
B["Status buddy<br/>Pico W"] -- "Wi-Fi" --> C["Arduino Cloud"]
C --> P["Phone app<br/>dashboard"]
The buddy pushes, and your phone pulls. They never need to be on the same network.
Go to cloud.arduino.cc, sign in, and:
door_open, type Boolean, Read-only, updated Periodically every 10 secondsopen_count, type Integer, Read-only, updated Periodically every 10 secondsImportant: the secret key is shown once. Save it now. Treat it like a password: keep it out of screenshots, screen recordings and GitHub.
Kev’s post makes three float variables for a weather station. We use a boolean and an integer instead, because that is what a door needs. Everything else about setting up is the same.
Open secrets.py on the Pico and add the Arduino Cloud values. These are placeholders. Use your own:
# secrets.py - lives on the Pico only. Never put this file on GitHub
WIFI_SSID = "YOUR_WIFI_NAME"
WIFI_PASSWORD = "YOUR_WIFI_PASSWORD"
DEVICE_ID = "YOUR_DEVICE_ID"
SECRET_KEY = "YOUR_SECRET_KEY"
The Arduino Cloud client leans on a few other libraries. MIP (MicroPython Install Package) is MicroPython’s tiny version of pip. It runs on the Pico, downloads over Wi-Fi, and puts packages in /lib. Because it needs the internet, the Pico must be on Wi-Fi first.
Save this as install_requirements.py on the Pico and run it once:
import network
import time
from secrets import WIFI_SSID, WIFI_PASSWORD
# Wi-Fi must be up before MIP can fetch anything
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
while not wlan.isconnected():
time.sleep(1)
print("Connecting...")
print("Connected:", wlan.ifconfig())
def install_packages():
import mip
packages = [
"logging", # standard logging API the cloud client uses
"cbor2", # compact binary format for sending values
"senml", # the data format Arduino Cloud expects
"umqtt.simple", # the MQTT client
"umqtt.robust", # adds reconnect logic on top of umqtt.simple
]
for pkg in packages:
try:
print("Installing", pkg)
mip.install(pkg)
except Exception as e:
print(" Failed:", e)
install_packages()
If you skip this, the next program fails on its first import with something like ImportError: no module named 'cbor2'. The fix is always to run this script.
The arduino_iot_cloud library itself is not on the MicroPython package index, so MIP can’t fetch it. You copy it once by hand. It lives in the companion repository for Kev’s Wi-Fi episode:
Inside is a folder called arduino_iot_cloud/ with four files: __init__.py, ucloud.py, umqtt.py and ussl.py. Copy that whole folder into /lib/ on the Pico:
/lib on the Pico side (create it if needed), and drag the folder acrossmpremote cp -r arduino_iot_cloud :/lib/When you’re done, the Pico’s files should look like this:
/
├── main.py
├── secrets.py
├── ssd1306.py
├── sam/
├── sam_render.mpy
├── install_requirements.py
└── lib/
├── arduino_iot_cloud/ <- copied by you
├── cbor2/ <- installed by MIP
├── senml/ <- installed by MIP
├── umqtt/ <- installed by MIP
└── logging.py <- installed by MIP
/lib is on MicroPython’s import path automatically, so from arduino_iot_cloud import ArduinoCloudClient just works.
The client’s own project is also on GitHub: arduino-iot-cloud-py.
This is a complete test program. It reads the reed switch, connects to Wi-Fi, and hands the door state to Arduino Cloud every 10 seconds.
import network
import time
from machine import Pin
from arduino_iot_cloud import ArduinoCloudClient
from secrets import WIFI_SSID, WIFI_PASSWORD, DEVICE_ID, SECRET_KEY
# Reed switch: 0 = magnet near = door closed
reed = Pin(15, Pin.IN, Pin.PULL_UP)
open_count = 0
# Wi-Fi
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(WIFI_SSID, WIFI_PASSWORD)
while not wlan.isconnected():
time.sleep(1)
# Cloud
client = ArduinoCloudClient(
device_id=DEVICE_ID.encode(),
username=DEVICE_ID.encode(),
password=SECRET_KEY.encode(),
)
def read_door_open(client):
return reed.value() == 1
def read_open_count(client):
return open_count
# "Every 10 seconds, call this function and push the result to that variable"
client.register("door_open", value=None, on_read=read_door_open, interval=10)
client.register("open_count", value=None, on_read=read_open_count, interval=10)
client.start()
The program has three blocks, and you have met two of them: Wi-Fi from lesson 11, and the reed switch from lesson 3. The new block is the cloud client, which takes your credentials, and the register() calls, which say “every 10 seconds, call this function and send the result to this variable”.
Two things to know:
client.start() never returns. It runs the cloud connection for ever. That is fine for this test, but our full gadget also needs to draw on the screen and speak. Lesson 14 solves that.open_count isn’t updated here, because this test doesn’t watch for changes. It’s in the program so the variable exists. The full gadget in lesson 14 counts openings properly.door_open, choosing one that suits a true or false valueNow the magic moment: turn off Wi-Fi on your phone. The widget still updates, because the data is coming from the internet, not your router.
The pattern you just wrote, read a thing, push it to the cloud, see it on your phone, is the same for everything. Kev’s list includes a cat flap monitor, a mailbox notification (tilt switch), a plant that needs watering and a garage door checker. Swap the sensor, change the variable name, and you are done.
uptime_seconds, and send time.ticks_ms() // 1000.door_open becomes true. Kev notes this is done in the dashboard, with no extra code.Problem: ImportError: no module named 'cbor2' (or senml, umqtt, logging).
Solution: Run install_requirements.py first, with the Pico on Wi-Fi.
Why: The cloud client needs those packages, and MIP is how you get them.
Problem: ImportError: no module named 'arduino_iot_cloud'.
Solution: Copy the whole arduino_iot_cloud folder to /lib/ on the Pico.
Why: MIP can’t fetch this one, so it must be copied by hand.
Problem: The dashboard never changes.
Solution: Check DEVICE_ID and SECRET_KEY in secrets.py against the Arduino Cloud device. If you lost the secret key, make a new device.
Why: The key is shown once, and a wrong key means a silent rejection.
Problem: The widget updates slowly.
Solution: This is normal. We told the variable to update every 10 seconds.
Why: interval=10 means the client only reads and sends every 10 seconds.
Quick quiz 1 of 3
Why must the Pico be on Wi-Fi before you run MIP?
Quick quiz 2 of 3
How do you get the arduino_iot_cloud library onto the Pico?
Quick quiz 3 of 3
Where should your Arduino Cloud secret key live?
secrets.py keeps them out of programs you might share or screenshot.
Comments