Noise Pollution App

Hello friends and welcome to Obsidian Soft,

I will show you how to make a sound sensor app in this tutorial. We will use the sound sensor to measure the sound in decibels and we will also use the slider component to show the level of sound or noise in terms of health risk. So, in a way, we will be measuring noise pollution and showing our results using a nice-looking front end.

Let's begin by downloading an extension. I don’t like using extensions that much as I believe they take away a large chunk of the learning experience. The goal of my channel is not just to help you make MIT app inventor apps but to make you learn to code and prepare you for other languages like JAVA or Python.

However,  sometimes extensions become necessary when a feature isn’t available in MIT App Inventor at all. So, what is a sound sensor on a mobile phone? Yes, you guessed it right! It is the microphone. We have the sound recorder component in MIT App Inventor that is connected to the microphone. Still, unfortunately, we can’t measure sound intensity with it so this is why we need the extension. so, let's download the extension first. 

https://gldias.github.io/extensions/SoundPressureLevel/SoundPressureLevel.html


Now open up MIT App Inventor, start a new project, and call it NoisePollution.

Upload the sound pressure extension that you downloaded earlier by going to extensions and importing it from your computer.


Now, add a component of this extension by dragging it to the viewer. For its properties, make ListenIntervalMilliseconds equal to 500. This means that it will listen every half a second.

For screen1 properties, make the background black and align horizontal and align vertical both center. Make screen orientation portrait and change the title to Noise Pollution.

Drag a slider from the User Interface. Rename to soundLvlBar. Make colorLeft dark blue.

Color right should stay default.

Width: 95%

Max value: 150

Min Value: 1

Uncheck thumb enabled as we don’t want the slider to be changed by the user.

And thumb position should be 1.

Add a label from User Interface. Rename to decibelsLbl. Make font bold, font size 22. 

Make the height: 15%,

text alignment: center, 

and text color: white.


Duplicate decibelsLbl (Ctrl + C and Ctrl V for Windows OR Command C + Command V for MacOS). Rename to soundDescLbl. Make font size 18.

Our simple but efficient screen design is done.

Let’s go to the blocks section.

We need the microphone permission for using the sound pressure extension so when screen1 is initialized, ask for permission for audio.

Get  screen1. Initialize. Inside it, put screen 1.AskFor Permission block and choose Audio.

Now, our sound pressure extension measures sound intensity using three types of measurements: Decibels, aWeightedDecibels, and cWeightedDecibels. We will use aWeightedDecibelsDecibels as A-weighting is the standard for determining hearing damage and noise pollution.


Whenever the noise surrounding the mobile phone changes, we need to check for the sound pressure level updated event to get that event from the sound pressure component. Inside it, we will first show the value of aWeightedDecibels in decibelsLbl but we will also round it off so use a round block from maths.


And next, we are going to look at the actual value of A-weighted decibels and do a comparison and update our slider accordingly. I am using this chart:

https://www.electronicshub.org/noise-level-decibels-chart/

Noise Level Chart

First, I am going to make a procedure that takes in three inputs: the actual value for our slider, the color for the slider’s left-hand side, and the description of the sound.

You can add inputs by clicking on cogwheel for the procedure and dragging and dropping. 


From controls get the if/else if/if i.e. the third type of if block. I am going to add 3 more else ifs by clicking on the cogwheel.

The first condition is when dbA is <= 30. This means it is very quiet and similar to a recording studio so we will call our updateScreen procedure with all this input.  Similarly, we will do the remaining.

<=70 No Risk - Normal sounds

<=85 No Risk - Loud Radio and busy Traffic

<=120 Risk - Concert or Airplane (orange color)

<=150 Hearing Damage - Concert (red  color)

And else means greater than 150 so we will put the thumb position manually at max value for the slider and update the color to dark red and soundDescLbl to Extremely High Risk.


So we are done. I hope you will have fun making this cool app and checking out the sound around to see whether it is a risk. The app uses an extension so it will not work on an iPhone. Also, the sound pressure level component stops working if the screen times out for your device so either turn off screen timeout or give it a longer interval, such as 5 minutes.

You can also download aia file for this project.

NoisePollution Project File


And, you can also have a look at the video tutorial here.

Please like my video and share it with your friends and family. Also, subscribe to my channel and press the bell icon so you don't miss any of the great projects I have planned for you. 

https://www.youtube.com/c/obsidiansofteducation

Comments

Popular posts from this blog

Jolly Phonics Group 1

Jolly Phonics Group 2

Jolly Phonics Flash Cards