Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe

How to build an app-controlled alarm mat

By Nikhil Agnihotri December 5, 2023

Waking up isn’t always easy, especially when the snooze button is typically only a short reach away. Overcoming the desire to stay in the comfort of our beds often requires an understanding of intrinsic motivation. But we have a solution that requires one simple device — a smart mat.

In this project, we’ll design a smart mat that will work as a morning alarm clock. It not only sounds an alarm but helps inspire you to overcome that morning procrastination of getting out of bed. 

We’ll design a prototype for a smart mat with the necessary electronics to ensure you get up for the day easily. It keeps time and sounds the alarm, which can be programmed from a mobile app. You’ll need a mat and a microcontroller with Bluetooth and WiFi functionality. We use ESP32. A push button and a buzzer are also required. Let’s get started. 

Components required

1. ESP32 x1
2.
Push buttons x as required
3. Buzzer x1
4. Regular mat x1

Circuit connections
A regular mat that can be torn into two layers is needed to get started (the electronics go inside). Prepare an array of push buttons, all connected in parallel and neatly arranged at equal distances from one another over the shape of the mat, as shown in the image below. 

Attach square pieces of a thin plastic sheet or acrylic sheet to the top of the push buttons using glue to form the middle layer. So, when a force is applied on the plastic sheet square, the button is pressed.

The array of push buttons forms the middle layer of the mat. If someone stands on it, multiple buttons will be pressed, and this will short the two wires that connect all of the push buttons in parallel. One of these wires connects to ESP32’s Ground pin, and the other connects to ESP32’s GPIO21 pin.

A buzzer is attached to ESP32 by connecting one of its terminals to the GND and the other to ESP32’s GPIO 18 pin. After making all the connections, the smart mat should look like the circuit diagram below.

The smart mat’s microcontroller circuit is powered by 6A/9A AAA batteries as shown below.

Before installing ESP32 into the mat’s circuit, remember to upload the sketch.

Arduino sketch

Remember to replace the SSID and network key with those of your own WiFi connection.

Mobile application
The alarm is set in the smart mat using a mobile application built using the MIT App Inventor. Login to MIT App Inventor and build a user interface in the Designer as shown below.

The application is built using following components in MIT App Inventor…

The properties of Label1 are set as shown below.

The properties of the TimePicker1 are set as shown below.

The properties of the HorizontalArragement1 are set as shown below.

The properties of Button1 are set as shown below.

The properties of the ListPicker1 are set as shown below.

The properties of the Notifier1 are set, as shown below.

The properties of BluetoothClient1 is set as shown below.

The logic of the app is defined in the block editor as shown below.

The mobile app allows users to set an alarm that’s in the smart mat. To do so, select the Bluetooth device button and the “Smart Wakeup Alarm Mat.” The smart mat is viewed in the app as a Bluetooth device and the button’s text will change to “Connected” once selected.

To set an alarm from the app, simply tap the time picker and select a time for the alarm to sound. Next, press the “Set Alarm” button to set it. The process is demonstrated in the following video.

How project works
To set an alarm in your smart mat, use MIT App Inventor’s mobile app builder. This application lets users use their smart mat as a Bluetooth device. When an alarm is set using the app, the hour and minute values (in a 24-hour format) are sent to ESP32 over Bluetooth as a comma-separated pair of values. 

ESP32 continuously searches for if the alarm is set. If not, it will continue to time-keep by polling the current time from the NTP server. ESP32 must be connected to a WiFi network. The SSID and password for this are hard-coded in the sketch. 

If an alarm is set, ESP32 will compare the current time based on the NTP server with the time set for the alarm. When the hour and minute values match between the current time and alarm time, the alarm is triggered, and the buzzer rings. The alarm continues until the user steps on the mat. This requires them to get out of bed!

When the user steps on the mat, the push buttons are pressed down, shorting the two wires that connect all the buttons in parallel. ESP32 stops playing the alarm as a LOW signal is received from the button network at GPIO21. 

The code
The sketch begins with BluetoothSerial.h, WiFi.h, NTPClient.h, and WiFiUdp.h. If any of these libraries are not found, install them using the library manager. 

Here’s a summary of what each one does in this project:

  • BluetoothSerial.h manages the smart mat (or ESP32) WiFi connection with the mobile application. 
  • WiFi.h manages the Wi-Fi connection with the home Wi-Fi network. 
  • NTPClient.h connects with the online NTP server. 
  • WiFiUdp.h manages the UDP connection over Wi-Fi. 

Afterward, notes for the buzzer are defined, as are the variables are also defined for each pin assignment for the buzzer and the button array. The variables to track the status of the button array, SSID, Wi-Fi network key, current time, hours value, minutes value, seconds value, alarm hours value, alarm minutes value, alarm status, and alarm shutdown status are also defined. Then, the objects of WiFiUdp, NTP client, and Bluetooth Serial are initialized. 

