Sanchana N
Published © MIT

Honkout: Honk More,Wait More

An initiative to curb noise pollution in world by reducing honking—honk more, wait more, for calmer, quieter streets.

IntermediateFull instructions provided12 hours21
Honkout: Honk More,Wait More

Things used in this project

Hardware components

Seeed Studio XIAO ESP32S3 Sense
Seeed Studio XIAO ESP32S3 Sense
×1
MAX7219 Dot Led Matrix Module 4 In 1 Display
×1
WS2812 64 Bit RGB LED Matrix
×3
Grove - Sound Sensor/ Noise Detector for Arduino
Seeed Studio Grove - Sound Sensor/ Noise Detector for Arduino
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
10 Pc. Jumper Wire Kit, 5 cm Long
10 Pc. Jumper Wire Kit, 5 cm Long

Story

Read more

Schematics

Circuit diagram

Code

Code

C/C++
/***** Honk More, Wait More — Smart Traffic Light *****
   Board: Seeed XIAO ESP32S3 Sense
   LEDs : 3x WS2812B 8x8 matrices daisy-chained (total 192 LEDs)
   Display: MAX7219 4-in-1 (4x 8x8) dot matrix
   Sensor: Analog sound sensor on A0
********************************************************/
#include <Adafruit_NeoPixel.h>
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

/* ---------- USER SETTINGS (tune these) ---------- */
#define RED_SEC     30       // red duration (seconds)
#define YELLOW_SEC  5        // yellow duration
#define GREEN_SEC   20       // green duration
#define BRIGHTNESS  50       // WS2812 brightness (0-255)
#define SOUND_PIN   A0       // analog input for mic
int SOUND_THRESHOLD = 1200;  // <-- set after calibration

/* ---------- WS2812 (all 3 matrices on one pin) ---------- */
#define WS_PIN      D2
#define LED_COUNT   (64*3)   // 192

// index ranges for each color section
#define IDX_RED_START     0
#define IDX_RED_END       63
#define IDX_YEL_START     64
#define IDX_YEL_END       127
#define IDX_GRN_START     128
#define IDX_GRN_END       191

Adafruit_NeoPixel strip(LED_COUNT, WS_PIN, NEO_GRB + NEO_KHZ800);

/* ---------- MAX7219 (MD_Parola) ---------- */
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES   4           // 4 modules = 32x8
#define MAX_DATA_PIN  D10
#define MAX_CLK_PIN   D8
#define MAX_CS_PIN    D9

MD_Parola P = MD_Parola(HARDWARE_TYPE, MAX_DATA_PIN, MAX_CLK_PIN, MAX_CS_PIN, MAX_DEVICES);

/* ---------- Helpers for LEDs ---------- */
void fillRange(int startIdx, int endIdx, uint8_t r, uint8_t g, uint8_t b) {
  for (int i = startIdx; i <= endIdx; i++) strip.setPixelColor(i, r, g, b);
}
void allOff() {
  for (int i = 0; i < LED_COUNT; i++) strip.setPixelColor(i, 0, 0, 0);
  strip.show();
}
void showRed() {
  allOff();
  fillRange(IDX_RED_START, IDX_RED_END, 255, 0, 0);
  strip.show();
}
void showYellow() {
  allOff();
  fillRange(IDX_YEL_START, IDX_YEL_END, 255, 165, 0);
  strip.show();
}
void showGreen() {
  allOff();
  fillRange(IDX_GRN_START, IDX_GRN_END, 0, 255, 0);
  strip.show();
}

/* ---------- MAX7219 text helpers ---------- */
void showCountdownCentered(int seconds) {
  char buf[8];
  snprintf(buf, sizeof(buf), "%02d", seconds);
  P.displayClear();
  // centered, static print (no animation effects)
  P.displayText(buf, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
  P.displayAnimate();  // render immediately
}

void scrollMessageOnce(const char* msg, uint8_t speed = 40) {
  P.displayClear();
  P.displayText((char*)msg, PA_CENTER, speed, 0, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  while (!P.displayAnimate()) {
    // animate until finished
    // (no delay here to keep it responsive)
  }
}

/* ---------- Sound sampling ---------- */
// Take a quick burst of samples, use the peak to decide
bool honkDetected() {
  int peak = 0;
  for (int i = 0; i < 40; i++) {           // ~quick 40-sample burst
    int v = analogRead(SOUND_PIN);
    if (v > peak) peak = v;
    delayMicroseconds(500);                // short spacing
  }
  return (peak > SOUND_THRESHOLD);
}

/* ---------- One light "phase" with optional honk reset ---------- */
void runPhase_RedWithHonkReset(int durationSec) {
  showRed();
  int t = durationSec;
  while (t > 0) {
    showCountdownCentered(t);

    // Check for honk only during RED
    if (honkDetected()) {
      // Show warning, then reset timer
      scrollMessageOnce("HONK MORE, WAIT MORE", 40);
      t = durationSec;              // reset to full red
      showRed();                    // ensure red stays on
      showCountdownCentered(t);
      // brief pause so number stays visible after scroll
      delay(300);
      continue; // go to next loop iteration without decrement
    }

    delay(1000);
    t--;
  }
}

void runPhase_Static(int durationSec, void (*showColor)()) {
  showColor();
  for (int t = durationSec; t > 0; t--) {
    showCountdownCentered(t);
    delay(1000);
  }
}

/* ---------- Setup & loop ---------- */
void setup() {
  Serial.begin(115200);

  // WS2812 init
  strip.begin();
  strip.setBrightness(BRIGHTNESS);
  strip.show();
  allOff();

  // MAX7219 init
  P.begin();
  P.setIntensity(2);     // 0..15; adjust to taste
  P.displayClear();

  // Optional: small hello scroll
  scrollMessageOnce("SMART TRAFFIC READY", 35);
}

void loop() {
  // RED
  runPhase_RedWithHonkReset(RED_SEC);

  // YELLOW
  runPhase_Static(YELLOW_SEC, showYellow);

  // GREEN
  runPhase_Static(GREEN_SEC, showGreen);
}

Credits

Sanchana N
1 project • 0 followers

Comments