TINKER PiEDESIGN IN INDIA

Home alarm with phone alerts

Arm the alarm from your phone. If the PIR sensor sees movement while armed, your phone gets a notification.

IoTWi-FiPIRnotifications

Open in TinkerPie Studio

What you need

Wiring

Put your Wi-Fi name and password in the first block. Then open the address shown in the console on a phone on the same Wi-Fi. For notifications, install the free "ntfy" app on the phone and subscribe to the same channel name as in the program (pick your own secret name). PIR: OUT → S1.

Step by step

  1. Open Home alarm with phone alerts in TinkerPie Studio. It opens as blocks.
  2. Wire it: Put your Wi-Fi name and password in the first block. Then open the address shown in the console on a phone on the same Wi-Fi. For notifications, install the free "ntfy" app on the phone and subscribe to the same channel name as in the program (pick your own secret name). PIR: OUT → S1.
  3. Press Run to try it in the simulator. Use the sliders and buttons under the board picture to test it.
  4. Type your Wi-Fi name and password into the connect to Wi-Fi block.
  5. Connect TinkerPie with a USB-C cable in Chrome or Edge, press Connect, then Download. Or, with Studio started from the TinkerPie launcher on your computer, open the Arduino C++ tab and press Build & Flash.
  6. Change something: a colour, a number, a sound. Then run it again.

The code

This is the program the blocks make. The same program runs in the simulator and on the board.

JavaScript
var armed, sent;

dashboard.onButton('ARM', function () {
  armed = true;
  sent = false;
  dashboard.show('Alarm', 'ARMED');
  basic.showIcon(IconNames.Yes, Colors.Red);
});
dashboard.onButton('DISARM', function () {
  armed = false;
  dashboard.show('Alarm', 'OFF');
  basic.clearScreen();
});
basic.forever(function () {
  if (armed && sensors.pirMotion(Pin.S1) && !sent) {
    iot.notify('Movement at home! The alarm saw someone.');
    sent = true;
    dashboard.show('Alarm', 'MOVEMENT!');
    led.fill(Colors.Red);
  }
  basic.pause(200);
});

armed = false;
sent = false;
basic.showIcon(IconNames.Square, Colors.Blue);
wifi.connect('my-wifi', 'my-password');
iot.setNotifyTopic('tinkerpie-alarm-change-me');
dashboard.show('Alarm', 'OFF');
basic.showIcon(IconNames.Yes, Colors.Green);
Arduino C++ (TinkerPie library)
// Home alarm with phone alerts
// Arduino C++ made by TinkerPie Studio from the blocks. Board: TinkerPie V1 (ESP32-S3).
// Arduino IDE: install the TinkerPie library (Studio menu > Arduino library), then Tools > Board > ESP32S3 Dev Module,
// USB CDC On Boot: Enabled, Flash Size: 16MB, Partition Scheme: 16M Flash (3MB APP/9.9MB FATFS), PSRAM: OPI PSRAM.
#include <TinkerPie.h>
using namespace tinkerpie;

bool armed = false;
bool sent = false;

void setup() {
  tinkerpie::begin();
  dashboard::onButton("ARM", []() {
    armed = true;
    sent = false;
    dashboard::show("Alarm", "ARMED");
    basic::showIcon(IconNames::Yes, Colors::Red);
  });
  dashboard::onButton("DISARM", []() {
    armed = false;
    dashboard::show("Alarm", "OFF");
    basic::clearScreen();
  });
  basic::forever([]() {
    if (armed && sensors::pirMotion(Pin::S1) && !sent) {
      iot::notify("Movement at home! The alarm saw someone.");
      sent = true;
      dashboard::show("Alarm", "MOVEMENT!");
      led::fill(Colors::Red);
    }
    basic::pause(200);
  });

  armed = false;
  sent = false;
  basic::showIcon(IconNames::Square, Colors::Blue);
  wifi::connect("my-wifi", "my-password");
  iot::setNotifyTopic("tinkerpie-alarm-change-me");
  dashboard::show("Alarm", "OFF");
  basic::showIcon(IconNames::Yes, Colors::Green);
}

void loop() {
  tinkerpie::loop();   // runs the forever blocks and handles events
}

More projects like this

Intruder alarmA PIR motion sensor sees someone moving: red flashes and a siren.Sensor projectsPhone weather stationTemperature, humidity and light from the board, live on your phone.IoTPhone-controlled robotButtons on your phone drive a two-wheel robot. The slider sets the speed.IoTDoorbell notifierPress A: a bell rings and your phone gets a notification, even from another room.IoTCloud thermometer (ThingSpeak)Logs temperature and light to a ThingSpeak channel every 20 seconds: graphs you can open anywhere.IoTSmart plant monitorSoil moisture on your phone dashboard, a notification when the plant is thirsty, and a ThingSpeak log.IoT