Keeping track of sound levels with the Rasp Pi

Lead Image © indomercy,

Quiet Zone

Noise can be nerve wracking and lead to all kinds of problems with neighbors and area residents. A simple gadget can help you establish whether the noise coming from your premises amounts to a nuisance.

When people get together in the evening for an event, things can get pretty loud. As long as this happens in an isolated location, there is usually no reason to complain. However, in more populated areas, problems can arise. Nearby residents may apply to local authorities who in turn may be only too willing to declare the noise an official nuisance or disturbance of the peace.

Whether or not the event actually constitutes a nuisance, neighbors and other nearby residents may be quick to point a finger at you the next time they perceive even a slight disturbance.

Rasp Pi users can help themselves out in such situations by regularly logging measurements of sound levels. The log can then be used to refute arguments put forth by neighbors or the local authorities. Equipping a Rasp Pi with a sound level meter is easy and cheap. The HochDrei Youth clubhouse in Potsdam, Germany, uses the PeakTech 8005 [1] (Figure 1), which is available in electronics stores for about EUR150. In this article, I discuss the setup that the club used.

Figure 1: The PeakTech 8005 continuously measures noise emissions and is also able to log them because of its integrated USB connection. (Image: PeakTech)

The device has a USB connection, which makes it easy to connect to a Raspberry Pi. Moreover, the [2] module developed by Peter Henning especially for the FHEM home automation software package [3] makes it easy to collect and evaluate data streams.


The minimal Raspbian Wheezy installation, referred to as Darkbasic [4], suffices for this project because all the Rasp Pi needs to do is sit in a box and collect data. Listing 1 shows how Darkbasic was updated. This involved using rpi-update [5] to get a fresh version of the firmware and kernel (Figure 2). The next step is to add FHEM and the PT8005 module.

Listing 1

Updating Darkbasic

# Darkbasic update
# echo "deb wheezy main" >> /etc/apt/sources.list
# apt-get update && apt-get upgrade
# sed -i 's/wheezy/jessie/g' /etc/apt/sources.list
# apt-get update && apt-get --yes dist-upgrade
# apt-get autoremove
# apt-get autoclean
# reboot
Figure 2: The minimalist system Darkbasic is based on Debian Wheezy, but it can easily be updated to Jessie and equipped with a 4.x kernel.

Follow the steps shown in Listing 2 for installing FHEM. Then, you can access the user interface for the FHEM server in the browser via URL http://raspiip:8083.

Listing 2

Installing FHEM

# echo "deb ./" >> /etc/apt/sources.list
# wget -qO - | apt-key add -
# apt-get update && apt-get install fhem

In the basic setting, anybody can access the administration interface without logging in; thus, it's a good idea to put access limits in place. This is done by expanding the file fhem.cfg by one line. To do this, you should first click on Edit files and then on fhem.cfg. Below the define WEB FHEMWEB 8083 global line, enter

attr WEB basicAuth <Base64-Userpassword>

replacing <Base64-Userpassword> with the output of the command:

echo -n <User>:<password> | base64

After clicking on Save fhem.cfg, it is time to restart the server. The restart will cause user authentication to go into effect.

FHEM has interfaces for various devices. The server will distinguish among the interfaces on the basis of the port number used. If you are not planning to connect to the server from a smartphone or tablet, you can simply do away with the corresponding lines. Otherwise, at this point, you should enter the user password combination that has been encoded in Base64. Then, you need to copy the module into the /opt/fhem/FHEM/ directory.

You can provide the necessary user rights to the module via the chown fhem:dialout command and initiate a restart over the web interface via update and shutdown restart. You should send the above commands with the help of the upper input lines of the web interface on the FHEM server. After that, the module is ready for use.

The next step is to configure the PT8005. This is done by simply adding the entry

define pt8005 PT8005 /dev/ttyUSB0

to the fhem.cfg file. If the editing process doesn't work, click on Unsorted | WEB and select the value editConfig that appears in the selection menu on attr WEB. After repeating the restart, the module will appear under Everything. It can now also be opened. (Figure 3).

Figure 3: To install the PT8005 module, you just make some limited modifications to the central configuration file fhem.cfg.

Measuring and Collecting

At this point, you can send various commands via set to the sound level meter or you can request a status update via get. For example, the command set Min/Max lets you switch views among sound levels, including the lowest, the highest, and the one currently being measured. Your choices for changes in view are limited to what is displayed on the meter. The command set auto lets you switch the range for measuring sound levels. As a rule, the default value AUTO covers the range from 30 to 130dB. Alternatively, you can set the default range to 30 to 80dB (LO), 50 to 100dB (MED), and 80 to 130dB (HI).

The dBA/C switch lets you adjust settings for measurement of sound frequencies. The default value dBA should correspond to the range humans hear. PeakTech recommends the dBC setting for measuring noises produced by machines and motors. The set interval setting lets you determine the intervals at which measurements are to be taken. The default setting is for an interval lasting 60 seconds. The smallest interval possible is five seconds. The speed setting is used for response time. For general measurements, a slow response time is recommended as well as an A weighting, which will average out the noise level over a one-second time period.

To log the data that has been measured, you should send a createlog pt8005 command to the FHEM server. The sound level meter will appear to the left in the menu. FHEM generates a logfile for an entire year. The HochDrei club in Potsdam collects data daily for comparison with noise levels accompanying events. This was done by adding the string -%m-%d to the file name of the logfile in fhem.log.

Usually, complaints about the noise caused by parties or events are made immediately. Therefore, older logfiles are deleted via cronjob (Listing 3). Logrotate is a good alternative to cronjob. If someone complains about the noise, the membership can look through the logfile via zless and zgrep and determine whether a sound level exceeded 40dB during the pertinent time period.

Listing 3

Deleting Old Files

#! /bin/bash
#: Title:
#: Date:   2015-08-22
#: Author:   Falko Benthin
#: Version: 1
#: Description:  pt8005-Logs compress, delete after 30 days
# compress files older than three days
find /opt/fhem/log/pt8005*log -mtime +3 -exec gzip {} \;
# delete files older than 30 days
find /opt/fhem/log/pt8005*log.gz -mtime +30 -exec rm {} \;
exit 0

Often, information appears repeatedly in the logfile (e.g., mode: normal, range: 30-130 dB and overflow) that, in the case of a possible disturbance of the peace, will not be helpful. To determine what the noise level actually was, you need to edit the fhem.cfg file and replace the expression pt8005 at the end of the

define FileLog_pt8005 FileLog ./log/pt8005-%Y-%m-%d.log pt8005

line with pt8005:soundlevel:. (Figure 4).

Figure 4: The log provides up-to-the-minute information about how much noise is produced.

Buy this article as PDF

Express-Checkout as PDF

Pages: 4

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content