Campus Noise Level Monitor - shalan/CSCE4301-WiKi GitHub Wiki

Project Title: Campus Noise Level Monitor

GitHub Repository: github.com/kirollos21/Campus-Noise-Level-Monitor

Name GitHub
Mohab Bahnassy mohab-bahnassy
Kirollos Zikry kirollos21
Farida Said faridaasaidd

Course: CSCE 4301 - Embedded Systems Semester: Spring 2026 Primary contact: Mohab Bahnassy - [email protected]


1. The Proposal

Abstract / Elevator Pitch

The Campus Noise Level Monitor is an STM32L4-based embedded system that continuously samples ambient sound in a room, classifies it into one of three states (QUIET, WARN, ALARM), and responds with coordinated visual and display feedback. Sound is captured via an analog microphone module processed through the STM32 internal ADC. A push-button allows occupants to cycle through threshold presets suited to different room types (Library, Study Room, Lab), while a UART interface lets facility staff log data and fine-tune thresholds from a connected PC terminal.

The system is designed to encourage awareness of noise levels in shared academic spaces. By providing real-time feedback through LEDs and a Pmod CLP 16x2 LCD display, it gives occupants immediate, unambiguous signals without requiring any interaction with a remote system. Facility staff can monitor and adjust the system through a wired serial connection, making the workflow reliable without depending on wireless infrastructure. A companion PC GUI (noise_monitor_gui.py) provides a live real-time chart of averaged and peak-to-peak noise readings, a colour-coded state badge, slider-based threshold controls, and a colour-tagged log view, all communicating with the firmware over the same UART2 link.

Project Objectives & Scope

Minimum Viable Product (MVP):

  • Analog sound sampling at 50 Hz via internal ADC (PB0).
  • Three-state classification system: QUIET, WARN, ALARM.
  • Pmod CLP LCD display showing live noise index, a visual intensity bar, and active preset name.
  • Red and green LED indicators signaling threshold status.
  • Push-button preset cycling: Library (quietest), Study Room, Lab (loudest).
  • UART logging of every sample to a PC terminal at 115200 baud.
  • UART runtime threshold override commands (SET THR WARN <n> / SET THR ALARM <n>).
  • PC GUI (noise_monitor_gui.py) real-time live chart, state badge, slider threshold controls, and colour-tagged log, communicating over UART2.

Stretch Goals:

  • Persistent threshold storage in Flash/EEPROM so settings survive power cycles.
  • Timestamped UART log entries using a software RTC seeded at startup.
  • CSV export mode for UART log output for easier data analysis.

2. System Architecture

2.1 High-Level Block Diagram

Subsystem Breakdown

The system is organized around the Nucleo-F303K8 as the central processing unit. The analog microphone connects to PB0, where a burst of 64 samples is taken every 100ms via the internal ADC to calculate a peak-to-peak amplitude. A Tim2 interrupt fires every 100ms to trigger this sampling, apply an 8-sample moving-average filter, and evaluate the noise state.

The classification result drives two output subsystems: the GPIO-controlled red and green LEDs (PB5, PB4) and the Pmod CLP 16x2 LCD connected via an 8-bit parallel data bus. A push-button on PA10 is polled with software debounce to allow the user to cycle through the three built-in presets.

The UART2 peripheral (PA2/PA15) serves as the primary interface for facility staff. It transmits a log entry for every sample to a PC terminal/GUI and receives text commands that are parsed to allow runtime threshold adjustment without reflashing the device.


3. Hardware Design

Component Selection

The MAX9812 analog microphone was selected for its simplicity and ease of integration with the STM32's 12-bit ADC. While the original proposal considered I2C MEMS, the analog approach allows for high-speed burst sampling to capture peak-to-peak transients effectively. The Pmod CLP LCD was chosen for its clear 16x2 character display and standard parallel interface.

Schematics & Wiring

All connections are made on a breadboard. The table below captures the exact pin assignments as implemented in firmware.

