{"id":167,"date":"2017-07-22T19:35:24","date_gmt":"2017-07-22T19:35:24","guid":{"rendered":"http:\/\/digm.drexel.edu\/uxid\/?p=167"},"modified":"2017-07-24T00:52:36","modified_gmt":"2017-07-24T00:52:36","slug":"light-theremin","status":"publish","type":"post","link":"https:\/\/philsinatra.net\/branches\/uxid\/2017\/07\/22\/light-theremin\/","title":{"rendered":"Light Theremin"},"content":{"rendered":"<p>A theremin is an\u00a0electronic musical instrument\u00a0controlled without any physical contact from the musician. It is named after it\u2019s Russian inventor, Leon Theremin. The device was patented in 1928. Here he is demonstrating his invention:<\/p>\n<figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube\"><div class=\"wp-block-embed__wrapper\"><iframe  id=\"_ytid_12932\"  width=\"326\" height=\"245\"  data-origwidth=\"326\" data-origheight=\"245\" src=\"https:\/\/www.youtube.com\/embed\/w5qf9O6c20o?enablejsapi=1&autoplay=0&cc_load_policy=0&cc_lang_pref=&iv_load_policy=1&loop=0&modestbranding=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure>\n<p>In project 6 of the Arduino starter kit we build a theremin that uses a photoresistor to measure light input, then convert that data into an audio signal that will sent to a piezo speaker for audio feedback.<\/p>\n<p>In the setup there is a loop that takes the first five seconds after loading to record the higher and lowest value that the photoresists records to determine the range. (sensorHigh &amp; sensorLow). So we can play with using a really bright desktop lamp to see how much variation we can create.<\/p>\n<p>In the loop function of the project code, we get the light sensor data and figure out where it is in the rage from low to high as defined in the setup. Then we find the same proportional place meant in the preset frequency range. We do this using the <code>map()<\/code> function.<\/p>\n<p><code>map(value, fromLow, fromHigh, toLow, toHigh)<\/code><\/p>\n<p>We then use the <code>tone()<\/code> function to generate a square wave of the specified frequency. The UNO has a frequency(Hz) range of 31 to 65535. Humans have an average hearing range of 20 to 20,000 hertz.<\/p>\n<p><code>tone(pin, frequency, duration)<\/code><\/p>\n<p>Here is the complete project:<\/p>\n<figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube\"><div class=\"wp-block-embed__wrapper\"><iframe  id=\"_ytid_68740\"  width=\"326\" height=\"183\"  data-origwidth=\"326\" data-origheight=\"183\" src=\"https:\/\/www.youtube.com\/embed\/jBfWN-roU08?enablejsapi=1&autoplay=0&cc_load_policy=0&cc_lang_pref=&iv_load_policy=1&loop=0&modestbranding=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure>\n<p>In my research I found that there is a limitation with the tone command in that only one tone can be generated at a time. If a tone is already playing on a different pin, the call to tone() will have no effect. If the tone is playing on the same pin, the call will set its frequency. If we want to play different pitches on multiple pins, we will need to call noTone() on one pin before calling tone() on the next pin.<\/p>\n<p>I have two small speakers that I found and am going to use two photoresistors and try to create a light theremin capable of playing two tones simultaneously.<\/p>\n<figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube\"><div class=\"wp-block-embed__wrapper\"><iframe  id=\"_ytid_59798\"  width=\"326\" height=\"183\"  data-origwidth=\"326\" data-origheight=\"183\" src=\"https:\/\/www.youtube.com\/embed\/-P13EUaP57g?enablejsapi=1&autoplay=0&cc_load_policy=0&cc_lang_pref=&iv_load_policy=1&loop=0&modestbranding=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure>\n<p>With that working, I want better notification for the setup process, so I added in a red led and two green legs. The red led will flash 5 times before the setup process, stay light with grabbing the sensor data, flash 5 more times to signify the setup is complete, then turn off for the duration.<\/p>\n<p>Once we are in the loop the green lights next to each speaker will turn on and off as the tone is being sent to that speaker.<\/p>\n<figure class=\"wp-block-embed wp-block-embed-youtube is-type-video is-provider-youtube\"><div class=\"wp-block-embed__wrapper\"><iframe  id=\"_ytid_36577\"  width=\"326\" height=\"183\"  data-origwidth=\"326\" data-origheight=\"183\" src=\"https:\/\/www.youtube.com\/embed\/-QcqyN0PbD4?enablejsapi=1&autoplay=0&cc_load_policy=0&cc_lang_pref=&iv_load_policy=1&loop=0&modestbranding=0&rel=1&fs=1&playsinline=0&autohide=2&theme=dark&color=red&controls=1&\" class=\"__youtube_prefs__  no-lazyload\" title=\"YouTube player\"  allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen data-no-lazy=\"1\" data-skipgform_ajax_framebjll=\"\"><\/iframe><\/div><\/figure>\n<p>And here is the final code and schematic:<\/p>\n<p class=\"codepen\" data-height=\"600\" data-theme-id=\"dark\" data-slug-hash=\"jLNeqO\" data-default-tab=\"js\" data-user=\"findes\" data-embed-version=\"2\" data-pen-title=\"Arduino: 2 speaker light theremin\">See the Pen <a href=\"https:\/\/codepen.io\/findes\/pen\/jLNeqO\/\">Arduino: 2 speaker light theremin<\/a> by Troy Finamore (<a href=\"https:\/\/codepen.io\/findes\">@findes<\/a>) on <a href=\"https:\/\/codepen.io\">CodePen<\/a>.<\/p>\n<p><script async src=\"https:\/\/production-assets.codepen.io\/assets\/embed\/ei.js\"><\/script><\/p>\n<p><a href=\"http:\/\/digm.drexel.edu\/uxid\/wp-content\/uploads\/2017\/07\/LightTheremin-Schematic.png\"><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-171\" src=\"http:\/\/digm.drexel.edu\/uxid\/wp-content\/uploads\/2017\/07\/LightTheremin-Schematic-300x216.png\" alt=\"LightTheremin-Schematic\" width=\"300\" height=\"216\" srcset=\"https:\/\/philsinatra.net\/branches\/uxid\/wp-content\/uploads\/2017\/07\/LightTheremin-Schematic-300x216.png 300w, https:\/\/philsinatra.net\/branches\/uxid\/wp-content\/uploads\/2017\/07\/LightTheremin-Schematic.png 704w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>What else can we do with this? How about an on\/off button? Or what if we use the potentiometer instead of one of the light sensors, or as a volume knob?<\/p>\n","protected":false},"excerpt":{"rendered":"<p>A theremin is an\u00a0electronic musical instrument\u00a0controlled without any physical contact from the musician. It is named after it\u2019s Russian inventor, Leon Theremin. The device was patented in 1928. Here he is demonstrating his invention: In project 6 of the Arduino starter kit we build a theremin that uses a photoresistor &hellip;<\/p>\n","protected":false},"author":2,"featured_media":170,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[5],"tags":[],"_links":{"self":[{"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/posts\/167"}],"collection":[{"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/comments?post=167"}],"version-history":[{"count":10,"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/posts\/167\/revisions"}],"predecessor-version":[{"id":179,"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/posts\/167\/revisions\/179"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/media\/170"}],"wp:attachment":[{"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/media?parent=167"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/categories?post=167"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/philsinatra.net\/branches\/uxid\/wp-json\/wp\/v2\/tags?post=167"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}