{"id":2251,"date":"2022-02-15T18:46:30","date_gmt":"2022-02-15T23:46:30","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2251"},"modified":"2022-04-04T16:11:53","modified_gmt":"2022-04-04T20:11:53","slug":"assignment-5-jud","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2251","title":{"rendered":"Assignment 5 &#8211; Jud"},"content":{"rendered":"<p>The idea for this sensor reading is to read the noise level in a room and detect whether it would be damaging to someone&#8217;s hearing. For the average human ear, a sustained noise level over 70dB or a burst of sound over 120dB can cause harm to the human ear. In order to counteract this, I used a speaker sensor connected to an Arduino to read the noise level in a room and decide whether either of these conditions have been met. If they have then an LED would turn on. So far I have gotten the speaker to read data but I haven&#8217;t been able to translate this data into decibels at the moment. The sensor I am currently using measures the noise level in its output by varying the signal to a degree relative to the amount of noise being detected. So if there is a high noise level, the sensor gives data that looks like the following:<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-2271 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.05-PM.png\" alt=\"\" width=\"1908\" height=\"1140\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.05-PM.png 1908w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.05-PM-300x179.png 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.05-PM-1024x612.png 1024w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.05-PM-768x459.png 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.05-PM-1536x918.png 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.05-PM-1200x717.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p>If there is a low noise output, the data looks more uniform like a straight line.<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-2270 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.19-PM.png\" alt=\"\" width=\"1908\" height=\"1140\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.19-PM.png 1908w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.19-PM-300x179.png 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.19-PM-1024x612.png 1024w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.19-PM-768x459.png 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.19-PM-1536x918.png 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/wp-content\/uploads\/2022\/02\/Screen-Shot-2022-02-15-at-6.43.19-PM-1200x717.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<p>I attempted to write a script that would look at the change in this data and use a filter to smooth the delta calculation but this didn&#8217;t work very well when I tried it out. My next idea would be to take a moving average of the data over time and then take the max and min of that range as the magnitude of the noise level. With this magnitude, it could then be converted into decibels through tuning of an equation.<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/\/Define Accelerometer Variables for pins\r\n#define MICROPHONE   A0\r\n\r\ndouble speakerLevel = 0;\r\ndouble prevSpeakerLevel = 0;\r\ndouble delta = 0;\r\ndouble prevDelta = 0;\r\n\r\ndouble alpha = 0.8;\r\n\r\n\r\nvoid setup() {\r\n  \/\/Setup pins as inputs\r\n\r\n  pinMode(MICROPHONE, INPUT);\r\n  \r\n  Serial.begin(9600);\r\n\r\n}\r\n\r\nvoid loop() {\r\n\r\n  speakerLevel = analogRead(MICROPHONE);\r\n  delta = abs(speakerLevel - prevSpeakerLevel);\r\n\r\n  speakerLevel = alpha*speakerLevel + (1-alpha)*prevSpeakerLevel;\r\n\r\n  delta = alpha*delta + (1-alpha)*prevDelta;\r\n\r\n  prevDelta = delta;\r\n  \r\n  Serial.println(speakerLevel);\r\n\/\/  Serial.println(delta);\r\n  \r\n}<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The idea for this sensor reading is to read the noise level in a room and detect whether it would be damaging to someone&#8217;s hearing. For the average human ear, a sustained noise level over 70dB or a burst of sound over 120dB can cause harm to the human ear. In order to counteract this, &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/?p=2251\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Assignment 5 &#8211; Jud&#8221;<\/span><\/a><\/p>\n","protected":false},"author":30,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[14,1],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2251"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/users\/30"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2251"}],"version-history":[{"count":1,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2251\/revisions"}],"predecessor-version":[{"id":2272,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=\/wp\/v2\/posts\/2251\/revisions\/2272"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2251"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2251"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/s2022\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2251"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}