An all-in-one IoT device built on the M5Stack Core2 that monitors noise levels, provides real-time visual feedback, and sends cloud alerts to a live web dashboard, helping maintain a perfect study environment.
The Story: The Quest for Quiet π€«Weβve all been there: you find the perfect spot in the library, ready to dive into your studies, only to be disrupted by a loud conversation nearby. Libraries are sanctuaries of silence, but maintaining that atmosphere is a constant challenge. Staff can't be everywhere, and often, people don't even realize they're being disruptive.
This project was born from a simple idea: what if technology could provide a gentle, automated nudge to maintain a peaceful environment?
I designed a smart, non-intrusive noise monitoring system that:
- Measures ambient noise in real-time.
- Provides immediate, visual feedback using a color-coded LED ring.
- Alerts library staff automatically via MQTT when noise exceeds a set threshold.
- Reports data to a live web dashboard for centralized monitoring.
The system is now live and can be viewed here: https://lib-room-manager.lovable.app [you would need to setup your device and MQTT or send a message through the HiveMQ webclient to see it working]
Why the M5Stack Core2 for AWS EduKit?This project needed a device that was simple, integrated, and powerful. The M5Stack Core2 for AWS EduKit was the perfect choice because it's an all-in-one platform with everything I needed out of the box:
- Built-in Microphone: No need for external sensors.
- Touchscreen Display: Perfect for showing real-time data like dB levels, time, and battery.
- RGB LED Ring: The ideal way to provide silent, intuitive, color-coded feedback.
- Rechargeable Battery & Wi-Fi: Allows for completely wireless and portable deployment.
---
Things You'll Need π οΈHardware
Software & Cloud Services
- Arduino IDE
- HiveMQ Cloud: We will use the free tier for our MQTT broker.
- Frontend : lovable.dev for bootstrapping the UI and Visual Studio Code for customization.
Arduino Libraries
- M5Unified
- PubSubClient
- ArduinoJson
- FastLED
---
How It Works: The Technical Deep DiveThe system operates in a continuous loop: listen, classify, visualize, and alert.
1. Listening and Classifying Noise:
The built-in I2S microphone constantly samples ambient sound. The code calculates the average amplitude and converts it to a decibel (dB) value. This value is then classified into three levels:
- Quiet (< 35 dB): The ideal study environment. The LED ring glows a calm Green.
- Normal (35β60 dB): A low level of ambient noise. The LEDs turn Orange as a gentle nudge. and if it stays like that for a few seconds, an alert is send.
- Loud (> 60 dB): The noise is disruptive. The LEDs flash Red, and a JSON alert is sent to the cloud.
2. The Pivot: Why HiveMQ Instead of AWS IoT?
- Initially, I planned to use AWS IoT Core. It's powerful and secure. However, I re-evaluated the project's needs vs complexity:
- Cost: While AWS has a free tier, it can become costly as you scale. HiveMQ Cloud offers a completely free plan that's perfect for this scale.
- Data Sensitivity: The data being sent is just a noise level (e.g., "72 dB"). It's not sensitive or private information. The security of AWS, while excellent, was overkill.
- Simplicity: HiveMQ's public broker and native WebSocket support were a huge win. It allowed my web dashboard to subscribe to MQTT messages *directly* in the browser, eliminating the need for a complex backend or AWS Lambda functions.
Think of it like a postal service: HiveMQ is the post office, the M5Stack is the sender, the topic (`library/noise/area1/alerts`) is the mailbox, and the web dashboard is the recipient. WebSockets are like getting your mail delivered instantly via email instead of waiting for a truck.
3. Setting up HiveMQ Cloud
- 1. Go to the HiveMQ Cloud Portal and sign up for the free plan.
- 2. Create a new cluster. Once it's deployed, you will get the Broker URL, Port, Username, and Password.
- 3. Under the "Access Management" tab, create a new user with a username and password. This is what the M5Stack will use to connect.
- 4. You will use these credentials in the Arduino code.
---
The Code π¨βπ»Setting up the Environment:
- Installed the Arduino IDE and the necessary board support for the M5Stack Core2.
- Installed the required libraries: M5Unified, PubSubClient, ArduinoJson, and FastLED.
Capturing and Processing Noise:
- The M5.Mic.record() function was used to capture audio samples from the built-in PDM microphone into a buffer.
- The code calculates the average amplitude of the samples and converts this into a decibel value using a logarithmic formula.
- A calibration offset (MIC_CALIBRATION_DB_OFFSET) was added and tuned through real-world testing to ensure the dB readings were accurate.
Designing the User Interface:
- LEDs: The FastLED library was used to program the RGB LED ring. Simple logic was written to set the color to green, orange, or red based on the currentNoiseCategory. A flashing red effect was added for "Loud" alerts to draw attention.
- Display: The M5.Display library was used to design a clear UI. The screen is divided to show the battery level, a large digital clock, the date, and the current dB reading with corresponding colors. The code is optimized to only redraw parts of the screen when their values change, which prevents flickering and improves performance.
Connecting to HiveMQ:
- The device's Wi-Fi was configured to connect to a local network.
- Time was synchronized using an NTP (Network Time Protocol) server to ensure accurate timestamps on alerts.
- The PubSubClient was configured with the HiveMQ broker address, port, and user credentials. The netClient.setInsecure() function is used because we are connecting to a public broker where certificate validation is handled differently than in a private AWS setup.
- A state machine (handleMQTTTaskMachine) was implemented to manage the connection process. When an alert is triggered, the machine moves through states: MQTT_SHOW_STATUS -> MQTT_PENDING_CONNECTION -> MQTT_PENDING_SEND -> MQTT_PENDING_DISCONNECT. This ensures a clean, reliable, and non-blocking process for sending alerts.
Final Touches and Optimization:
- A "grace period" on startup was added to prevent false alerts while the microphone initializes.
- The microphone buffer handling was optimized to prevent crashes or freezes.
- The thresholds for Quiet, Normal, and Loud were fine-tuned by testing the device in different environments to ensure they felt right.
Below is the Arduino code for the device. Make sure you have the required libraries installed. You will need to fill in your Wi-Fi and HiveMQ credentials in the configuration section.
#include <M5Unified.h>
#include <WiFi.h>
#include <WiFiClientSecure.h>
#include <PubSubClient.h>
#include <ArduinoJson.h>
#include <time.h>
#include <math.h>
#include <FastLED.h>
//====================================================================================
// 1. CONFIGURATION - !!! FILL IN YOUR DETAILS HERE !!!
//====================================================================================
const char* WIFI_SSID = "YOUR_WIFI_SSID";
const char* WIFI_PASSWORD = "YOUR_WIFI_PASSWORD";
// --- HiveMQ Broker Configuration ---
const char* HIVEMQ_BROKER = "YOUR_HIVEMQ_URL.s1.eu.hivemq.cloud";
const int HIVEMQ_PORT = 8883; // Standard TLS Port
const char* HIVEMQ_USERNAME = "YOUR_HIVEMQ_USERNAME";
const char* HIVEMQ_PASSWORD = "YOUR_HIVEMQ_PASSWORD";
const char* MQTT_CLIENT_ID = "library-device-area1"; // Give each device a unique ID
const char* MQTT_TOPIC_PUBLISH = "library/noise/area1/alerts";
// --- Timezone Settings (Example: India Standard Time) ---
const long GMT_OFFSET_SEC = 19800;
const int DAYLIGHT_OFFSET_SEC = 0;
const char* NTP_SERVER_1 = "pool.ntp.org";
const char* NTP_SERVER_2 = "time.nist.gov";
You can find the full, ready-to-use code in the GitHub Repository(https://github.com/AmaljithCf/Library-Study-NoiseMonitor.git).
---
The Librarian's Command Center: The DashboardThe true power of this system comes from its centralized dashboard. Built using lovable.dev and customized with VS Code, the dashboard connects to HiveMQ via WebSockets and provides a real-time overview of the entire library.
As you can see, librarians can:
- Monitor Multiple Areas:* See the status of the "Reading Hall, " "Children Zone, " and "Computer Lab" all at once.
- Set Custom Thresholds: Each area has its own noise limit, because a children's area has different expectations than a silent reading hall.
- Get Instant Alerts: When a threshold is breached (like in the Reading Hall), a prominent alert pops up, telling staff exactly where the problem is.
This allows for incredibly efficient management. Instead of patrolling, staff can respond precisely when and where they are needed, armed with objective data.
Beyond Noise: A Tool for Leadership and Self-DisciplineAfter building this, I realized its impact is far greater than just noise management. It's a behavioral tool.
- Fosters Self-Awareness: The gentle, visual nudge of the LED ring helps people, especially kids, become more aware of their own volume without feeling singled out.
- Encourages Shared Responsibility: The goal becomes a collaborative game of "let's keep the light green." It shifts the dynamic from being "policed" to collectively owning the atmosphere of the space.
- Builds Leadership: When a child sees the light turn orange and says, "Hey guys, let's quiet down, " they are practicing positive peer leadership. The device provides the objective prompt, making it easier for them to take that initiative.
---
Next Steps and Future Ideas πThis project is a solid foundation, but there's so much more that can be built on top of it:
- Analytics Dashboard: Log the data over time to identify noise patterns. Are Tuesday afternoons always the loudest? This data can inform staffing and policy decisions.
- Noise Heatmaps: Deploy multiple devices to create a visual heatmap of the quietest and loudest zones in the library.
- Automated Policies: Programmatically change thresholds for specific "quiet hours."
- Deeper Integration: Connect the alerts to other systems like Slack or a staff communication app.
This project demonstrates how a simple IoT device can solve a real-world problem in a thoughtful and effective way, creating a better environment for everyone.
Comments