Program a Sound Level Meter to Help Protect Your Hearing
Abstract
Have you ever said, "That hurt my ears!" when someone yelled loudly right next to you? Do you cover your ears when a fire truck drives by with the sirens blaring? It is good to protect your ears—even sounds that do not "hurt" can cause hearing damage if you are exposed to them for too long. In this project, you will program a device that alerts you when sounds have exceeded safe levels long enough to cause hearing damage.
Summary
None
This project requires a micro:bit, available from our partner Home Science Tools®
Prolonged exposure to sounds over 70 dB can cause hearing damage. Wear ear protection if testing your device with sounds louder than 70 dB.
Objective
Program a device to alert you when sounds have exceeded safe levels for too long.
Introduction
Have you ever wondered how we measure the loudness of a sound? We measure sound in units called decibels (dB). The decibel scale is logarithmic, not linear. For every increase of 10 dB, a sound is perceived as roughly twice as loud. For example, a quiet place like a library typically has a sound level of 40 dB. Normal human conversation is about 60 dB, which means it sounds about four times as loud as a library. Figure 1 shows some decibel levels of common sounds.

threshold of hearing 0, normal breathing 10, rustling leaves 20, whisper 30, library 40, moderate rainfall 50, normal conversation 60, city traffic 70, screaming baby 80, lawn mower 90, chainsaw 100, car horn 110, live rock concert 120, jet engine 130, gunshot 140
Sounds below 70 dB are generally considered safe, but sounds louder than that can damage your hearing over time, for example, over the course of a school or work day. Very loud sounds, like those from chainsaws and jet engines, can cause hearing damage in shorter periods of time. That is why it is very important for people who work around loud equipment and machinery to wear ear protection. Even if you do not work directly near loud equipment, you can still be exposed to loud background noise, or noise pollution, like noise from a highway or city traffic.
It might seem obvious that some sounds are so loud that they hurt your ears, but what about longer-term exposure to sounds right around 70 dB? It might not hurt your ears, and you might not realize you are at risk of hearing damage. A sound-monitoring device can help in situations like this. The device can continuously monitor decibel levels and keep track of your sound exposure throughout the day. If sound levels exceed a certain threshold for too long, the device can alert you. This can help you evaluate what actions you can take to reduce your risk of hearing loss—like moving farther away from the source of a loud noise, wearing ear protection, or taking breaks to let your ears rest.
In this project, you will use a small programmable device called a micro:bit to make your own sound-monitoring device. You can customize the program, so the exact thresholds to trigger the alarm and how it sends alerts are up to you!
Terms and Concepts
- Decibel (dB)
- Logarithmic
- Linear
- Noise pollution
Questions
- What decibel levels are considered safe for continuous exposure?
- What decibel levels can cause hearing damage over time?
- What decibel levels can cause instantaneous hearing damage?
- What are some steps you can take to help prevent hearing damage?
Bibliography
- Hearing Health Foundation (n.d.). What Are Safe Decibels? Retrieved January 28, 2026
- Occupational Safety and Health Administration (n.d.). Occupational Noise Exposure. Retrieved January 28, 2026
- Science Buddies (n.d.). How to Use a micro:bit. Retrieved January 28, 2026
- Science Buddies (n.d.). Engineering Design Process. Retrieved January 28, 2026
Materials and Equipment
- micro:bit Go Bundle, available from our partner Home Science Tools®®. The kit contains:
- micro:bit board
- USB cable
- Battery holder
- AAA batteries (2)
- Computer with USB port
- Note: the micro:bit kit comes with a USB-A to micro-USB cable. If your computer only has USB-C ports, you will need a USB-C (male) to USB-A (female) adapter.
- Various sources of sound to test your sound level meter
- Ear protection
Experimental Procedure

- If you have never used a micro:bit before, watch our micro:bit setup video before you continue.
- This is an engineering design project. There is no single "correct" way to write your program. We will provide some simple examples, but you can modify or add to them. Think about the criteria you want to establish for your project.
- Do you want your device to alert the user if instantaneous sound levels exceed a certain threshold?
- Do you want to alert the user if cumulative sound levels have stayed above a certain level for a certain amount of time?
- Do you want your device to have a combination of these features, monitoring both instantaneous and cumulative levels?
- How will the device alert the user? What outputs are available on the micro:bit that you could use?
- How will your user interact with the device? What inputs are available on the micro:bit that you could use?
- Start a new program in MakeCode.
- Click on Extensions in the blocks menu.
- Search for "sound level decibels" and import the
sound-level-dbextension. - This extension adds a block that displays the measured sound level in decibels, instead of the 0-255 range shown by the normal
sound levelblock.
- First, you will make a basic decibel meter that displays the current sound level in decibels on the micro:bit's LED display. Write the program shown in Figure 2.
- Place a
show numberblock from theBasicmenu inside yourforeverloop. - Place a
sound level (dB)block from theInputmenu inside yourshow numberblock.
- Place a

