Introduction: Volume Regulator

Attention all librarians and library-lovers!

If you're like us and need some peace and quiet to get some work done, check out Linda, the library monitor. Linda is a volume regulator in disguise! As soon as the room gets too loud it will make sure to voice its concerns. No more being too shy to ask for the person next to you to stop talking, Linda's got you covered!

First, Linda will tell the person to be quiet, but if they persist, it will warn them a few times before it really show it's anger. No one will be able to ignore Linda, it's got quite the perseverance! They'll run out of breath before Linda does.

Supplies

Electronics:

1 x Arduino board

1 x Breadboard

2 x 9V Batteries

1 x Micro Servo Motor SG90

1 x NPN Transistor PN2222

1 x 330 Ω Resistor

2 x Electret Mic MAX9814 amp Auto Gain

1 x SPKME-001338 3W 8 ohm Speaker

1 x microSD Breakout Shifter

1 x 18W TDA2030A Amp

1 x Micro SD Card

Alligator to Jumper Cables

Jumper Wires

Other Materials:

Large Book (e.g. a Dictionary)

Wood Sheet (or other material for laser cutting)

Tape

Super Glue

Tools:

Ruler

Scissors

Xacto Knife

Soldering Iron

Access to a Laser Cutter

Step 1: Audio Setup

Create your own audio files from https://voicegenerator.io/ (using Linda's voice). Alternatively, you can use the attached files.

Bring the audio files into the Audacity app to raise their volumes. Export the audio files as unsigned 8-bit .wav files. You can skip this step if you used the attached files.

Format your SD card (make sure it is fat32 or fat16 format)

Upload the audio files onto the SD card using simple names that can be called upon in the code (e.g. 1.wav)

Step 2: Circuit Setup and Theory

Wire your parts according to the circuit diagram

Sensors:

Microphone

Using a microphone component, the Arduino can measure sounds and bring about actions in accordance with the input it receives. For example, in this project, we intended for the volume of a room to trigger an Arduino’s response. 

Audio signals are an alternating current with highly variable waves. The volume or loudness of a sound is directly related to the amplitude of the peaks. A higher amplitude audio signal creates a higher volume sound, and vice versa (Figure 1).

In this project, we will be taking a series of analog reads from the microphone pin in order to plot the fluctuating audio signal. From there, we will use the minimum and maximum values recorded in that series of analog reads to calculate the difference, or delta, between these two peaks. A smaller difference in peaks is indicative of a smaller amplitude of the audio signal waveform, and thus a quieter sound (Figure 2). A greater difference in peaks is indicative of a larger amplitude of the audio signal waveform, and thus a louder sound (Figure 3).

