My wife and I have both been working from home during the COVID-19 pandemic, and have observed that often our children (3, 6, and 8) will be making noise quite unaware of how loud they’ve become.

A quick search showed that there are a number of noise traffic lights on the market, but it occurred to me that I could make my own, and that it would be a great way of learning about the Arduino platform.

I started by ordering the following components from Jaycar:

  1. An Arduino Uno.
  2. An acrylic case for the Arduino.
  3. A KX-038 sound sensor module.
  4. A traffic light LED module.

Assembly was quick and easy - the case came with all required screws and nuts, and the module boards stuck on easily with double-sided adhesive foam squares, cut to fit.

Compaq MX-11800

The software side took a little longer. My naive initial attempt basically didn’t work - it triggered the lights based on absolute levels, which didn’t take into account different operating environments. It had to be reprogrammed between, say, my quiet workbench and the noisy living room.

My second attempt was to have the system calibrate itself at startup. It takes 200 readings over the course of a good few seconds, and calculates the mean and standard deviation. While it’s taking the readings it rapidly cycles the LEDs, so it’s clear that it’s doing something, as opposed to just sitting there wedged.

Once it’s established the mean background noise level, it illuminates the yellow LED at 3 standard deviations above mean, and the red LED at 6 standard deviations. (I arrived at these numbers after a little experimentation).

As I usually do, I set up a development environment in Emacs. Conveniently the arduino and arduino-mk packages for Ubuntu provide a toolchain and default Makefile for Arduino projects, and Emacs has great Arduino support (although I skipped CEDET and used arduino-mode instead).

You can see it here, running a few tests that I wrote to give myself some confidence in the mean and standard deviation functions I wrote. Running them is a matter of plugging in the Arduino and executing make tests; this compiles the code, deploys it, and monitors the test progress over the serial connection.

Emacs Arduino

With the device assembled, the code written and tested, all that remained was setting it up. It’s now mounted (with more double-sided adhesive squares) to one of the bookshelves in the living room :)

Compaq MX-11800

I’ve created a Gitlab project, traffic-lights, to store the code. If you use it for inspiration (or to build your own lights), please do remember that it’s my first Arduino project, and that I hacked it up in a weekend. YMMV :)