Signal MCU Pin Direction Notes
Mic ADC input PB0 (ADC1_IN11) IN (Analog) MAX9812 OUT
LCD DB0 PA0 OUT Pmod CLP data bit 0
LCD DB1 PA1 OUT Pmod CLP data bit 1
LCD DB2 PB1 OUT Pmod CLP data bit 2
LCD DB3 PA4 OUT Pmod CLP data bit 3
LCD DB4 PA5 OUT Pmod CLP data bit 4
LCD DB5 PA6 OUT Pmod CLP data bit 5
LCD DB6 PA7 OUT Pmod CLP data bit 6
LCD DB7 PA8 OUT Pmod CLP data bit 7
LCD RS PF0 OUT Register select
LCD R/W PF1 OUT Read/Write (held LOW = write)
LCD E PA9 OUT Enable strobe
Green LED PB4 OUT QUIET indicator
Red LED PB5 OUT WARN / ALARM indicator
Push-button PA10 IN (pull-up) Preset cycling, active LOW
UART2 TX PA2 OUT 115200 8N1 to PC, Internal wiring
UART2 RX PA15 IN Internal wiring

Bill of Materials (BOM)

Component Role Interface Source Image
Nucleo-F303K8 Main MCU CSCE workshop
Analog Microphone Sound input ADC / PB0 CSCE workshop
Pmod CLP 16x2 LCD Live noise display Parallel / PA0-PA9, PC14-15 CSCE workshop
Push-button Preset cycling GPIO / PA10 CSCE workshop
Red LED WARN/ALARM indicator GPIO / PB5 On-hand
Green LED QUIET indicator GPIO / PB4 On-hand
USB Cable Power + UART UART2 / PA2, PA15 On-hand

4. Software Implementation

4.1 Software Architecture

The firmware uses a bare-metal superloop with interrupt-driven sampling. A TIM2 interrupt fires every 100ms and sets a flag. The main loop polls this flag, performs a peak-to-peak ADC conversion, updates a circular buffer for the 8-sample moving average, and evaluates state transitions. UART reception is handled via interrupts to populate a circular command buffer without blocking the main loop.

4.2 Key Algorithms

  • Peak-to-Peak Sampling: Samples the ADC 64 times in a tight loop to find max/min values, providing an amplitude index independent of DC offset.
  • Hysteresis Logic: To prevent rapid state oscillation:
  • QUIET → WARN: Instantaneous, as soon as avg >= warn_thr.
  • WARN → ALARM: Requires the averaged reading to exceed alarm_thr for 5 consecutive ticks (0.5 s).
  • ALARM → QUIET: Requires the averaged reading to stay below warn_thr for 30 consecutive ticks (3 s).
  • LCD Visual Bar: The top row of the LCD shows the current averaged noise index as a 4-digit value plus a 6-segment bar ([██████]) scaled proportionally to the ALARM threshold using full-block characters (0xFF).

  • UART Log Format (per sample):

[QUIET] pp= 123 avg=  87 WARN=100 ALARM=200 preset=Study Room

4.3 Development Environment

  • IDE: STM32CubeIDE / Keil uVision 5
  • Toolchain: STM32 HAL / ARM MDK
  • Terminal: PuTTY at 115200 baud
  • Target MCU: STM32F303K8 on Nucleo-F303K8 board
  • GUI language: Python 3 (Tkinter + Matplotlib + pyserial)

5. Testing, Validation & Debugging

5.1 Subsystem Integration Status

Subsystem Status Notes
ADC / Mic Integrated Successfully sampling at 50Hz; peak-to-peak logic verified.
LCD (Pmod CLP) Integrated Parallel 8-bit driver fully functional; displays bar graph and presets.
UART (Log/Cmd) Integrated Logging active; SET THR commands successfully update thresholds in RAM.
FSM / Logic Integrated Hysteresis and state transitions working as intended.
Buzzer DEPRECATED Removed from design to comply with quiet-space requirements.
PC GUI Integrated noise_monitor_gui.py connects, parses log lines, updates chart and badge, sends SET THR commands.

5.2 Testing Evidence

  • Command Parsing: Sending SET THR WARN 500 via PuTTY results in an OK response and immediate threshold update.
  • State Stability: Verified that short ambient noises do not trigger alarms due to the 500ms delay logic.
  • LCD Refresh: Confirmed display updates every 100ms without flickering.