- Connect your micro:bit to battery power and carry it around. Measure background sound levels in different locations, like different rooms of your home or outside.
- The microphone used to measure sound is on the back of the micro:bit board. Make sure you do not cover the microphone when holding the micro:bit because this could affect the sound levels.
- Try measuring decibel levels of different continuous sounds, like a fan or humming. Since it takes a while for each decibel reading to scroll across the screen, this program will not work well for measuring quick sounds like clapping.
- If you decide to test something loud (like a lawnmower), wear ear protection.
- How does the sound level change as you move closer to or farther away from the sound source?
- Write a new program like the one in Figure 3. This program displays a smiley face when the sound level is below a certain threshold and switches to a frowny face when sound levels meet or exceed that threshold.
- Add an
if elsestatement from theLogicmenu inside yourforeverloop. - Put a
comparisonblock from theLogicmenu inside the condition for theif elsestatement. - Put a
sound level (dB)block from theInputmenu in the first value of the comparison block. - Enter a number (in decibels) for the other value in the
comparisonblock. The example in Figure 3 shows a value of 60, but you can choose a different number. - Optional: change the comparison operator to a less than (<) symbol, depending on how you want your
if elsestatement to behave. - Put a
show icon :)block in theifpart of theif elsestatement. - Put a
show icon :(block in theelsepart of theif elsestatement.
- Add an

- Download the new program to your micro:bit and connect it to battery power. Carry it around (again, being careful not to cover the microphone) and test it with all the same locations and sounds you tested earlier.
- Does the program reliably switch to the frowny face when exposed to loud sounds?
- The code in the forever loop takes some time to run. Does the program work for quick sounds like claps, or does it miss some of them? Does it work well for more continuous sounds?
- Optionally, you can try writing a program using the
on loud soundevent block (from theInputmenu) instead of aforeverloop with anif elsestatement. You can adjust the loud sound threshold using theset loud sound threshold toblock, also from theInputmenu. Does this program do a better job monitoring for quick loud sounds?
- So far, the two programs you have written only react to instantaneous sound levels. What if you want to measure exposure to sound levels above a certain threshold over time? Figure 4 shows one way you could do that. Remember that this is an engineering design project, so you do not have to do exactly what is shown in Figure 4. Here is how the program works conceptually:
- When the program starts:
- It sets a variable called
secondsto zero. This variable will count the total time (in seconds) the user has been exposed to sound above a certain threshold. - The program also sets variables called
sound_threshold, the decibel level considered unsafe for extended periods of time, andtime_threshold, the total amount of allowed exposure time. You can choose these values. - It shows a smiley face on the screen.
- It sets a variable called
- Then, once every second (1,000 milliseconds):
- The program checks if the current
sound level (dB)is greater than thesound_thresholdvalue. - If so, then it increases the
secondsvariable by 1. - It checks if the current
secondsvalue is greater than thetime_thresholdvalue. - If so, it switches the display to a frowny face, indicating that the user has exceeded safe levels of total noise exposure.
- The program checks if the current
- When the program starts:

- Here are instructions to write the program:
- To make a variable, click the Variables menu, then click
Make a Variable. Create three variables. Step 9 and Figure 4 have example names, but you can use other names if you want. Just make sure the names make sense to you. - For each variable, add a
set (variable name) toblock to theon startblock.- Leave the
secondsvariable set to 0. - Select a sound threshold value. To make it easier to test your code without requiring extremely loud sounds, you may want to set a value around 50 or 60 dB.
- Select a time threshold value in seconds. To make it easier to test your project without waiting for long periods of time, you might want to pick a short time threshold at first, like 5 or 10 seconds.
- Leave the
- Put a
show icon :)block in theon startblock. - Add an
every 500 msblock from theLoopsmenu to your program. - Change the time to 1000 ms.
- Add an
ifstatement (not anif elsestatement) inside yourevery 1000 msblock. - Add blocks to make the condition of the
ifstatementsound level (dB) > sound_threshold(or whatever you named the variable). - Put a
change seconds by 1block inside theifstatement. - Add a second
ifstatement inside theevery 1000 msblock. Make sure it comes after the firstifstatement, not nested inside it. - Make the condition of the second
ifstatementseconds > time_threshold(again, your variable names may be different). - Add a
show icon :(block inside the secondifstatement.
- To make a variable, click the Variables menu, then click
- Download the new program to your micro:bit and test it.
- If you set low enough sound and time thresholds, you can test it quickly just by talking or humming, without requiring any other sources of sound.
- Does the program work as expected? In other words, does it start out showing a smiley face and switch to a frowny face after a loud sound has gone on for too long?
- Set higher values for the sound and time thresholds. Keep the micro:bit with you as you go about an activity (remember to wear hearing protection if needed). How long does it take for the "alarm" to trigger? Do you think you would have noticed the sound levels on your own, without help from the micro:bit?
- If you plan to enter this project in a science or engineering fair, you should make your own changes to the program, not just copy the program in Figure 4. Go back to the criteria you set in step 2. Does the current program meet all of your criteria? If not, what could you add or change? See the Variations section for more ideas.
Ask an Expert
Global Goals
The United Nations Sustainable Development Goals (UNSDGs) are a blueprint to achieve a better and more sustainable future for all.
Variations
- The example programs use the micro:bit's LED display to show smiley or frowny faces. Can you use other outputs, like showing a message on the screen? What about playing a sound with the micro:bit's built-in speaker? Is the sound loud enough for you to hear it if you are already in a loud room? What about sending a radio message to another micro:bit?
- Can you add a way for the user to interact with your program? For example, there is no way to reset the program in Figure 4 and start the timer over without resetting the micro:bit. Can you use a button press (or other input) to reset the
secondsvariable to zero? - Can you make the timer automatically reset if decibel readings have stayed within a safe level for a certain amount of time? Does it make sense to do that based on guidelines about hearing protection?
- Do some research about safe exposure limits for sounds at different decibel levels. Can you write a program that will trigger an alarm if exposure limits are exceeded for any of multiple decibel/time combinations? For example, 8 hours of sound at 70 dB or 4 hours of sound at 80 dB?
- It might be inconvenient to carry a micro:bit around all day. Can you design or build something so a person can easily wear a micro:bit attached to their clothing? Remember to make sure the microphone on the back of the micro:bit is not covered when the person wears it.
Careers
If you like this project, you might enjoy exploring these related careers:









