30 July 2024

Pocketable Nano Alert Alarm

If you want to alert someone nearby to a situation, especially a dangerous or unpleasant situation, this Arduino Nano microcontroller based pocketable alert alarm will help you!



Below is the wiring diagram of the 9V battery powered Nano Alert Alarm (click to enlarge).

Here is the list of parts:

  • Arduino Nano v3 x1
  • 5V Passive Buzzer (Piezo Speaker) x1
  • 5mm Red LED x1
  • 150Ω Resistor x1 (optional - or just use a zero-ohm jumper)
  • 470Ω Resistor x1
  • 470uF/16V Electrolytic Capacitor x1
  • Push Button Switch (NO) x1
  • 9V 6F22 Battery x1
The Arduino Sketch of this project is pretty simple and straight forward (see below).

int ledPin = 13; //LED Pin

int inputPin = 8; //Alarm Button Pin
int pinSpeaker = 9; //Passive Buzzer Pin
int val = 0;

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(inputPin, INPUT_PULLUP); //Internal Pullup Enabled
  pinMode(pinSpeaker, OUTPUT);
  }

void loop() {
  val = digitalRead(inputPin);
  if (val == LOW) {
    digitalWrite(ledPin, HIGH);
    playTone(300, 160);
    delay(150);

  } else {

    digitalWrite(ledPin, LOW);
    playTone(0, 0);
  }
}
// duration in mSecs, frequency in hertz
void playTone(long duration, int freq) {
  duration *= 1000;
  int period = (1.0 / freq) * 1000000;
  long elapsed_time = 0;
  while (elapsed_time < duration) {
    digitalWrite(pinSpeaker, HIGH);
    delayMicroseconds(period / 2);
    digitalWrite(pinSpeaker, LOW);
    delayMicroseconds(period / 2);
    elapsed_time += (period);
  }
}

In Arduino, the tone() function generates a 50% duty cycle square wave of the specified frequency on a pin. A duration can be specified, otherwise the wave continues until a call to noTone().

That pin then can be wired to a small piezo buzzer or piezo speaker to play tones.

What is the function of playTone?
  • playTone(a,pin,frequency,duration) plays a tone on a piezo speaker attached to the digital pin on Arduino at the specified pin and frequency for the specified duration.
  • playTone(a,pin) plays a tone on a piezo speaker attached to the digital pin on Arduino.
  • playTone(a,pin,frequency) plays a tone on a piezo speaker attached to the digital pin on Arduino at the specified pin and frequency.
Syntax
  • playTone(a,pin,frequency,duration)
  • playTone(a,pin)
  • playTone(a,pin,frequency)
For more details, see this official Arduino page!

That's it for now. Gather the necessary parts and set up your own pocketable Nano alert alarm.

The pocket alert alarm (personal safety alarm) can be carried in a pocket, purse, or attached to a belt so that it can be used in an emergency situation to call for help, draw attention to an unsafe situation, or to scare off an attacker.

Simply push and hold the alarm button and the alarm will sound and the light will flash.

Finally, test your alarm periodically and replace the battery as needed. Cheers!

No comments:

Post a Comment

We welcome your comments and opinions on our posts but play nice.

We will not edit or delete comments unless they contain off-topic statements or promotional links, false facts, spam or obviously fake profiles!