5.3 Remaining Bugs or Technical Risks

  • LCD Wiring Density: The 8-bit parallel interface requires many jumpers; physical stability is a risk until mounted.
  • ADC Sensitivity: The analog microphone is sensitive to power rail noise; hardware filtering is being considered.

5.4 Plan for Final Completion

  1. Calibration: Finalize default thresholds for target environments through empirical testing.
  2. Persistence: Implement Flash memory writing for thresholds to survive reboot.

6. Results & Demonstration

6.1 Final Prototype

Final Prototype Assembly

Hardware Connections

Terminal Output

Example of the UART log across all three states (Study Room preset).

GUI Output

6.2 Video Demonstration

Video Link

https://github.com/user-attachments/assets/372c818d-55fb-40c8-91e5-74090af5cbed

The video covers:

  • The startup sequence and UART.
  • State transitions from QUIET to WARN and ALARM (including hysteresis verification).

6.3 Performance Metrics

  • Sampling Rate: 50 Hz (confirmed via TIM2 prescaler = 47999, period = 99 at 48 MHz).
  • Burst Size: 64 ADC conversions per tick for peak-to-peak measurement.
  • Response Latency: ~105 ms (one tick period + burst conversion time).
  • UART Baud Rate: 115200 bps (TX = PA2, RX = PA15).

7. Project Management

7.1 Division of Labor

Team Member Responsibilities
Mohab Bahnassy System architecture; ADC/microphone driver; FSM and hysteresis logic; UART command parser; integration testing.
Kirollos Zikry TIM2 interrupt setup; moving-average filter; GPIO (LED + button) driver; software debounce; UART log formatting, and threshold controls.
Farida Said PC GUI (noise_monitor_gui.py), Pmod CLP LCD driver (parallel bus, custom characters, bar graph); debugging UART command parser

All members worked on the wiki.

7.2 Timeline

Week Milestone Status
Week 1–2 Proposal finalized; component list confirmed Done
Week 3 ADC + microphone sampling verified on breadboard Done
Week 4 FSM, hysteresis, and LED logic integrated Done
Week 5 LCD driver wiring and debugging Done
Week 6 UART logging and SET THR command parsing function Done
Week 7 Integrating UART logging and UART commands Done
Week 8 End-to-end integration testing; Done
Week 9 GUI creation Done
Week 10 Final presentation In progress

8. Appendices

8.1 Source Code Repository

Repository

8.2 Functional Requirements

ID Requirement
FR-1 Sample ambient sound at 50 Hz via internal ADC
FR-2 Apply 8-sample moving-average filter before threshold comparison
FR-3 Maintain QUIET / WARN / ALARM states with defined hysteresis
FR-4 Drive green LED in QUIET; red LED in WARN; blinking red LED in ALARM
FR-5 Display noise index and intensity bar LCD
FR-6 Cycle through three presets via button press
FR-7 Accept SET THR UART commands to override thresholds at runtime
FR-8 Transmit UART log entry for every sample
FR-9 REMOVED: Audio feedback/Buzzer removed to prevent further noise.
FR-11 PC GUI shall provide WARN and ALARM threshold sliders that auto-sync to firmware values on first connection, and send validated SET THR commands on user request

8.3 Peripherals Used

Peripheral Pin(s) Purpose
ADC1 (IN11) PB0 Analog sound input; peak-to-peak burst sampling (64 samples/tick)
TIM2 100 ms periodic sampling interrupt (prescaler=47999, period=99 @ 48 MHz)
GPIO input PA10 Push-button with 3-tick software debounce
GPIO output PB4, PB5 Green LED (QUIET) / Red LED (WARN, ALARM)
GPIO output PA0, PA1, PB1, PA4–PA9 LCD 8-bit parallel data bus (DB0–DB7); E strobe on PA9
GPIO output PF0, PF1 LCD RS (register select) and R/W control
UART2 PA2 (TX), PA15 (RX) 115200 baud logging + SET THR command input

8.5 Presentation links:

Proposal Presentation

Milestone 3

Final Presentation

8.4 Status Log

May 3, 2026 — Wiki updated with current STM32 implementation status. Audio feedback removed. Integration verified.

May 13, 2026 — Wiki updated with final STM32 implementation status, pin table, performance metrics, and Division of Labor / Timeline sections.

8.5 References