Table of contents:

Another example of an elementary device based on an ESP32 microcontroller is a home alarm system. The device consists of only three elements: a microcontroller, a motion sensor, and a buzzer. It can be installed in a drawer, closet, and even at the house’s front door. If the sensor detects motion, the mobile app will alert you via push notification.

Assembling the device

The following elements will be required for assembling a home alarm system:

ESP32 microcontroller 1 pc.
motion sensor 1 pc.
buzzer 1 pc.

 

Additionally, you will need wires to connect these elements. We also used a breadboard to facilitate device assembly and testing. In general, however, a breadboard is an optional component. Without it, the device becomes more compact and it is more convenient to store it in a desk drawer or closet.

Here’s how a ready-made alarm looks like on a breadboard:

Alarm system on a breadboard Alarm system on a breadboard Alarm system on a breadboard

Writing firmware for alarm system

We wrote the firmware for the device using the ESPHome tool. Here is the complete firmware code that you can use to build a similar device:

switch:
    - platform: gpio
      id: buzzer
      name: buzzer
      pin:
        number: GPIO22
        inverted: true
    - platform: gpio
      id: state
      name: state
      pin:
        number: GPIO2
binary_sensor:
  - platform: gpio
    pin: GPIO18
    name: "PIR Sensor"
    device_class: motion
    on_press:
      then:
        - mqtt.notify:
                    payload: |-
                      root["logLevel"] = "info";
                      root["message"] = "Motion Detected";
        - if:
            condition:
              switch.is_on: state
            then:
              switch.turn_on: buzzer
                
    on_release:
      then:
        - mqtt.notify:
                    payload: |-
                      root["logLevel"] = "info";
                      root["message"] = "Horizont is clear";
        - if:
            condition:
              switch.is_on: state
            then:
              switch.turn_off: buzzer
                
    
    filters:
      - delayed_on: 100ms

The device is based on the 2Smart Cloud custom IoT development platform, which supports ESPHome as a tool for creating professional IoT products. We just pasted this code into the editor window in the vendor’s board. After that, we downloaded the test firmware, flashed the device, and configured the interface of the mobile application for alarm control.

These features are free if you connect no more than 20 devices to the platform. The mobile app for ESPHome devices connection is also a free feature of 2Smart Cloud.

2Smart Cloud platform interface

Let’s collaborate

We’re empower your business with our technology expertise

Let’s discuss your case

How the alarm system works

By default, the device detects motion using a sensor and sends notifications to the mobile application about each occurrence.

Notofocations screen of the 2Smart Cloud mibile app

The Motion Sensor widget on the app screen also indicates that motion has been detected.

Device screen of the 2Smart Cloud mibile app

Device screen of the 2Smart Cloud mibile app

Additionally, an observing mode is provided; if it is turned on, the alarm is activated. As soon as the device detects motion, the buzzer starts beeping, and a notification is sent to the mobile application.

The buzzer can be turned off. For this, we have also added a separate widget.

2Smart Cloud supports integration with voice assistants in a mobile phone. Therefore, we can activate the alarm with the phrase: “OK Google, turn on the guard.” And if you use an iPhone, you can set up a shortcut that will automatically turn on the alarm when you leave home and turn it off when you return.

P.S. An alarm signal doesn’t necessarily mean that someone has entered your home. Sometimes it’s just a cat.

Rate this article:

4.9 / 5. 7

( 7 votes )

Don't forget to share this post!

Let’s dive into your case

Share with us your business idea and expectations about the software or additional services.

    Thanks for contacting us!

    We will get in touch soon.

    This site is protected by Google reCAPTCHA and the following Privacy policy and Terms of use apply

    Send us a message

    This site is protected by Google reCAPTCHA and the following Privacy policy and Terms of use apply