Project: Blinky – Sound Level Warning
My office recently moved from a building in which the rooms were were quite small and only a few people sat in each room to an office in which everyone sits in a large open space.
A concern we had with the new office was that the background noise would be quite loud when everyone is talking on the phone and conversing between each other. We diden’t want to divide the room into smaller sections so one solution we had to this problem was to buy some sort of decibel detecting device that would warn when the sound level got too high. Unfortuately those devices are hard to find and quite expensive so I instead set out to see if I could build a cheap but just as good detector myself.
Here is a video of the result:
There were three problems to solve in order to get this to work.
(1) Sound Detection – How loud is it, and when is it to loud.
(2) Controll - some sort of switch board to open or close a channel when sound is to loud.
(3) Warning – Making the switch board turn on a stroboscope.
Problem (1), Sound Detection.
To analyze the sound in the office I thought I would use one of the old laptops which noone uses anymore and build a program which would read input from a microphone and create some sort of average of the current sound levels. I started building this in C# .net 4.0 and it turned out pretty good.
I used NAudio to read a byte[] from the microphone and then analyzed this data to see how “loud” the sound is.
Here is a screenshot of the program:
The top green bar moves back and forth as sound decreases or increases. If the bar goes past the red line then the sound is to loud. Two of the three sliders are used to calibrate when this happens.
“Smoothing” is used to tell the program how sensitive it should be, the farther to the left the slider is the more sensitive it is to sudden changes in sound levels.
“Multiply” is used to set the detection level of the program, slide this back and forth untill the measuring bar responds to noise as you want and dosen’t spike for every sound you make. This is basically how much the program should multiply the input that it is reading from the microphone.
The final slider, “Blinky Time”, is just a setting to tell the program how long it should let the blinker stay on once noise has gone below the limit again.
The complete Visual Studio 2010 Project is linked at the bottom, but here is the code for just the sound detection:
using System;
using NAudio.Wave;
using NAudio.Midi;
using System.Collections;
namespace Volumizer
{
class SoundController
{
private WaveIn waveInStream;
private double average;
public SoundController()
{
waveInStream = new WaveIn();
waveInStream.BufferMillisconds = 10; // Mic polling intervall
waveInStream.DataAvailable +=
new EventHandler<WaveInEventArgs>(waveInStream_DataAvailable);
}
void waveInStream_DataAvailable(object sender, WaveInEventArgs e)
{
byte[] _buffer = e.Buffer;
int skipnum = 4; // dont need to read every byte of data
// skip a few bytes to speed it up.
double sum = 0;
for (var i = 0; i < _buffer.Length; i = i + 2 + skipnum )
{
double sample = BitConverter.ToInt16(_buffer, i) / 32768.0;
sum += (sample * sample);
}
double rms = Math.Sqrt(sum / _buffer.Length / skipnum );
var decibel = 20 * Math.Log10(rms);
average = decibel;
}
public double getSoundLevel()
{
return average;
}
public void startMeasuring()
{
waveInStream.StartRecording();
}
public void stopMeasuring()
{
waveInStream.StopRecording();
waveInStream = null;
}
}
}
Problem (2), Controlling some sort of output / switchboard
There are a number of controller boards which can be connected and controlled though a USB port, I used a Velleman K8055. I chose this board mostly because it was available on short notice in an electronics store near me, if you have more patience you could check out Pololu and probably spend a little less money.
The nice thing about the K8055 is that it is easily controlled though C# using the included SDK / DLL.
To turn on a digital output (i.e. turn the light switch on or off) all you need to do is import the functions from the included dll file:
[DllImport("k8055d.dll")]
public static extern void SetDigitalChannel(int Channel);
[DllImport("k8055d.dll")]
public static extern void ClearDigitalChannel(int Channel);
I then made the program call these functions based on if the sound was to loud or not.
Problem (3), Relays and Stroboscopes
The digital output on the cirtuitboard has a maximum throughput of 50V/100mA so instead of connecting the warning light directly to the board I used the board to power a relay which in turned powered my warning light, that way there’s no risk of putting to much power through the circuits.
Here are a few pictures of it (and yes, I used a small lunchbox to protect the electronics
):
|
|
|
|
|
Good luck making your own!
Project Blinky 1.0 - 2.04 MB. 35 DownloadsThe Visual Studio 2010 Solution for project Blinky.
Here are a couple of related pages that may interest you:
- my office & Haldex Run
Last week I was given my very first office at Haldex, the place where I’m doing my...
2 Responses to Project: Blinky – Sound Level Warning
Leave a Reply Cancel reply
Tags
550d ads Audi backburner Billboard BMW C# competition Computers/Servers contract Dragster EXSi false advertisement gaining knowledge gallery haldex helsingborg Hobbies hobby Hovercraft Java kraken Lundalogik marketing Motorsports overview photo photos Programming Programs Racing RC recreation rendering machine sailing server servers systeam Thesis thesis search Trainee Veidec Virtualization VMWare Work







Nice work.
Was fun reading.
Good stuff!
How did you even think about doing this…