{"id":17164,"date":"2023-02-13T10:36:33","date_gmt":"2023-02-13T15:36:33","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/?p=17164"},"modified":"2023-02-22T10:02:34","modified_gmt":"2023-02-22T15:02:34","slug":"project-1-double-transducers-wind-speed-to-colored-light","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/project-1-double-transducers-wind-speed-to-colored-light\/","title":{"rendered":"Double Transducers: Wind Speed to Colored Light"},"content":{"rendered":"<div id=\"attachment_17175\" style=\"width: 484px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-17175\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-17175\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5891-244x300.jpg\" alt=\"\" width=\"474\" height=\"583\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5891-244x300.jpg 244w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5891-832x1024.jpg 832w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5891-768x946.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5891-1247x1536.jpg 1247w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5891-1663x2048.jpg 1663w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5891-973x1198.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5891-508x626.jpg 508w\" sizes=\"(max-width: 474px) 100vw, 474px\" \/><p id=\"caption-attachment-17175\" class=\"wp-caption-text\">Overall project photo<\/p><\/div>\n<p>Team: Sapna Tayal, Harry Ren<\/p>\n<p>Our project took the input of wind speed through a wind sensor and converted that to linear motion through a rack and pinion mechanism. This linear movement is detected by an ultrasonic ranger and transmitted into an RGB value to a Neopixel-led ring.<\/p>\n<p>Video of the transducers working:<\/p>\n<p>Sapna:<\/p>\n<div style=\"width: 620px;\" class=\"wp-video\"><!--[if lt IE 9]><script>document.createElement('video');<\/script><![endif]-->\n<video class=\"wp-video-shortcode\" id=\"video-17164-1\" width=\"620\" height=\"1102\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Untitled-1.mp4?_=1\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Untitled-1.mp4\">https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Untitled-1.mp4<\/a><\/video><\/div>\n<p>Harry:<\/p>\n<div style=\"width: 620px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-17164-2\" width=\"620\" height=\"1102\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_92631.mp4?_=2\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_92631.mp4\">https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_92631.mp4<\/a><\/video><\/div>\n<p>Sapna&#8217;s Images:<\/p>\n<div id=\"attachment_17190\" style=\"width: 256px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-17190\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-17190 size-medium\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5740-246x300.jpg\" alt=\"\" width=\"246\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5740-246x300.jpg 246w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5740-839x1024.jpg 839w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5740-768x938.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5740-1258x1536.jpg 1258w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5740-1677x2048.jpg 1677w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5740-973x1188.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5740-508x620.jpg 508w\" sizes=\"(max-width: 246px) 100vw, 246px\" \/><p id=\"caption-attachment-17190\" class=\"wp-caption-text\">testing the light and the servo motor with a potentiometer<\/p><\/div>\n<div id=\"attachment_17196\" style=\"width: 310px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-17196\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-17196 size-medium\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5738-300x297.jpg\" alt=\"\" width=\"300\" height=\"297\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5738-300x297.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5738-1024x1013.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5738-150x150.jpg 150w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5738-768x759.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5738-1536x1519.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5738-2048x2025.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5738-88x88.jpg 88w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5738-973x962.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5738-508x502.jpg 508w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><p id=\"caption-attachment-17196\" class=\"wp-caption-text\">doing tests with wind sensor (the broken one so it wasn&#8217;t working)<\/p><\/div>\n<div id=\"attachment_17195\" style=\"width: 291px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-17195\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-17195 size-medium\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5747-2-281x300.jpg\" alt=\"\" width=\"281\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5747-2-281x300.jpg 281w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5747-2-960x1024.jpg 960w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5747-2-768x819.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5747-2-1440x1536.jpg 1440w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5747-2-1920x2048.jpg 1920w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5747-2-973x1038.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG_5747-2-508x542.jpg 508w\" sizes=\"(max-width: 281px) 100vw, 281px\" \/><p id=\"caption-attachment-17195\" class=\"wp-caption-text\">Assembly process! Adjusting the distance of the rack and pinion for an effective mapping of the ultrasonic sensor<\/p><\/div>\n<p>&nbsp;<\/p>\n<p>Harry&#8217;s Images:<\/p>\n<div id=\"attachment_17346\" style=\"width: 366px\" class=\"wp-caption alignleft\"><img aria-describedby=\"caption-attachment-17346\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-17346\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Screen-Shot-2023-02-14-at-4.59.36-PM-300x252.png\" alt=\"\" width=\"356\" height=\"299\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Screen-Shot-2023-02-14-at-4.59.36-PM-300x252.png 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Screen-Shot-2023-02-14-at-4.59.36-PM-1024x862.png 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Screen-Shot-2023-02-14-at-4.59.36-PM-768x646.png 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Screen-Shot-2023-02-14-at-4.59.36-PM-973x819.png 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Screen-Shot-2023-02-14-at-4.59.36-PM-508x428.png 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Screen-Shot-2023-02-14-at-4.59.36-PM.png 1136w\" sizes=\"(max-width: 356px) 100vw, 356px\" \/><p id=\"caption-attachment-17346\" class=\"wp-caption-text\">Final Transducer: Wind sensor inputs from the left, Color light outputs from the right.<\/p><\/div>\n<div id=\"attachment_17348\" style=\"width: 235px\" class=\"wp-caption alignleft\"><img aria-describedby=\"caption-attachment-17348\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-17348\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9235-225x300.jpg\" alt=\"An image of a potentiometer and LED in a breadboard with an arduino\" width=\"225\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9235-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9235-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9235-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9235-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9235-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9235-508x677.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9235-scaled.jpg 1920w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><p id=\"caption-attachment-17348\" class=\"wp-caption-text\">Progress photo: Potentiometer LED setup which will soon be converted with a NEOPIXEL LED to test color code<\/p><\/div>\n<div id=\"attachment_17349\" style=\"width: 235px\" class=\"wp-caption alignleft\"><img aria-describedby=\"caption-attachment-17349\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-17349\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9245-1-225x300.jpg\" alt=\"A breadbord with a servo, ultrasonic ranger, LCD, wind sensor, and NEOPIXEL LED wired in. Wires are very tangled\" width=\"225\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9245-1-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9245-1-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9245-1-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9245-1-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9245-1-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9245-1-508x677.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9245-1-scaled.jpg 1920w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><p id=\"caption-attachment-17349\" class=\"wp-caption-text\">Progress photo: Completed wiring of the tranducer prior to assembly on the chip board.<\/p><\/div>\n<div id=\"attachment_17354\" style=\"width: 235px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-17354\" decoding=\"async\" loading=\"lazy\" class=\"size-medium wp-image-17354\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9265-225x300.jpg\" alt=\"Ultrasonic ranger across from a balsa sheet to track distance\" width=\"225\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9265-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9265-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9265-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9265-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9265-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9265-508x677.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9265-scaled.jpg 1920w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><p id=\"caption-attachment-17354\" class=\"wp-caption-text\">Part Highlight: ultrasonic ranger and the wall object that is being tracked. (The distance will change a light color)<\/p><\/div>\n<div id=\"attachment_17355\" style=\"width: 310px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-17355\" decoding=\"async\" loading=\"lazy\" class=\"wp-image-17355 size-medium\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9264-300x225.jpg\" alt=\"Part Highlight: Servo motor driving a laser printed rack &amp; pinion.\" width=\"300\" height=\"225\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9264-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9264-1024x768.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9264-768x576.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9264-1536x1152.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9264-2048x1536.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9264-973x730.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/IMG-9264-508x381.jpg 508w\" sizes=\"(max-width: 300px) 100vw, 300px\" \/><p id=\"caption-attachment-17355\" class=\"wp-caption-text\">Part Highlight: Servo motor driving a laser printed rack &amp; pinion.<\/p><\/div>\n<p>Discussion:<\/p>\n<p>Our process for making the double transducers was one with a lot of unexpected pitfalls\u2014 often issues that weren&#8217;t really in our control. We started by ideating different transducer pairs for the middle step of the project and realizing the different strengths we brought with our differing experiences and backgrounds (Harry with more experience working with code, and Sapna with designing and building physical things), decided to go with a linear motion and ultrasonic sensor pair one that seemed exciting. Borrowing a wind sensor from Ideate lending, and playing around with example code on some neopixel led lights, we headed into what would be the horrors of putting all the pieces together. The lights and mapping of the range of the ultrasonic sensor to RGB values came first. Not finding too much help with online resources, Harry figured out a series of if statements that would cycle the RGB values from the (255, 0, 0) to (255, 255, 255) and range through the red to yellow to green to blue to purple range. Once we got that working, we focused on mapping a simple potentiometer (for testing purposes) to a servo motor that would eventually hold the gear that would eventually move the rack closer or further away to the ultrasonic sensor. This worked just fine. But the issues really started when we tried to connect the wind sensor to the motor. It was a frustrating tug of war between running the example code for the wind sensor, having it work mostly well, and then running our code to map it to the servo, and having it give up on us. The data would just be too noisy, and extremely inconsistent. Turns out it was a bunch of things out to get us: the wind sensor we were testing with was (99% sure) broken, and through reverse checking by removing big chunks of code, testing, and then adding stuff back in, we found that there was probably a library clash between the wind sensor and the neopixel precoded libraries we were using. So, with a lot of overthinking and analysing of little pieces of code, we managed to find that expanding a loop for the 12 led bulbs in the neopixel seemed to mostly solve our bugs! The last thing was fine-tuning the ranges and maps for the different pieces, adding the LCD screen and putting it all together!<\/p>\n<p>With all of the electronics working, we proceeded with assembly. The process was mostly smooth. We did however, have some issues with the servo\/ rack and pinion assembly. Our solution was to use modeling clay to elevate the servo to the necessary height, and use balsa strips to create a rail for the rack and pinion. After the physical assembly, we completed a final tuning of the ranges and maps for each portion. Our final product works mostly as expected and testing was limited to the consistencies of our breath as we had no other way to produce constant wind for our input.<\/p>\n<p>This project served as an introduction to Arduino and electronics for the both of us and we are very happy with the final outcome. The process of successfully troubleshooting both a hardware problem, and a hidden software bug allowed us to experience both tracing physical electronic wiring and long code loops to find issues. This skill will no doubt be useful as we move on to more complex projects. Additionally, through our project and the class presentations, we learned about many useful and unique input and outputs that we could use in the future.<\/p>\n<p>&nbsp;<\/p>\n<p>Arduino Code :<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">\/*\r\nProject Name: Double Transducer: Wind speed to Light Color\r\n\r\nTeam Members: Harry Ren, Sapna Tayal\r\n\r\n- reads a wind speed input and converts it to a servo motor output\r\n- reads an ultrasonic sensor input and converts it to a light color\r\n- normalizes all input and output data and displays it on an LCD screen\r\n\r\nPin Mapping:\r\nA0: Wind sensor OUT\r\nA2: Wind sensor TMP\r\nSDA: LCD SDA\r\nSCL: LCD SCL\r\n12: Ultrasonic TRIG\r\n11: ULtrasonic ECHO\r\n6: LED Data IN\r\n5: Servo Data\r\n\r\nPortions of code are adapted from the following sources \r\n- Ideate 99-355: https:\/\/courses.ideate.cmu.edu\/99-355\/s2016a4\/text\/ex\/Arduino\/event-loop-programming\/event-loop-programming.html\r\n- NEOPIXEL by ADAFRUIT example: strandtest\r\nrelevant functions are credited\r\n\r\ncode by Harry Ren and Sapna Tayal at Carnegie Mellon University, (hjren@andrew.cmu.edu, sapnat@andrew.cmu.edu)\r\nreleased by the authors to the public domain, Feb 2023\r\n*\/\r\n\r\n#include &lt;Adafruit_NeoPixel.h&gt;\r\n#include &lt;Servo.h&gt;\r\n#include &lt;NewPing.h&gt;\r\n#include &lt;Wire.h&gt;\r\n#include &lt;LiquidCrystal_I2C.h&gt;\r\n#ifdef __AVR__\r\n#include &lt;avr\/power.h&gt; \/\/ Required for 16 MHz Adafruit Trinket\r\n#endif\r\n\r\n\/\/ Neopixel connection Pin?\r\n#define LED_PIN    6\r\n\/\/ How many NeoPixels are attached to the Arduino?\r\n#define LED_COUNT 60\r\n\/\/ Declare our NeoPixel strip object:\r\nAdafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);\r\n\r\n\/\/ Declare servo object\r\nServo doorMotor;\r\n\r\n\/\/Set Pin constants\r\nconst int DOORMOTORPIN = 5; \/\/Servo Pin\r\nconst int POTPIN = A1; \/\/ Potentiometer input for testing\r\nconst int OutPin  = A0;   \/\/ wind sensor analog pin  hooked up to Wind P sensor \"OUT\" pin\r\nconst int TempPin = A2;   \/\/ temp sesnsor analog pin hooked up to Wind P sensor \"TMP\" pin\r\nconst int trigPin = 12; \/\/ultrasonic trig pin\r\nconst int echoPin = 11; \/\/ultrasonic echo pin\r\n#define Max_D 20 \/\/ ultrasonic max distance\r\n\r\n\/\/Declare ultrasonic\r\nNewPing sonar(trigPin,echoPin,Max_D);\r\n\r\n\/\/Declare LCD screen\r\nLiquidCrystal_I2C screen(0x27, 16, 2);\r\n\r\n\/\/Declare Variables for Event loop programming\r\n\/\/Event loop function from https:\/\/courses.ideate.cmu.edu\/99-355\/s2016a4\/text\/ex\/Arduino\/event-loop-programming\/event-loop-programming.html\r\nlong next_output_time_1 = 0;        \/\/ timestamp in microseconds for when next to update output 1\r\nlong next_output_time_2 = 0;        \/\/ timestamp in microseconds for when next to update output 2\r\nlong output_interval_1 = 250000;       \/\/ interval in microseconds between output 1 updates\r\nlong output_interval_2 = 700;       \/\/ interval in microseconds between output 2 updates\r\nint output_state_1 = LOW;           \/\/ current state of output 1\r\nint output_state_2 = LOW;           \/\/ current state of output 2\r\n\r\n\/\/setup function\r\nvoid setup() {\r\n  Serial.begin(115200);\r\n  pinMode(POTPIN,INPUT);\r\n  pinMode(OutPin,INPUT);\r\n  doorMotor.attach(DOORMOTORPIN);\r\n\r\n  strip.begin();           \/\/ INITIALIZE NeoPixel strip object (REQUIRED)\r\n  strip.show();            \/\/ Turn OFF all pixels ASAP\r\n  strip.setBrightness(50); \/\/ Set BRIGHTNESS to about 1\/5 (max = 255)\r\n\r\n  screen.init(); \/\/INITIALIZE LCD Screen\r\n  screen.backlight();\r\n  screen.home();\r\n  screen.clear();\r\n}\r\n\r\n\/\/ loop() function\r\nvoid loop() {\r\n\r\n  \/\/Wind speed input code\r\n  int windADunits = analogRead(OutPin);\r\n  float windMPH =  pow((((float)windADunits - 264.0) \/ 85.6814), 3.36814);\r\n\r\n  \/\/Servo output code\r\n  int servoval= map(windMPH,0,5,0,180);\r\n  doorMotor.write(servoval);\r\n  delay(100);\r\n\r\n  \/\/ultrasonic input code \r\n  int ultra = sonar.ping_cm();\r\n  Serial.println(ultra);\r\n  int light_inp = map(ultra,12,6,0,1023);\r\n  \r\n  \/\/set colors, no looping implemented as looping during testing resulted in library conflicts with Servo.h\r\n  strip.setPixelColor(0, get_col(light_inp));\r\n  strip.setPixelColor(1, get_col(light_inp));\r\n  strip.setPixelColor(2, get_col(light_inp));\r\n  strip.setPixelColor(3, get_col(light_inp));\r\n  strip.setPixelColor(4, get_col(light_inp));\r\n  strip.setPixelColor(5, get_col(light_inp));\r\n  strip.setPixelColor(6, get_col(light_inp));\r\n  strip.setPixelColor(7, get_col(light_inp));\r\n  strip.setPixelColor(8, get_col(light_inp));\r\n  strip.setPixelColor(9, get_col(light_inp));\r\n  strip.setPixelColor(10, get_col(light_inp));\r\n  strip.setPixelColor(11, get_col(light_inp));\r\n  strip.setPixelColor(12, get_col(light_inp));\r\n  strip.setPixelColor(13, get_col(light_inp));\r\n  strip.setPixelColor(14, get_col(light_inp));\r\n  strip.setPixelColor(15, get_col(light_inp));\r\n  strip.setPixelColor(16, get_col(light_inp));\r\n  strip.show(); \r\n\r\n\r\n  \/\/ https:\/\/courses.ideate.cmu.edu\/99-355\/s2016a4\/text\/ex\/Arduino\/event-loop-programming\/event-loop-programming.html\r\n  \/\/ read the current time in microseconds\r\n  long now = micros();\r\n  \/\/ Polled task 1 for output 1.  Check if the next_output_time_1 timestamp has\r\n  \/\/ been reached; if so then update the output 1 state.\r\n  if (now &gt; next_output_time_1) {\r\n    \/\/ reset the timer for the next polling point\r\n    next_output_time_1 = now + output_interval_1;\r\n    \/\/ toggle the output_state_1 variable\r\n    output_state_1 = !output_state_1;\r\n\r\n    \/\/Screen instructions: Prints normalized values for all sensor readings\r\n    screen.clear();\r\n    screen.home();\r\n    screen.print(\"i:\");\r\n    int normwind = map(windMPH,0,20,0,100);\r\n    screen.print(normwind);\r\n    screen.setCursor(6,0);\r\n    screen.print(\"m:\");\r\n    int normServo = map(servoval,0,180,0,100);\r\n    screen.print(normServo);\r\n    screen.setCursor(8,1);\r\n    int normultra = map(ultra,12,6,0,100);\r\n    screen.print(normultra);\r\n    screen.setCursor(11,1);\r\n    screen.print(\"o:\");\r\n    int normlight = map(light_inp,0,1023,0,100);\r\n    screen.print(normlight);\r\n    }\r\n}\r\n\r\n\/\/ Color mapping function\r\n\/\/Input: int from 0 to 1023\r\n\/\/Output: RBG Tuple\r\n\r\n\/* RGB Values for reference\r\nred: (255, 0, 0)\r\ngreen: (0, 255, 0)\r\nblue: (0, 0, 255)\r\ncyan: (0, 255, 255)\r\npurple: (255, 0, 255)\r\nyellow: (255, 255, 0) \r\n*\/\r\nuint32_t get_col(int i){\r\n  \/\/red to yellow\r\n  if(i&lt;170){\r\n    i=map(i,0,170,0,255);\r\n    return strip.Color(255,i,0);\r\n  }\r\n  \/\/yellow to green\r\n  else if (i&lt;340){\r\n    i=map(i,170,340,0,255);\r\n    return strip.Color(255-i,255,0);\r\n  }\r\n  \/\/green to cyan\r\n  else if (i&lt;510){\r\n    i=map(i,340,510,0,255);\r\n    return strip.Color(0,255,i);\r\n  }\r\n  else if (i&lt;680){\r\n    i=map(i,510,680,0,255);\r\n    return strip.Color(0,255-i,255);\r\n  }\r\n  else if (i&lt;850){\r\n    i=map(i,680,850,0,255);\r\n    return strip.Color(i,0,255);\r\n  }\r\n  else{\r\n    i=map(i,850,1023,0,255);\r\n    return strip.Color(255,i,255);\r\n  }\r\n}\r\n<\/pre>\n<p>Block Diagram and Schematics:<\/p>\n<div id=\"attachment_17358\" style=\"width: 625px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-17358\" decoding=\"async\" loading=\"lazy\" class=\" wp-image-17358\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-content\/uploads\/2023\/02\/Project1-documentation.drawio.svg\" alt=\"\" width=\"615\" height=\"717\" \/><p id=\"caption-attachment-17358\" class=\"wp-caption-text\">Block Diagram and Schematics for transducer.<\/p><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Team: Sapna Tayal, Harry Ren Our project took the input of wind speed through a wind sensor and converted that to linear motion through a rack and pinion&#8230;<\/p>\n","protected":false},"author":36,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"video","meta":[],"categories":[86],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-json\/wp\/v2\/posts\/17164"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-json\/wp\/v2\/users\/36"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-json\/wp\/v2\/comments?post=17164"}],"version-history":[{"count":18,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-json\/wp\/v2\/posts\/17164\/revisions"}],"predecessor-version":[{"id":17545,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-json\/wp\/v2\/posts\/17164\/revisions\/17545"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-json\/wp\/v2\/media?parent=17164"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-json\/wp\/v2\/categories?post=17164"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2023\/work\/wp-json\/wp\/v2\/tags?post=17164"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}