Real examples,
ready to deploy
Copy, paste, and customize these examples for your projects.
Basic Examples
Get started with these foundational examples.
Blink LED
BeginnerThe "Hello World" of hardware. Toggle an LED on and off.
Hardware: LED + resistor
Messages: ~5,000/day
async onDeviceConnect() {
setInterval(async () => {
await this.env.DEVICE.setGpioState(25, "high");
await sleep(500);
await this.env.DEVICE.setGpioState(25, "low");
}, 1000);
}
Button Input
BeginnerReact to button presses with debouncing and LED feedback.
Hardware: Button + LED
Messages: Event-based (~10/day)
async onDeviceConnect() {
await this.env.DEVICE.configureGpioInputMonitoring(
20, true
);
}
async onMessage(msg) {
if (msg.payload.state === "high") {
await this.toggleLed();
}
}
Temperature Monitor
BeginnerRead analog temperature sensor and store readings.
Hardware: TMP36 sensor
Messages: ~1,440/day (1/min)
async onDeviceConnect() {
await this.env.DEVICE.configureAdcMonitoring(26, {
interval: 60000
});
}
async onMessage(msg) {
const temp = this.toTemp(msg.payload.value);
await this.env.DEVICE.kv.put("temp", temp);
}
Sensor Examples
Work with various sensors and communication protocols.
BME280 Environmental
IntermediateRead temperature, humidity, and pressure via I2C.
Protocol: I2C
Messages: ~4,320/day (3/min)
Motion Detector
IntermediatePIR motion sensor with event-based alerts.
Hardware: PIR sensor
Messages: Event-based
Light Level Monitor
BeginnerTrack ambient light with a photoresistor.
Hardware: Photoresistor + ADC
Messages: ~288/day (1/5min)
Integration Examples
Connect your devices to external services.
Discord Alerts
IntermediateSend sensor data and alerts to a Discord channel.
Integration: Discord Webhook
Use case: Team notifications
async sendAlert(message) {
await fetch(DISCORD_WEBHOOK, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
content: `🚨 Alert: ${message}`
})
});
}
Email Notifications
IntermediateSend email alerts when thresholds are exceeded.
Integration: Resend / SendGrid
Use case: Critical alerts
Data Logger
IntermediateLog all sensor readings to a database for analysis.
Integration: Database API
Use case: Historical data
Advanced Examples
Complex projects for production deployments.
Multi-Device System
AdvancedCoordinate multiple devices working together as a fleet.
View on GitHub →