In the setup() function, the pin interfaced to the button array is set as a digital input. The baud rate for the serial communication to debug messages to the serial console is set to 115200. The Bluetooth is initialized with name “Smart Wakeup Alarm Mat.” 

ESP32 connects to the Wi-Fi network and the NTP client is initialized and configured for the correct time zone. 

The user-defined function stringToCharArray() is defined to extract values from the string data received over Bluetooth and Wi-Fi networks. The function playAlarm() signals the alarm by setting off the buzzer. The function senseInput() detects if the button array is pressed and if so, it shuts off the alarm. 

In the loop() function, ESP32 uses a Bluetooth connection to search for the data received from the mobile app. If data is received, the alarm is set, and its hour and minute values are stored. The status of the alarm is set to TRUE, and the status for the alarm to shut off is set to FALSE. 

It then retrieves the current time from the NTP server and extracts the current hour and minute values. These values are compared with those of the set alarm. If they match, the alarm is triggered. The alarm does not turn off until the button array is pressed by stepping over on the mat.  

Results
This image shows a compilation of the debug messages received from the smart wakeup alarm mat.  

You may also like:


  • The top mobile app development tools for IoT and electronics

  • How to get started with MIT App Inventor

  • What are the top weather APIs for the IoT?

  • How to design an IoT-based smart alarm

  • How to design a smartphone-operated door lock

  • How to build a WhatsApp-notifying home security system

Filed Under: Electronic Projects, ESP8266
Tagged With: alarm, bluetooth, ESP32, smartmat
 

Next Article

← Previous Article
Next Article →

Questions related to this article?
👉Ask and discuss on EDAboard.com and Electro-Tech-Online.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

EE TECH TOOLBOX

“ee
Tech Toolbox: Internet of Things
Explore practical strategies for minimizing attack surfaces, managing memory efficiently, and securing firmware. Download now to ensure your IoT implementations remain secure, efficient, and future-ready.

EE Learning Center

EE Learning Center
“engineers
EXPAND YOUR KNOWLEDGE AND STAY CONNECTED
Get the latest info on technologies, tools and strategies for EE professionals.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


RSS EDABOARD.com Discussions

  • Multiple DC/DC converters and a single input source
  • Voltage mode pushpull is a nonsense SMPS?
  • High Side current sensing
  • Reducing "shoot-through" in offline Full Bridge SMPS?
  • MOSFET thermal noise in Weak vs Strong inversion

RSS Electro-Tech-Online.com Discussions

  • PIC KIT 3 not able to program dsPIC
  • Failure of polypropylene motor-run capacitors
  • Siemens large industrial PLC parts
  • Wideband matching an electrically short bowtie antenna; 50 ohm, 434 MHz
  • Curved lines in PCB design

Featured – RPi Python Programming (27 Part)

  • RPi Python Programming 21: The SIM900A AT commands
  • RPi Python Programming 22: Calls & SMS using a SIM900A GSM-GPRS modem
  • RPi Python Programming 23: Interfacing a NEO-6MV2 GPS module with Raspberry Pi
  • RPi Python Programming 24: I2C explained
  • RPi Python Programming 25 – Synchronous serial communication in Raspberry Pi using I2C protocol
  • RPi Python Programming 26 – Interfacing ADXL345 accelerometer sensor with Raspberry Pi

Recent Articles

  • What is AWS IoT Core and when should you use it?
  • AC-DC power supply extends voltage range to 800 V DC
  • Infineon’s inductive sensor integrates coil system driver, signal conditioning circuits and DSP
  • Arm Cortex-M23 MCU delivers 87.5 µA/MHz active mode
  • STMicroelectronics releases automotive amplifiers with in-play open-load detection

EE ENGINEERING TRAINING DAYS

engineering

Submit a Guest Post

submit a guest post
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • Battery Power Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • EV Engineering
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • Subscribe to our newsletter
  • About Us
  • Contact Us
  • Advertise

Copyright © 2025 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy

Search Engineers Garage

  • Electronic Projects & Tutorials
    • Electronic Projects
      • Arduino Projects
      • AVR
      • Raspberry pi
      • ESP8266
      • BeagleBone
      • 8051 Microcontroller
      • ARM
      • PIC Microcontroller
      • STM32
    • Tutorials
      • Audio Electronics
      • Battery Management
      • Brainwave
      • Electric Vehicles
      • EMI/EMC/RFI
      • Hardware Filters
      • IoT tutorials
      • Power Tutorials
      • Python
      • Sensors
      • USB
      • VHDL
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Product News
    • Business News
    • Company/Start-up News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • DigiKey Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Learn
    • eBooks/Tech Tips
    • Design Guides
    • Learning Center
    • Tech Toolboxes
    • Webinars & Digital Events
  • Resources
    • Digital Issues
    • EE Training Days
    • LEAP Awards
    • Podcasts
    • Webinars / Digital Events
    • White Papers
    • Engineering Diversity & Inclusion
    • DesignFast
  • Guest Post Guidelines
  • Advertise
  • Subscribe