Real examples,
ready to deploy

Copy, paste, and customize these examples for your projects.

Basic Examples

Get started with these foundational examples.

Blink LED

Beginner

The "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

Beginner

React 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

Beginner

Read 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

Intermediate

Read temperature, humidity, and pressure via I2C.

Protocol: I2C

Messages: ~4,320/day (3/min)

Motion Detector

Intermediate

PIR motion sensor with event-based alerts.

Hardware: PIR sensor

Messages: Event-based

Light Level Monitor

Beginner

Track ambient light with a photoresistor.

Hardware: Photoresistor + ADC

Messages: ~288/day (1/5min)

Integration Examples

Connect your devices to external services.

Discord Alerts

Intermediate

Send 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

Intermediate

Send email alerts when thresholds are exceeded.

Integration: Resend / SendGrid

Use case: Critical alerts

Data Logger

Intermediate

Log 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

Advanced

Coordinate multiple devices working together as a fleet.

View on GitHub →

Smart Thermostat

Advanced

Temperature control with relay and scheduling logic.

View on GitHub →

Plant Watering

Advanced

Automated irrigation based on soil moisture levels.

View on GitHub →

Ready to try these examples?

Sign up and start building in minutes.