Noval Aryansah
Published

Simple Smart Noise Monitoring System with Wireless Display

Real-time wireless noise monitoring system using ESP32, MAX4466, and LED matrix visualization with smart threshold alerts.

BeginnerFull instructions provided2 hours61
Simple Smart Noise Monitoring System with Wireless Display

Things used in this project

Hardware components

ESP32
Espressif ESP32
×1
Adafruit MAX4466
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
Buzzer
Buzzer
×1
XIAO ESP32C3
Seeed Studio XIAO ESP32C3
×1
MAXREFDES99# MAX7219 Display Driver Shield
Maxim Integrated MAXREFDES99# MAX7219 Display Driver Shield
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Breadboard, 170 Pin
Breadboard, 170 Pin
10 Pc. Jumper Wire Kit, 5 cm Long
10 Pc. Jumper Wire Kit, 5 cm Long

Story

Read more

Schematics

Sender Schematic Wiring

Receiver Schematic Wiring

Code

Sender Code

Arduino
#include <WiFi.h>
#include <esp_now.h>

#define MIC_PIN 34
#define POT_PIN 35
#define BUZZER 25

uint8_t receiverMAC[] = {0xE4, 0xB3, 0x23, 0xC3, 0x6C, 0x28};

typedef struct {
  float amplitude;
  int threshold;
} data_t;

data_t data;

float smoothValue = 0;

void setup() {
  Serial.begin(115200);
  pinMode(BUZZER, OUTPUT);

  WiFi.mode(WIFI_STA);

  if (esp_now_init() != ESP_OK) {
    Serial.println("ESP-NOW INIT FAILED");
    return;
  }

  esp_now_peer_info_t peerInfo = {};
  memcpy(peerInfo.peer_addr, receiverMAC, 6);
  peerInfo.channel = 0;
  peerInfo.encrypt = false;

  esp_now_add_peer(&peerInfo);

  Serial.println("Sender Ready");
}

void loop() {
  int signalMax = 0;
  int signalMin = 4095;

  unsigned long startTime = millis();

  while (millis() - startTime < 100) {
    int sample = analogRead(MIC_PIN);
    if (sample > signalMax) signalMax = sample;
    if (sample < signalMin) signalMin = sample;
  }

  int peakToPeak = signalMax - signalMin;

  // smoothing
  smoothValue = (smoothValue * 0.7) + (peakToPeak * 0.3);

  int potValue = analogRead(POT_PIN);

  // mapping threshold ke skala noise
  int mappedThreshold = map(potValue, 0, 4095, 0, 600);

  // buzzer
  digitalWrite(BUZZER, smoothValue > mappedThreshold);

  // kirim data
  data.amplitude = smoothValue;
  data.threshold = potValue;

  esp_now_send(receiverMAC, (uint8_t *)&data, sizeof(data));

  // DEBUGc 
  Serial.print("Noise: "); Serial.print(smoothValue);
  Serial.print(" | Pot: "); Serial.print(potValue);
  Serial.print(" | Th: "); Serial.println(mappedThreshold);

  delay(200);
}

Receiver Code

Arduino
#include <WiFi.h>
#include <esp_now.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4

#define DATA_PIN 10
#define CLK_PIN 8
#define CS_PIN 5

MD_Parola display = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

// CONFIG
#define HYSTERESIS 30
#define ALERT_DURATION 4000
#define COOLDOWN_TIME 3000

typedef struct {
  float amplitude;
  int threshold;
} data_t;

data_t incomingData;

bool showAlert = false;
bool inCooldown = false;

unsigned long alertStart = 0;
unsigned long cooldownStart = 0;

// callback
void onReceive(const esp_now_recv_info_t *info, const uint8_t *data, int len) {
  memcpy(&incomingData, data, sizeof(incomingData));
}

// BAR FUNCTION
void drawBar(int level) {
  display.displayClear();

  for (int x = 0; x < level; x++) {
    for (int y = 0; y < 8; y++) {
      display.getGraphicObject()->setPoint(y, x, true);
    }
  }
}

void setup() {
  Serial.begin(115200);

  WiFi.mode(WIFI_STA);
  esp_now_init();
  esp_now_register_recv_cb(onReceive);

  display.begin();
  display.setIntensity(5);
  display.displayClear();

  Serial.println("Receiver Ready");
}

void loop() {
  float noise = incomingData.amplitude;
  int potValue = incomingData.threshold;

  int threshold = map(potValue, 0, 4095, 0, 600);

  Serial.print("Noise: ");
  Serial.print(noise);
  Serial.print(" | Th: ");
  Serial.println(threshold);

  unsigned long now = millis();

  // cooldown selesai
  if (inCooldown && now - cooldownStart > COOLDOWN_TIME) {
    inCooldown = false;
  }

  // trigger alert
  if (!showAlert && !inCooldown && noise > (threshold + HYSTERESIS)) {
    showAlert = true;
    alertStart = now;

    display.displayScroll("NOISE HIGH!", PA_LEFT, PA_SCROLL_LEFT, 50);
  }

  // MODE ALERT
  if (showAlert) {
    if (display.displayAnimate()) {
      display.displayReset();
    }

    if (now - alertStart > ALERT_DURATION) {
      showAlert = false;
      inCooldown = true;
      cooldownStart = now;
      display.displayClear();
    }
    return;
  }

  // MODE NORMAL (BAR)
  int level = map(noise, 0, 600, 0, 32);
  level = constrain(level, 0, 32);

  drawBar(level);

  delay(50);
}

Credits

Noval Aryansah
2 projects • 0 followers
Tech Enthusiast, Coding is (F)un

Comments