Step by Step Guide

In this project, you will build a simple vibration-triggered alarm system using the Pixie M1. When the vibration switch detects movement, the buzzer will sound, and the LED will blink. The alarm can be turned off by pressing the button three times. This project introduces you to reading sensor input (vibration switch), controlling outputs (LED and buzzer), and implementing a basic disarm function with a push button.


What You'll Need

2. Make the Connections


Connect the parts as shown by the diagram bellow

Vibration Switch Module

  • G (Ground) → Breadboard ground rail (blue/negative row)
  • VIN (Power) → Pixie M1 3V3 pin
  • S (Signal) → Pixie M1 Pin 1

Buzzer Module

  • G (Ground) → Breadboard ground rail (blue/negative row)
  • VIN (Power) → Pixie M1 3V3 pin
  • D (Signal) → Pixie M1 Pin 2

NeoPixel Module

  • G (Ground) → Breadboard ground rail (blue/negative row)
  • VIN (Power) → Pixie M1 3V3 pin
  • S (Signal) → Pixie M1 Pin 3

Push Button Module

  • G (Ground) → Breadboard ground rail (blue/negative row)
  • VIN (Power) → Pixie M1 3V3 pin
  • S (Signal) → Pixie M1 Pin 4

4. Connect to PC & Upload Code

  • Install Arduino IDE and Setup Axiometa PIXIE M1 if you haven't already
  • Connect the Pixie M1 to your computer using the USB-C cable
  • Select the correct board in Arduino IDE:
  • Go to Tools → Board →  Axiometa Pixie M1
  • Copy and Paste the code you can find at the end of this page.
  • Upload code (CMD+U or CTRL+U)

5. Test

After uploading Flick the Breadboard - the alarm sequence should begin:

  • The NeoPixel Should should blink and the buzzer should beep
  • Press the button three times to disable the alarm
  • Flick the breadboard once again and the alarm should trigger again

Next Steps:

  • Change the timing of buzzer and NeoPixel
  • Add different sequence to disable the alarm
Back to blog

Arduino Code

example.ino
#include <Adafruit_NeoPixel.h>

#define NEOPIXEL_PIN 3
#define NUM_PIXELS 1
#define BUTTON_PIN 2
#define VIBRATION_PIN 1
#define BUZZER_PIN 9

Adafruit_NeoPixel strip(NUM_PIXELS, NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800);

bool alarmActive = false;
bool ledState = false;

unsigned long previousMillis = 0;
const long blinkInterval = 150;

// Triple press detection
int pressCount = 0;
unsigned long lastPressTime = 0;
const unsigned long pressWindow = 1000;

// Vibration debounce
bool isVibrationTriggered() {
  static unsigned long vibrationStart = 0;
  if (digitalRead(VIBRATION_PIN) == HIGH) {
    if (millis() - vibrationStart > 10) return true;
  } else {
    vibrationStart = millis();
  }
  return false;
}

void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(VIBRATION_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);

  strip.begin();
  strip.setBrightness(100);
  strip.show();

  Serial.begin(115200);
  Serial.println("System ready.");
}

void loop() {
  if (!alarmActive && isVibrationTriggered()) {
    triggerAlarm();
  }

  if (alarmActive) {
    handleAlarmBlinking();
    checkButtonTriplePress();
  }
}

void triggerAlarm() {
  alarmActive = true;
  Serial.println("⚠️ Vibration detected!");
}

void handleAlarmBlinking() {
  unsigned long currentMillis = millis();
  if (currentMillis - previousMillis >= blinkInterval) {
    previousMillis = currentMillis;
    ledState = !ledState;

    if (ledState) {
      strip.setPixelColor(0, strip.Color(255, 0, 0));  // Red
      digitalWrite(BUZZER_PIN, HIGH);
    } else {
      strip.clear();
      strip.show();
      digitalWrite(BUZZER_PIN, LOW);
    }
    strip.show();
  }
}

void checkButtonTriplePress() {
  static bool lastButtonState = HIGH;
  bool currentButtonState = digitalRead(BUTTON_PIN);

  if (lastButtonState == HIGH && currentButtonState == LOW) {
    unsigned long now = millis();
    if (now - lastPressTime > pressWindow) {
      pressCount = 1;
    } else {
      pressCount++;
    }
    lastPressTime = now;

    Serial.print("Press count: ");
    Serial.println(pressCount);

    if (pressCount >= 3) {
      resetAlarm();
    }
  }

  lastButtonState = currentButtonState;
}

void resetAlarm() {
  alarmActive = false;
  digitalWrite(BUZZER_PIN, LOW);
  strip.clear();
  strip.show();
  pressCount = 0;
  Serial.println("✅ Alarm reset.");
}