Smart Doorbell System

Smart Doorbell System

Build a responsive alert system that integrates digital inputs with multi-modal outputs. This project simulates a real-world doorbell using a tactile button, a status LED, and an active buzzer.

Project Goal: Create a system that monitors GP14 for a button press. When triggered, it activates a red status LED on GP15 and sounds an A5 (880Hz) tone on the GP16 buzzer.

1. Wiring Blueprint

From Component Pin Pico Pin Role
Tactile Button Terminal 1 GP14 Digital Input (Pull-up)
Red LED Anode (+) GP15 Visual Indicator
Active Buzzer Positive (+) GP16 Audible Alert (PWM)
Common GND / Negative GND Common Ground Rail

2. JavaScript Implementation

Using the intarva SDK, we implement a non-blocking loop to monitor the button state and trigger the outputs.

JavaScript (SDK)
import { Pico, Pin, PWM } from "intarva";

const LED_PIN = 15;      // GP15
const BUTTON_PIN = 14;   // GP14 (Pull-up)
const BUZZER_PIN = 16;   // GP16 (PWM)

async function main() {
    console.log("Smart Doorbell: System Initialized.");

    while (true) {
        // Read button state (LOW when pressed due to Pull-up)
        const isPressed = await Pico.digitalRead(BUTTON_PIN) === 0;

        if (isPressed) {
            console.log("[Event] Doorbell Pressed!");
            await Pico.digitalWrite(LED_PIN, 1);
            await Pico.tone(BUZZER_PIN, 880); // Play A5 note
        } else {
            await Pico.digitalWrite(LED_PIN, 0);
            await Pico.noTone(BUZZER_PIN);
        }

        await Pico.delay(10); // Loop stability
    }
}

main();