Arduino Volume Meter

After a lifetime of llistening to loud music, I have sensitive ears and (rather passive aggressively) wanted to let my colleagues know how noisy the office sometimes gets.

I got a 12v Tower Light and thought is would make a good volume indicator

Tower Light

and a MAX9814 Microphone Amplifier

MAX9814 Microphone Amplifier

The Microhone and Amplifier

Very easy to install. The main loop of the code samples the amplitude of the signal coming from the microphone throughout a 50 millisecond window and I convert it into volts.

void loop() {
   unsigned long startMillis= millis();  // Start of sample window
   unsigned int peakToPeak = 0;   // peak-to-peak level

   unsigned int signalMax = 0;
   unsigned int signalMin = 1024;

   // collect data for 50 mS
   while (millis() - startMillis < sampleWindow)
      sample = analogRead(0);
      if (sample < 1024)  // toss out spurious readings
         if (sample > signalMax)
            signalMax = sample;  // save just the max levels
         else if (sample < signalMin)
            signalMin = sample;  // save just the min levels
   peakToPeak = signalMax - signalMin;  // max - min = peak-peak amplitude
   double volts = (peakToPeak * 5.0) / 1024;  // convert to volts

And I light the appropriate light, depending on the voltage while I defined by trial and error

float green = 0.3;
float yellow = 0.6;
float red = 1.2;
  if(volts < green){
     digitalWrite(GREEN, HIGH);
     digitalWrite(YELLOW, HIGH);
     digitalWrite(RED, HIGH);
   }else if(volts < yellow){
     digitalWrite(GREEN, LOW);
     digitalWrite(YELLOW, HIGH);
     digitalWrite(RED, HIGH);
   }else if(volts < red){
     digitalWrite(GREEN, HIGH);
     digitalWrite(YELLOW, LOW);
     digitalWrite(RED, HIGH);
     digitalWrite(GREEN, HIGH);
     digitalWrite(YELLOW, HIGH);
     digitalWrite(RED, LOW);

It’s very simple and really doesn’t need an arduino, but a 3 hour build is a 3 hour build…

The finished product

I put it in a box, pokeing the microphone through the lid.


Fun, but the best bits were a bit too easy. The mic and amplifier do such a good job, I really only had to install them.

But it worked! For a while… People seemed surprised to realise how quickly a noisy environment grew, and it changed behaviour. Until people got used to it, and possibly, quite reasonably, resented being scolded for making a noise.

The final product

An interesting experiment.

The code

Written on July 27, 2018