Example
projects
Real code, ready to deploy. Browse by category or dive into the source.
Basic
Pico W
Blink LED
Toggle the onboard LED on and off with a timer
await this.env.DEVICE
.setGpioOutput(99, 1);
// Pin 99 = onboard LED
Basic
Pico W
Button Input
React to physical button presses on a GPIO pin
await this.env.DEVICE
.configureGpioInput(14);
// Fires gpio_state_changed
Basic
I2C
OLED Counter
Display a button press counter on an SSD1306 OLED
this.env.DEVICE.display
.clear()
.drawText(0,0,`Count: ${n}`)
.render();
Sensors
ADC
Temperature Monitor
Read an analog temperature sensor with periodic ADC polling
await this.env.DEVICE
.configureAdcMonitoring(26, {
interval: 60000
});
Sensors
I2C
BME280 Weather
Read temperature, humidity, and pressure over I2C
const sensor = Pico.i2c({
bus: 0,
sda_pin: 0, scl_pin: 1
});
Sensors
GPIO
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());
Integration
Webhook
Discord Alerts
Send a Discord message when temperature exceeds a threshold
await fetch(WEBHOOK_URL, {
method: "POST",
body: JSON.stringify({
content: `Temp: ${t}C`
})
});
Integration
KV
Data Logger
Log sensor readings to cloud KV storage with timestamps
await this.env.DEVICE.kv
.put(`reading:${ts}`,
{ temp, humidity });
Advanced
Multi-sensor
Smart Thermostat
Control heating based on temperature with OLED display
if (temp < target) {
await device.setGpioOutput(
RELAY_PIN, 1);
display.drawText(0,0,"Heating");
}
Advanced
Fleet
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");
Advanced
ADC + GPIO
Plant Watering
Monitor soil moisture and control a water pump automatically
if (moisture < 30) {
await device.setGpioOutput(
PUMP_PIN, 1);
await delay(5000);
}
Want the full source?
All examples are available on GitHub with instructions.