We found the “How to use microphones on the Arduino” page by Circuit Basics very informative and we highly recommend that you give it a read (https://www.circuitbasics.com/how-to-use-microphones-on-the-arduino/).

The breakout board we use is the Adafruit MAX9814 electret microphone amplifier with auto gain control. This board features a 20Hz-20KHz electret microphone and a built-in pre-amplifier. This preamplifier helps adjust the detected audio signal to a level that the Arduino can work with before it is received by the Arduino. For more details on the specification of this microphone, refer to this datasheet: https://cdn-shop.adafruit.com/datasheets/MAX9814.pdf

Actuators:

Motor

 A servo motor is a rotary actuator that allows for the precise control of angular positions, velocity and acceleration. For this project, we made use of the Micro Servo Motor SG90, a tiny and lightweight servo motor with high output power. It can rotate 180 degrees and has a stall torque (4.8v) of 1.8kg/cm.

For more details on the specification of this servo motor, refer to this datasheet: https://ullisroboterseite.de/projekte-teedipper/SG90%209%20g%20Micro%20Servo.pdf

Speaker

Speakers are actuators that work by converting electrical energy into mechanical energy, or motion. The mechanical energy pushes and pulls the air surrounding the speaker’s moving coil, compressing it and creating pressure waves, otherwise known as sound. 

Audio transducers, such as speakers, are inherently analog. This necessitates the use of Pulse Width Modulation, or PWM, a technique for getting analog results with digital means. This digital-to-analog converter is used to create a square wave of varying widths that simulates the behaviour of an analog wave. Luckily, the Arduino IDE has a built-in function “analogWrite()” which can be easily used to generate a PWM signal that our speaker can understand.

For this project, we used the SPKME-001338 3W 8OHM Speaker.

Step 3: Coding Setup

Use the attached Arduino Code. You will need to install the "TMRpcm" library by TMRh20 from the library manager. Note, once you have the library, open its folder, then the file named "pcmConfig.h" and uncomment the line which says "#define USE_TIMER2".

Next, calibrate the microphones according to your room: run the code once in a quiet room to get your lowest values, then run it again while making a loud noise next to the microphones to get your highest values.

Once you have your range, you can adjust the "Level0", "Level1", "Level2" and "Level3" variables in the code to suit your room (with Level0 being the lowest and Level3 the highest).

You should also change the name of the audio files to match your own nomenclature.

Linda.h

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Show hidden characters
#include"Servo.h"
#include"SD.h"
#include"TMRpcm.h"
#include"SPI.h"
constint chipSelect = 10;
constint microphonePin1 = A0;
constint microphonePin2 = A1;
int delayVal = 100;
int Level0 = 220; //Change this value according to the room
int Level1 = 270; //Change this value according to the room
int Level2 = 300; //Change this value according to the room
int Level3 = 330; //Change this value according to the room
TMRpcm tmrpcm;
Servo myservo;
voidsetup() {
// put your setup code here, to run once:
tmrpcm.speakerPin = 3;
myservo.attach (6);
pinMode (A0, INPUT);
pinMode (A1, INPUT);
pinMode (6, OUTPUT);
pinMode (9, OUTPUT);
Serial.begin (9600);
if (!SD.begin(chipSelect)) {
Serial.println("SD Fail");
return;
}
Serial.println ("OK");
tmrpcm.setVolume(6);
myservo.write (0);
}
voidloop() {
// put your main code here, to run repeatedly:
int mn1 = 1024;
int mx1 = 0;
int mn2 = 1024;
int mx2 = 0;
for (int i = 0; i < 10000; ++i) {
int val1 = analogRead(microphonePin1);
mn1 = min(mn1, val1);
mx1 = max(mx1, val1);
int val2 = analogRead(microphonePin2);
mn2 = min(mn2, val2);
mx2 = max(mx2, val2);
}
int delta1 = mx1 - mn1;
int delta2 = mx2 - mn2;
int Volume = (delta1 + delta2)/2;
if (Volume >= Level0 && Volume < Level1) {
Serial.print(" LOW Volume = ");
Serial.println(Volume);
tmrpcm.play("1.wav"); //Change according to the name of your file
myservo.write (40);
delay (1000);
myservo.write (0);
delay (200);
}
elseif (Volume >= Level1 && Volume < Level2) {
Serial.print(" MEDIUM Volume = ");
Serial.println(Volume);
tmrpcm.play("2.wav"); //Change according to the name of your file
myservo.write (40);
delay (1000);
myservo.write (0);
delay (200);
}
elseif (Volume >= Level2 && Volume < Level3) {
Serial.print(" HIGH Volume = ");
Serial.println(Volume);
tmrpcm.play("3.wav"); //Change according to the name of your file
myservo.write (40);
delay (2000);
myservo.write (0);
delay (200);
}
elseif (Volume >= Level3 ) {
Serial.print(" UNACCEPTABLE!! Volume = ");
Serial.println(Volume);
tmrpcm.play("4.wav"); //Change according to the name of your file
myservo.write (40);
delay (4000);
myservo.write (0);
delay (1000);
}
else {
Serial.print(" QUIET Volume = ");
Serial.println(Volume);
}
}
view raw Linda.h hosted with ❤ by GitHub

Step 4: Building Linda

Laser cut a mount for the servo motor using the attached .pdf file. Using a piece of the wood, you can also attach an extension to the servo motor arm to raise the book cover higher.

Cut out the insides of the book according to the orange parts in the image (all measurements are in millimeters). Cut deep enough to fit all the components into the book. Also make sure that the holes for the microphones are cut at different depths, so that the pages remain connected to the book.

Place the circuit inside the center hole in the book

Place the microphones in the side cuts in the book

Step 5: Enjoy Your Peace and Quiet!

Congratulations! You now have your very own Linda!

Make sure to let us know how it went for you. We know that for us, we had a lot of trouble getting Linda to speak in the first place! Troubleshooting and calibrating Linda to the right noise level for the room was another difficulty. But the greatest difficulty of all, was getting Linda to speak and move at the same time - it seems Linda is rather lazy - but no worries, Linda just had to learn to use two separate timers to do both tasks at once!

Linda also sometimes gets really upset and all it wants to do is curse at us - we definitely didn't expect Linda's temper!