{"id":2033,"date":"2020-12-22T02:33:55","date_gmt":"2020-12-22T07:33:55","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=2033"},"modified":"2020-12-22T02:33:55","modified_gmt":"2020-12-22T07:33:55","slug":"change-of-tune","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=2033","title":{"rendered":"Change of tune"},"content":{"rendered":"<p><strong>Problem:<br \/>\n<\/strong>There are many factors that have to be considered in managing risk of contagion during the pandemic.\u00a0One particularly difficult element to get a good gauge on and keep continuous track of is is how well ventilated the air around you is at any given time.<\/p>\n<p>This is crucial and can counterbalance whether it is safe to remain where you are at any given point of time. It can significantly overcome the risk odds of being less than 6ft away from people, both indoors and outdoors.<\/p>\n<div style=\"width: 700px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-2033-1\" width=\"700\" height=\"750\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/aerosol_english.mp4?_=1\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/aerosol_english.mp4\">https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/11\/aerosol_english.mp4<\/a><\/video><\/div>\n<p>Without ventilation, aerosols remain suspended in the air, becoming increasingly concentrated as time goes by. (<a href=\"https:\/\/english.elpais.com\/society\/2020-10-28\/a-room-a-bar-and-a-class-how-the-coronavirus-is-spread-through-the-air.html\">Source<\/a>)<\/p>\n<div class=\"wp-video\">\n<div id=\"mep_9\" class=\"mejs-container mejs-container-keyboard-inactive wp-video-shortcode mejs-video\" role=\"application\" aria-label=\"Video Player\">\n<div class=\"mejs-inner\">\n<div class=\"mejs-mediaelement\"><strong>Solution:<\/strong><\/div>\n<\/div>\n<\/div>\n<\/div>\n<div>A concealed wind sensor housed in a lapel pin that gives you audio feedback about the air ventilation around you. Ideally, this would be able to connect to your phone or audio device wirelessly so that you can check on this discretely whenever needed.<\/div>\n<div><\/div>\n<div>To engage, push a button on the pin and the reading will be sent to your audio device.<\/div>\n<div><img loading=\"lazy\" class=\"alignnone size-medium wp-image-2034\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/5a473ca9f30c5349661f867b-large-300x297.jpg\" alt=\"\" width=\"300\" height=\"297\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/5a473ca9f30c5349661f867b-large-300x297.jpg 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/5a473ca9f30c5349661f867b-large-150x150.jpg 150w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/5a473ca9f30c5349661f867b-large.jpg 570w\" sizes=\"(max-width: 300px) 85vw, 300px\" \/><\/div>\n<div><\/div>\n<div><strong>Visual indicators:<\/strong><\/div>\n<div>For demo purposes, I have added LEDs to help visualize the invisible elements present in the solution.<\/div>\n<div><\/div>\n<div>White LED: visual feedback of wind sensor values changing<\/div>\n<div>Green\/yellow\/red LED: indicator of what range of ventilation is safe or not.<\/div>\n<div><\/div>\n<div><strong>Audio feedback:<\/strong><\/div>\n<div>I chose 3 different tunes for the 3 risk levels:<\/div>\n<div><\/div>\n<div>High risk &#8211; morse code for SOS<\/div>\n<div>Medium risk &#8211; tense, suspenseful tune<\/div>\n<div>Low risk &#8211; major key arpeggio as a simple, positive sounding indicator.<\/div>\n<div><\/div>\n<div><strong>Demo:<\/strong><\/div>\n<div>\n<p>At the start, the wind sensor reads a low level of ventilation, and starts playing the SOS tune. As the ventilation increases, it switches to the low risk tune of a major arpeggio. As that value falls slightly, it starts playing the suspenseful tune before reverting back to the major arpeggio as the values increase again.<\/p>\n<p><iframe title=\"IMG_0339\" src=\"https:\/\/player.vimeo.com\/video\/493633310?dnt=1&amp;app_id=122963\" width=\"563\" height=\"1000\" frameborder=\"0\" allow=\"autoplay; fullscreen\" allowfullscreen><\/iframe><\/p>\n<p><strong>Components:<\/strong><\/p>\n<ul>\n<li>1x RGB Diffused Common Cathode<\/li>\n<li>3x LED (Red, Green, Yellow)<\/li>\n<li>1x button<\/li>\n<li>7x Resistor 220 ohm<\/li>\n<li>Wind Sensor Rev. C<\/li>\n<li>35CSB speaker<\/li>\n<\/ul>\n<p><strong>Schematic:<\/strong><\/p>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-2036\" src=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/soundCrit_bb.png\" alt=\"\" width=\"2073\" height=\"1290\" srcset=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/soundCrit_bb.png 2073w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/soundCrit_bb-300x187.png 300w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/soundCrit_bb-1024x637.png 1024w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/soundCrit_bb-768x478.png 768w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/soundCrit_bb-1536x956.png 1536w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/soundCrit_bb-2048x1274.png 2048w, https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/wp-content\/uploads\/2020\/12\/soundCrit_bb-1200x747.png 1200w\" sizes=\"(max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/p>\n<\/div>\n<p>Code:<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">\/*************************************************\r\n* Sound Sensor\r\n*************************************************\/\r\n#define analogPinForRV    1   \/\/ blue jumper wire\r\n#define analogPinForTMP   0   \/\/ yellow jumper wire\r\n\r\n\/\/ to calibrate your sensor, put a glass over it, but the sensor should not be\r\n\/\/ touching the desktop surface however.\r\n\/\/ adjust the zeroWindAdjustment until your sensor reads about zero with the glass over it. \r\n\r\nconst float zeroWindAdjustment =  .2; \/\/ negative numbers yield smaller wind speeds and vice versa.\r\n\r\nint TMP_Therm_ADunits;  \/\/temp termistor value from wind sensor\r\nfloat RV_Wind_ADunits;    \/\/RV output from wind sensor \r\nfloat RV_Wind_Volts;\r\nunsigned long lastMillis;\r\nint TempCtimes100;\r\nfloat zeroWind_ADunits;\r\nfloat zeroWind_volts;\r\nfloat WindSpeed_MPH;\r\n\r\n\/\/LED Feedback\r\nint redPin = 9; \/\/Pin for the red RGB led pin\r\nint greenPin = 10; \/\/Pin for the green RGB led pin\r\nint bluePin = 11; \/\/Pin for the blue RGB led pin \r\n\r\nint writeValue_red; \/\/declare variable to send to the red LED\r\nint writeValue_green; \/\/declare variable to send to the green LED\r\nint writeValue_blue; \/\/declare variable to send to the blue LED\r\n\r\n\r\n\r\n\/*************************************************\r\n* Interrupt Button\r\n*************************************************\/\r\nstatic const int togglePin = 5;\r\nbool buttonState = false;\r\nconst bool isInterrupt = true;\r\n\r\n\/*************************************************\r\n* Melodies\r\n*************************************************\/\r\n#include \"pitches.h\"\r\nint speakerPin = 8;\r\n\r\n\/\/ notes in the major melody (9 notes):\r\nint majorMelody[] = {\r\nNOTE_C4, NOTE_D4,NOTE_G4, NOTE_C5, 0, NOTE_C4, NOTE_D4, NOTE_G4, NOTE_C5};\r\n\r\n\/\/ note durations: 4 = quarter note, 8 = eighth note, etc.:\r\nint majorNoteDurations[] = {\r\n   4, 4, 4, 4, 4, 4, 4, 4, 4\r\n};\r\n\r\n\/\/ notes in the minor melody (9 notes):\r\nint minorMelody[] = {\r\nNOTE_FS4, NOTE_FS4, NOTE_FS4, NOTE_DS4, 0, NOTE_E4, NOTE_E4, NOTE_E4, NOTE_CS4};\r\n\/\/ note durations: 4 = quarter note, 8 = eighth note, etc.:\r\n\r\nint minorNoteDurations[] = {\r\n   8, 8, 8, 2, 4, 8, 8, 8, 2\r\n};\r\n\r\n\/\/ notes in morse code (11 notes):\r\nint SOS[] = {\r\n  NOTE_GS5, NOTE_GS5, NOTE_GS5, 0, NOTE_GS5, NOTE_GS5, NOTE_GS5, 0, NOTE_GS5, NOTE_GS5, NOTE_GS5\r\n};\r\n\r\nint SOSDurations[] = {\r\n  8, 8, 8, 4, 2, 2, 2, 4, 8, 8, 8\r\n};\r\n\r\n\r\n\/*************************************************\r\n * \r\n * SETUP\r\n * \r\n*************************************************\/\r\n\r\n\/\/void SwitchPressed(){\r\n\/\/  buttonState =! buttonState;\r\n\/\/}\r\n\r\nvoid setup() {\r\n\r\n  Serial.begin(57600);   \/\/ faster printing to get a bit better throughput on extended info\r\n  \/\/ remember to change your serial monitor\r\n\r\n  Serial.println(\"start\");\r\n  \/\/ put your setup code here, to run once:\r\n\r\n  \/\/   Uncomment the three lines below to reset the analog pins A2 &amp; A3\r\n  \/\/   This is code from the Modern Device temp sensor (not required)\r\n  pinMode(A2, INPUT);        \/\/ GND pin      \r\n  pinMode(A3, INPUT);        \/\/ VCC pin\r\n  digitalWrite(A3, LOW);     \/\/ turn off pullups\r\n\r\n  \/\/initialize button pin as input\r\n\/\/  pinMode(buttonPin, INPUT_PULLUP);\r\n\r\n  \/\/Risk feedback state\r\n  int greenLED = 2;\r\n  int yellowLED = 3;\r\n  int redLED = 4;\r\n  pinMode(greenLED, OUTPUT);\r\n  pinMode(yellowLED, OUTPUT);\r\n  pinMode(redLED, OUTPUT);\r\n\r\n\/\/  if (isInterrupt){\r\n\/\/      attachInterrupt(digitalPinToInterrupt(togglePin), SwitchPressed, RISING);    \r\n\/\/  }\r\n  \r\n}\r\n\r\nvoid loop() {\r\n  \r\n\/*************************************************\r\n* Reading Wind Sensor\r\n*************************************************\/\r\n  if (millis() - lastMillis &gt; 200){      \/\/ read every 200 ms - printing slows this down further\r\n    \r\n    TMP_Therm_ADunits = analogRead(analogPinForTMP);\r\n    RV_Wind_ADunits = analogRead(analogPinForRV);\r\n    RV_Wind_Volts = (RV_Wind_ADunits *  0.0048828125);\r\n\r\n    \/\/ these are all derived from regressions from raw data as such they depend on a lot of experimental factors\r\n    \/\/ such as accuracy of temp sensors, and voltage at the actual wind sensor, (wire losses) which were unaccouted for.\r\n    TempCtimes100 = (0.005 *((float)TMP_Therm_ADunits * (float)TMP_Therm_ADunits)) - (16.862 * (float)TMP_Therm_ADunits) + 9075.4;  \r\n\r\n    zeroWind_ADunits = -0.0006*((float)TMP_Therm_ADunits * (float)TMP_Therm_ADunits) + 1.0727 * (float)TMP_Therm_ADunits + 47.172;  \/\/  13.0C  553  482.39\r\n\r\n    zeroWind_volts = (zeroWind_ADunits * 0.0048828125) - zeroWindAdjustment;  \r\n\r\n    \/\/ This from a regression from data in the form of \r\n    \/\/ Vraw = V0 + b * WindSpeed ^ c\r\n    \/\/ V0 is zero wind at a particular temperature\r\n    \/\/ The constants b and c were determined by some Excel wrangling with the solver.\r\n    \r\n   WindSpeed_MPH =  pow(((RV_Wind_Volts - zeroWind_volts) \/.2300) , 2.7265);   \r\n   \r\n\/\/    Serial.print(\"  TMP volts \");\r\n\/\/    Serial.print(TMP_Therm_ADunits * 0.0048828125);\r\n\/\/    \r\n\/\/    Serial.print(\" RV volts \");\r\n\/\/    Serial.print((float)RV_Wind_Volts);\r\n\/\/\r\n\/\/    Serial.print(\"\\t  TempC*100 \");\r\n\/\/    Serial.print(TempCtimes100 );\r\n\/\/\r\n\/\/    Serial.print(\"   ZeroWind volts \");\r\n\/\/    Serial.print(zeroWind_volts);\r\n\r\n    Serial.print(\"   WindSpeed MPH \");\r\n    Serial.println((float)WindSpeed_MPH);\r\n\r\n    lastMillis = millis();\r\n  }\r\n\r\n\/*************************************************\r\n* Wind sensor LED feedback\r\n*************************************************\/\r\n\r\n  writeValue_red = (255.\/10.)*WindSpeed_MPH; \/\/Calculate the value to write on the red LED (add point to change to float point)\r\n  writeValue_green = (255.\/10.)*WindSpeed_MPH; \/\/Calculate the value to write on the green LED\r\n  writeValue_blue = (255.\/10.)*WindSpeed_MPH; \/\/\/Calculate the value to write on the blue LED\r\n  \r\n  analogWrite(redPin,writeValue_red); \/\/write value to set the brightness of the red LED\r\n  analogWrite(greenPin,writeValue_green); \/\/write value to set the brightness of the green LED\r\n  analogWrite(bluePin,writeValue_blue); \/\/write value to set the brightness of the blue LED\r\n\r\n\r\n\r\n\/*************************************************\r\n* State + Sound\r\n*************************************************\/\r\n\r\n\/\/if (buttonState == true){\r\n\/\/  \r\n\r\n    if(WindSpeed_MPH &lt;= 2){\r\n    \/\/ turn red LED on:\r\n    digitalWrite(4, HIGH);\r\n    \/\/ turn the rest off:\r\n    digitalWrite(2, LOW);\r\n    digitalWrite(3, LOW);\r\n\r\n    \/\/ play SOS melody:\r\n     for (int thisNote = 0; thisNote &lt; 11; thisNote++) {\r\n      int noteDuration = 1000\/SOSDurations[thisNote];\r\n      tone(8, SOS[thisNote],noteDuration);\r\n      \/\/pause for the note's duration plus 30 ms:\r\n      delay(noteDuration +30);\r\n      noTone(8);\r\n    }\r\n  }\r\n\r\n    else if (WindSpeed_MPH &gt;7) {\r\n      \/\/turn green LED on:\r\n      digitalWrite(2, HIGH);\r\n      \/\/ turn the rest off:\r\n      digitalWrite(4, LOW);\r\n      digitalWrite(3, LOW);\r\n\r\n      \/\/play major melody:\r\n      for (int thisNote = 0; thisNote &lt; 9; thisNote++) {\r\n      int noteDuration = 1000\/majorNoteDurations[thisNote];\r\n      tone(8, majorMelody[thisNote],noteDuration);\r\n      \/\/pause for the note's duration plus 30 ms:\r\n      delay(noteDuration +30);\r\n      noTone(8);\r\n    }\r\n   }\r\n\r\n    else {\r\n      \/\/turn yellow LED on:\r\n      digitalWrite(3, HIGH);\r\n      \/\/ turn the rest off:\r\n      digitalWrite(2, LOW);\r\n      digitalWrite(4, LOW);\r\n\r\n      \/\/play minor melody:\r\n      for (int thisNote = 0; thisNote &lt; 9; thisNote++) {\r\n      int noteDuration = 1000\/minorNoteDurations[thisNote];\r\n      tone(8, minorMelody[thisNote],noteDuration);\r\n      \/\/pause for the note's duration plus 30 ms:\r\n      delay(noteDuration +30);\r\n      noTone(8);\r\n      \r\n    }\r\n    }\r\n\/\/    }\r\n\/\/    else {\r\n\/\/      noTone(8);\r\n\/\/      \/\/turn all LEDs off:\r\n\/\/      digitalWrite(3, LOW);\r\n\/\/      digitalWrite(2, LOW);\r\n\/\/      digitalWrite(4, LOW);\r\n\/\/    }\r\n\/*************************************************\r\n* Wind sensor LED feedback on button press\r\n*************************************************\/\r\n\/\/buttonState = digitalRead(buttonPin);\r\n\/\/\r\n\/\/if (buttonState == HIGH){\r\n\/\/\r\n\/\/  if (flag == 0){\r\n\/\/    \/\/light up white LED\r\n\/\/    analogWrite(redPin,writeValue_red); \/\/write value to set the brightness of the red LED\r\n\/\/    analogWrite(greenPin,writeValue_green); \/\/write value to set the brightness of the green LED\r\n\/\/    analogWrite(bluePin,writeValue_blue); \/\/write value to set the brightness of the blue LED\r\n\/\/  flag = 1;\r\n\/\/  }\r\n\/\/\r\n\/\/  if (flag == 1){\r\n\/\/    \/\/turn off white LED\r\n\/\/    analogWrite(redPin,0); \/\/write value to set the brightness of the red LED\r\n\/\/    analogWrite(greenPin,0); \/\/write value to set the brightness of the green LED\r\n\/\/    analogWrite(bluePin,0); \/\/write value to set the brightness of the blue LED\r\n\/\/    flag = 0;\r\n\/\/  }\r\n\/\/}\r\n\/\/\r\n\/\/if (buttonState == HIGH){\r\n\/\/    \/\/light up white LED\r\n\/\/    analogWrite(redPin,writeValue_red); \/\/write value to set the brightness of the red LED\r\n\/\/    analogWrite(greenPin,writeValue_green); \/\/write value to set the brightness of the green LED\r\n\/\/    analogWrite(bluePin,writeValue_blue); \/\/write value to set the brightness of the blue LED\r\n\/\/}\r\n\/\/\r\n\/\/else if (buttonState == LOW){\r\n\/\/    \/\/turn off white LED\r\n\/\/    analogWrite(redPin,0); \/\/write value to set the brightness of the red LED\r\n\/\/    analogWrite(greenPin,0); \/\/write value to set the brightness of the green LED\r\n\/\/    analogWrite(bluePin,0); \/\/write value to set the brightness of the blue LED\r\n\/\/}\r\n\r\n}<\/pre>\n<p>Reminder: include <a href=\"https:\/\/www.arduino.cc\/en\/Tutorial\/BuiltInExamples\/toneMelody\">pitches.h<\/a> for code to work<\/p>\n<div>\n<p>&nbsp;<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Problem: There are many factors that have to be considered in managing risk of contagion during the pandemic.\u00a0One particularly difficult element to get a good gauge on and keep continuous track of is is how well ventilated the air around you is at any given time. This is crucial and can counterbalance whether it is &hellip; <a href=\"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/?p=2033\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Change of tune&#8221;<\/span><\/a><\/p>\n","protected":false},"author":26,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[20,1],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/2033"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/users\/26"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2033"}],"version-history":[{"count":2,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/2033\/revisions"}],"predecessor-version":[{"id":2039,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=\/wp\/v2\/posts\/2033\/revisions\/2039"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/48-339\/f2020\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}