Today’s project deals with a simple silent alarm system with password input for resetting the alarm. So that you get anything at all from the alarm, the board sends a push message to your smartphone. We’ll set the tilt sensor that’s behind today’s door as a motion detector. It can give information about vibrations and thus inform you if someone tips the NanoESP board.

Aufbau mit Tiltsensor
Layout with tilt sensor
The sketch: A16_P13_Blynk9_PushAlarm.ino
/*
  Blnky9: PushAlarm
  Change ssid, password and token
*/

char ssid[] = "YourSSID";
char password[] = "YourPassword";
char token[] = "YourToken";

String passwordAlarm = "password";
String  alarmMsg = "Alarm! Someone touched the NanoESP!";

#define BLYNK_DEBUG
#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <ESP8266_SoftSer.h>
#include <BlynkSimpleShieldEsp8266_SoftSer.h>
#include <SimpleTimer.h>

// Set ESP8266 Serial object
#include <SoftwareSerial.h>
SoftwareSerial EspSerial(11, 12); // RX, TX

ESP8266 wifi(EspSerial);
SimpleTimer timer;

WidgetTerminal terminal(V1);

boolean alarm = false;

void setup()
{
  // Set console baud rate
  Serial.begin(19200);
  EspSerial.begin(19200);

  Blynk.begin(token, wifi, ssid, password);

  //push msg
  Blynk.notify("Alarm active");

  pinMode(2, INPUT_PULLUP);
  
  //timer for blinking led on alarm
  timer.setInterval(1000L, blinkAlarm);
}

void loop()
{
  Blynk.run();
  if (alarm) timer.run(); else digitalWrite(13, LOW); //blink if alarm active

  if (digitalRead(2)) { //read tilt sensor
    if (!alarm) {
      alarm = true;

      Blynk.notify(alarmMsg); //push msg on alarm

      terminal.println(F("Alarm! Type in Password:"));
      terminal.flush();
    }
  }
}


BLYNK_CONNECTED() {
  Blynk.syncAll();

  terminal.println(F("Blynk v" BLYNK_VERSION ": Device started"));
  terminal.println("-------------");
  terminal.flush();
}


BLYNK_WRITE(V1) //Terminal
{
  //type in password on alarm
  if (alarm) {

    String passInput = param.asStr();
    
    if (passwordAlarm == passInput) {
      alarm = false;
      terminal.println(F("Alarm deaktivated"));
      terminal.flush();

    }
    else {
      terminal.println(F("Wrong password!"));
      terminal.flush();
    }
  }
}


//timer function for blinking led on alarm
void blinkAlarm()
{
  digitalWrite(13, !digitalRead(13));
}

(The former Arduino Create embed is no longer available; the code is taken from the download of all sketches.)

blynk_tag1313

The Blynk interface for today’s project is kept quite simple. There is a terminal through which the important information is delivered. At the same time, the terminal is used to input the password. Set the password in the programme. If you haven’t entered anything, the password is “password”. There’s also another element, namely the push widget. Push messages are sent through it to your mobile. Push means that the message appears directly as a message on your smartphone. In the widget, you can choose between “Normal” and “High Priority.” With High Priority, the message is displayed immediately, but it needs significantly more battery. Now if someone tries to steal your NanoESP, you’ll get a message directly on your mobile.

Jemand hat am Board gewackelt
Someone moved the NanoESP