Siren Spark

Difficulty: ● ○ ○ ○ ○

  • Did you know ?

    Police sirens alternate between rising and falling tones not just for drama, but because our brains are wired to detect changing pitches more urgently—making it almost impossible to ignore, even in noisy environments.

No products found in parts_required metafield

How It Works ?

Switch detection: Toggle switch → pin reads HIGH when ON
Siren activation: Switch ON → triggers sound and red-blue LED bursts
Light animation: Matrix flashes random red and blue LEDs → simulates emergency lights
Sound control: Buzzer plays rising and falling tones → mimics real siren pattern
Instant stop: Switch OFF → sound and lights shut down immediately

GENESIS

Connection Guide

Snap your modules as shown above, copy the code into the Arduino IDE and Click upload

example.ino
#include <Adafruit_NeoPixel.h>

#define SWITCH_PIN 14      // Toggle switch
#define BUZZER_PIN 6       // Buzzer pin
#define MATRIX_PIN 10      // NeoMatrix IN pin (GPIO10)
#define MATRIX_SIZE 25     // 5x5 matrix has 25 LEDs

Adafruit_NeoPixel matrix = Adafruit_NeoPixel(MATRIX_SIZE, MATRIX_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pinMode(SWITCH_PIN, INPUT_PULLUP);  // Toggle switch input
  pinMode(BUZZER_PIN, OUTPUT);        // Buzzer output
  matrix.begin();                     // Start NeoMatrix
  matrix.show();                      // All off
}

void policeLightsInterruptible() {
  for (int i = 0; i < 15; i++) {
    if (digitalRead(SWITCH_PIN) == LOW) return;  // Abort if switch turned off

    int randomIndex = random(MATRIX_SIZE);
    uint32_t color = random(2) == 0 ? matrix.Color(255, 0, 0) : matrix.Color(0, 0, 255);
    matrix.setPixelColor(randomIndex, color);
  }
  matrix.show();
  delay(30);
  matrix.clear();
  matrix.show();
}

void sirenInterruptible() {
  for (int i = 0; i < 3; i++) {
    for (int freq = 1000; freq <= 2500; freq += 50) {
      if (digitalRead(SWITCH_PIN) == LOW) {
        noTone(BUZZER_PIN);
        matrix.clear(); matrix.show();
        return;
      }
      tone(BUZZER_PIN, freq, 30);
      policeLightsInterruptible();
    }
    for (int freq = 2500; freq >= 1000; freq -= 50) {
      if (digitalRead(SWITCH_PIN) == LOW) {
        noTone(BUZZER_PIN);
        matrix.clear(); matrix.show();
        return;
      }
      tone(BUZZER_PIN, freq, 30);
      policeLightsInterruptible();
    }
  }
  noTone(BUZZER_PIN);
  delay(300);
}

void loop() {
  if (digitalRead(SWITCH_PIN) == HIGH) {
    sirenInterruptible();  // Run siren with check for early stop
  } else {
    noTone(BUZZER_PIN);       // Ensure buzzer is off
    matrix.clear(); matrix.show();  // Turn off LEDs
  }
}