Example
projects
Real code, ready to deploy. Browse by category or dive into the source.
Blink LED
Toggle the onboard LED on and off with a timer
await this.env.DEVICE
.setGpioState(99, "high");
// Pin 99 = onboard LED
Button Input
React to physical button presses on a GPIO pin
await this.env.DEVICE
.configureGpioInputMonitoring(
14, true);
// Fires gpio_state_changed
OLED Counter
Display a button press counter on an SSD1306 OLED
this.env.DEVICE.display
.clear()
.drawText(0,0,`Count: ${n}`)
.render();
Temperature Monitor
Read an analog temperature sensor with periodic ADC polling
await this.env.DEVICE
.configureGpioInputMonitoring(
26, true);
BME280 Weather
Read temperature, humidity, and pressure over I2C
const sensor = Pico.i2c({
bus: 0,
sda_pin: 0, scl_pin: 1
});
Motion Detector
Detect motion with a PIR sensor and log events to KV
if (msg.type === "gpio_state_changed")
await kv.put("lastMotion",
Date.now());
Discord Alerts
Send a Discord message when temperature exceeds a threshold
await fetch(WEBHOOK_URL, {
method: "POST",
body: JSON.stringify({
content: `Temp: ${t}C`
})
});
Data Logger
Log sensor readings to cloud KV storage with timestamps
await this.env.DEVICE.kv
.put(`reading:${ts}`,
{ temp, humidity });
Smart Thermostat
Control heating based on temperature with OLED display
if (temp < target) {
await device.setGpioState(
RELAY_PIN, "high");
display.drawText(0,0,"Heating");
}
Multi-Device System
Coordinate multiple devices reading different sensors
// Same script deploys to
// multiple devices — each
// gets its own KV namespace
kv.put("role", "sensor-a");
Plant Watering
Monitor soil moisture and control a water pump automatically
if (moisture < 30) {
await device.setGpioState(
PUMP_PIN, "high");
await delay(5000);
}
Device-to-Device RPC
Sensor triggers light controller via type-safe method calls
await this.env.DEVICES[
"light"
].turnOn();
// { status: "on" }
Want the full source?
All examples are available on GitHub with instructions.