{"id":12315,"date":"2021-03-10T04:02:08","date_gmt":"2021-03-10T09:02:08","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/?p=12315"},"modified":"2021-03-10T04:02:08","modified_gmt":"2021-03-10T09:02:08","slug":"double-transducer-distance-pressure","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/double-transducer-distance-pressure\/","title":{"rendered":"Double Transducer | Distance -&gt; Pressure"},"content":{"rendered":"\r\n<div id=\"attachment_12600\" style=\"width: 1930px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-12600\" loading=\"lazy\" class=\"wp-image-12600 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-scaled.jpg\" alt=\"Feature Image\" width=\"1920\" height=\"2560\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-scaled.jpg 1920w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-508x677.jpg 508w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><p id=\"caption-attachment-12600\" class=\"wp-caption-text\">Distance to pressure double transducer.<\/p><\/div>\r\n<div class=\"mceTemp\">\u00a0<\/div>\r\n<h2>Double Transducer IRL:<\/h2>\r\n<h3>Daniel Zhu:<\/h3>\r\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-12315-1\" width=\"620\" height=\"349\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/double-transducer.mp4?_=1\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/double-transducer.mp4\">https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/double-transducer.mp4<\/a><\/video><\/div>\r\n<h3>Sunjana:<\/h3>\r\n<div style=\"width: 620px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-12315-2\" width=\"620\" height=\"349\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1171.mp4?_=2\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1171.mp4\">https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1171.mp4<\/a><\/video><\/div>\r\n<p>&nbsp;<\/p>\r\n<h2>TinkerCAD:<\/h2>\r\n<div style=\"width: 620px;\" class=\"wp-video\"><video class=\"wp-video-shortcode\" id=\"video-12315-3\" width=\"620\" height=\"349\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Tinekercad.mp4?_=3\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Tinekercad.mp4\">https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Tinekercad.mp4<\/a><\/video><\/div>\r\n<h2><strong>Final Project Images:<\/strong><\/h2>\r\n<h3>Daniel Zhu:<\/h3>\r\n<div id=\"attachment_12600\" style=\"width: 1930px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12600\" loading=\"lazy\" class=\"wp-image-12600 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-scaled.jpg\" alt=\"Featured Image\" width=\"1920\" height=\"2560\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-scaled.jpg 1920w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Cover-Image-508x677.jpg 508w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><p id=\"caption-attachment-12600\" class=\"wp-caption-text\">Distance to Pressure Double Transducer &#8211; Daniel Zhu<\/p><\/div>\r\n<h3>Sunjana:<\/h3>\r\n<h2><img loading=\"lazy\" class=\"alignnone size-full wp-image-12635\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG-1172-scaled.jpg\" alt=\"\" width=\"2560\" height=\"1920\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG-1172-scaled.jpg 2560w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG-1172-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG-1172-1024x768.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG-1172-768x576.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG-1172-1536x1152.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG-1172-2048x1536.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG-1172-973x730.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG-1172-508x381.jpg 508w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><\/h2>\r\n<h2><strong>Close Up Images<\/strong><\/h2>\r\n<div id=\"attachment_12628\" style=\"width: 390px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12628\" loading=\"lazy\" class=\"wp-image-12628 \" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1164.jpg\" alt=\"\" width=\"380\" height=\"285\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1164.jpg 640w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1164-300x225.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1164-508x381.jpg 508w\" sizes=\"(max-width: 380px) 100vw, 380px\" \/><p id=\"caption-attachment-12628\" class=\"wp-caption-text\">Close up of the method servo used to apply pressure to the paper<\/p><\/div>\r\n<div id=\"attachment_12629\" style=\"width: 412px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12629\" loading=\"lazy\" class=\"wp-image-12629 \" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1165.jpg\" alt=\"\" width=\"402\" height=\"332\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1165.jpg 640w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1165-300x248.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_1165-508x420.jpg 508w\" sizes=\"(max-width: 402px) 100vw, 402px\" \/><p id=\"caption-attachment-12629\" class=\"wp-caption-text\">Close up of servo in position to press the lever switch intermittently when its shaft is turned programmatically<\/p><\/div>\r\n<h2><br \/>Simple Narrative Description:<\/h2>\r\n<p><span style=\"font-weight: 400\">As the distance between the Ultrasonic Distance Sensor and an object decreases, the rate at which a servo motor presses a lever switch increases. As the lever switch registers a faster and faster rate of being triggered, a second servo motor presses a stack of cardboard more closely to the table, applying more pressure. Conversely, as the distance between the Ultrasonic Distance Sensor and an object increases, the rate at which a servo motor presses a lever switch decreases. As the lever switch registers slower rate of being triggered, a second servo motor presses a stack of cardboard less closely to the table, relieving pressure.\u00a0<\/span><\/p>\r\n<h2>Progress Images:<\/h2>\r\n<h3>Daniel Zhu:<\/h3>\r\n<p><img loading=\"lazy\" class=\"alignnone wp-image-12613 size-medium\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_0936-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_0936-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_0936-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_0936-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_0936-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_0936-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_0936-508x677.jpg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_0936-scaled.jpg 1920w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><\/p>\r\n<div id=\"attachment_12614\" style=\"width: 179px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12614\" loading=\"lazy\" class=\"wp-image-12614 size-medium\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_003BF81977FA-1-169x300.jpeg\" alt=\"\" width=\"169\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_003BF81977FA-1-169x300.jpeg 169w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_003BF81977FA-1-576x1024.jpeg 576w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_003BF81977FA-1-508x904.jpeg 508w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/IMG_003BF81977FA-1.jpeg 750w\" sizes=\"(max-width: 169px) 100vw, 169px\" \/><p id=\"caption-attachment-12614\" class=\"wp-caption-text\">Noise in Ultrasonic Distance sensor data.<\/p><\/div>\r\n<h3>Sunjana:<\/h3>\r\n<div id=\"attachment_12616\" style=\"width: 235px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12616\" loading=\"lazy\" class=\"size-medium wp-image-12616\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/158128857_281225156733647_2301680018762961481_n-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/158128857_281225156733647_2301680018762961481_n-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/158128857_281225156733647_2301680018762961481_n.jpg 302w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><p id=\"caption-attachment-12616\" class=\"wp-caption-text\">Converting rotational motion into pressure<\/p><\/div>\r\n<div id=\"attachment_12617\" style=\"width: 235px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12617\" loading=\"lazy\" class=\"size-medium wp-image-12617\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/158824553_162565129032385_3002268511541311449_n-225x300.jpg\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/158824553_162565129032385_3002268511541311449_n-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/158824553_162565129032385_3002268511541311449_n.jpg 302w\" sizes=\"(max-width: 225px) 100vw, 225px\" \/><p id=\"caption-attachment-12617\" class=\"wp-caption-text\">Unsoldered prototype<\/p><\/div>\r\n<h2><strong>Discussion:<\/strong><\/h2>\r\n<p><span style=\"font-weight: 400\">This project introduced numerous physical, coding, and conceptual difficulties. Conceptually, it was difficult for us to come up with an idea to convert distance into pressure: while we had spent a lot of time working with light as a medium (LEDs) and movement, we hadn\u2019t ever worked with any electrical components that had a specific function of exerting pressure. After speaking with the professor, we learned that in order to exert pressure, we could take inspiration from a crank that used a circular turning motion to push and pull an object. We then decided upon the idea of our second transducer outputting an angle change for a motor so it could turn like a crank and push and pull an object we created. The object in turn would apply pressure to a piece of paper as it was being pushed.\u00a0<\/span><\/p>\r\n<p><span style=\"font-weight: 400\">Physically, our challenge lay in orienting the different components of the machine (i.e. the servos and the button) so that they would form a chain reaction (i.e. a servo pressing a button intermittently, causing the other servo to intermittently apply pressure to a piece of paper). It took some trial and error to figure out which button was most responsive to the servo\u2019s touch, as well as whether a servo or stepper motor was better suited to our task. It became too technically difficult for us to implement the crank with the stepper motor providing the circular turning motion, like we had originally intended, so we ended up going with the servo. In the future, we would want to be able to utilize the stepper motor as it would allow for more creativity in our output, since it turns 360 degrees.\u00a0<\/span><\/p>\r\n<p><span style=\"font-weight: 400\">Coding-wise, our challenge lay in figuring out the relationship between the first servo, the button, and the second servo, and how to pass information through each of these components. Specifically, we had to figure out how to convert the digital intermittent pressing of the button into an analog angle for the second servo. This also took a lot of debugging and trial and error, as we didn\u2019t immediately know which angles of the servo were most optimal for pressing on the paper, and we didn\u2019t know how we could change the angles such that the servo would be intermittently pressing down and intermittently going back up based on the button-pressing speed of the first servo.\u00a0<\/span><\/p>\r\n<p><span style=\"font-weight: 400\">Even though this project was extremely difficult, since we were relative Arduino beginners, we were able to go far out of our comfort zone and learn to put together various moving parts, as well as how to convert an analog signal to a digital signal and back to an analog signal.\u00a0<\/span><\/p>\r\n<h2>Diagrams:<\/h2>\r\n<h3><strong>Block Diagram:<\/strong><\/h3>\r\n<div id=\"attachment_12598\" style=\"width: 1142px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12598\" loading=\"lazy\" class=\"wp-image-12598 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Block-Diagram-scaled-e1615354422318.jpg\" alt=\"Block Diagram\" width=\"1132\" height=\"614\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Block-Diagram-scaled-e1615354422318.jpg 1132w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Block-Diagram-scaled-e1615354422318-300x163.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Block-Diagram-scaled-e1615354422318-1024x555.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Block-Diagram-scaled-e1615354422318-768x417.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Block-Diagram-scaled-e1615354422318-973x528.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Block-Diagram-scaled-e1615354422318-508x276.jpg 508w\" sizes=\"(max-width: 1132px) 100vw, 1132px\" \/><p id=\"caption-attachment-12598\" class=\"wp-caption-text\">Block Diagram<\/p><\/div>\r\n<h3><strong>Schematic Diagram:<\/strong><\/h3>\r\n<div id=\"attachment_12599\" style=\"width: 963px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-12599\" loading=\"lazy\" class=\"wp-image-12599 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Schematic-Diagram-scaled-e1615354455214.jpeg\" alt=\"Schematic Diagram\" width=\"953\" height=\"1395\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Schematic-Diagram-scaled-e1615354455214.jpeg 953w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Schematic-Diagram-scaled-e1615354455214-205x300.jpeg 205w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Schematic-Diagram-scaled-e1615354455214-700x1024.jpeg 700w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Schematic-Diagram-scaled-e1615354455214-768x1124.jpeg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-content\/uploads\/2021\/03\/Schematic-Diagram-scaled-e1615354455214-508x744.jpeg 508w\" sizes=\"(max-width: 953px) 100vw, 953px\" \/><p id=\"caption-attachment-12599\" class=\"wp-caption-text\">Schematic Diagram<\/p><\/div>\r\n<h2>Code:<\/h2>\r\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"c\">\/*\r\n   60-223, Project 1: Double Transducer\r\n   Daniel Zhu (dszhu)\r\n   time spent: 6+ hrs\r\n\r\n   Collaboration and sources:\r\n   1) Code for LCD taken from the course website.\r\n   2) Code for Servo Motor take from course website.\r\n\r\n   Challenge(s): A faulty barrel jack charger as well as\r\n   noise in the LCD Display due to it being connected to\r\n   a power source shared by servo motors caused it to display\r\n   egyption hieroglyphics for several hours.\r\n\r\n   Description: As the distance between the Ultrasonic Distance Sensor\r\n   and an object decreases, the rate at which a servo motor presses a\r\n   lever switch increases. As the lever switch registers a faster and\r\n   faster rate of being triggered, a second servo motor presses a stack\r\n   of cardboard more closely to the table, applying more pressure.\r\n\r\n   Pin mapping:\r\n\r\n   Arduino pin | type   | description\r\n   ------------|--------|-------------\r\n   2             output    LCD Display Coding Pin\r\n   3             output    LCD Display Coding Pin\r\n   4             output    LCD Display Coding Pin\r\n   5             output    LCD Display Coding Pin\r\n   6             output    LCD Display E\r\n   7             input     LCD Display RS\r\n   8             output    Output Servo Motor (Pressure)\r\n   9             output    Middle Servo Motor (Morse)\r\n   10            input     Lever Switch Input\r\n   11            output    TRIGGER_PIN - Ultrasonic Distance Sensor\r\n*\/\r\n\r\n#include &lt;Servo.h&gt; \/\/Servo Library\r\n#include &lt;NewPing.h&gt; \/\/Ultrasonic Distance Finder Library\r\n#include &lt;LiquidCrystal.h&gt; \/\/LCD Library\r\n#include &lt;Wire.h&gt; \/\/LCD Library\r\n\r\n\/\/Ultrasonic Distance Sensor Pins\r\nconst int TRIGGER_PIN = 12;  \/\/ Arduino pin tied to trigger pin on the ultrasonic sensor.\r\nconst int ECHO_PIN = 11;  \/\/ Arduino pin tied to echo pin on the ultrasonic sensor.\r\nconst int MAX_DISTANCE = 200; \/\/ Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.\r\nNewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); \/\/Createing a new Sonar object for use.\r\n\r\nconst int SDELAY = 50; \/\/ Minimum amount of delay between sonar pings\r\nlong sTimeSince = 0; \/\/ Time since last sonar ping\r\nint dist = sonar.ping_cm(); \/\/ Keeps track of object distance from sensor\r\n\r\n\/\/Servo Motor Pins\r\nconst int BTN = 10; \/\/ Lever Switch\r\nconst int SERVO_IN = 9; \/\/ Middle Servo\r\nconst int SERVO_OUT = 8; \/\/ Output Servo\r\nServo Morse;\r\nServo Pressure;\r\n\r\nlong mTimeSince = 0; \/\/ Time since Middle Servo Triggered\r\nbool mSwitch = false; \/\/ Keeps track of whether the servo is in the motion of pressing or returning\r\n\r\nlong pTimeSince = 0; \/\/ Time since Output Servo Triggered\r\nint prsRate = 0; \/\/ Lever Switch input press rate\r\n\r\n\/\/LCD Display\r\nconst int rs = 7, en = 6, d4 = 2, d5 = 3, d6 = 4, d7 = 5;\r\nLiquidCrystal lcd(rs, en, d4, d5, d6, d7);\r\n\r\nlong lTimeSince = 0; \/\/Time Since LCD Display was last updated\r\nconst int lcdDelay = 250; \/\/ Minimum time between LCD updates\r\n\r\nvoid setup() {\r\n  pinMode(BTN, INPUT);\r\n  Morse.attach(SERVO_IN);\r\n  Pressure.attach(SERVO_OUT);\r\n  Serial.begin(115200);\r\n  lcd.begin(16, 2);\r\n}\r\n\r\nvoid loop() {\r\n\r\n  if (millis() - sTimeSince &gt; SDELAY) { \/\/ Triggering the Ultrasonic Sensor + Finding the Distance\r\n    dist = sonar.ping_cm();\r\n    sTimeSince = millis();\r\n  }\r\n\r\n  int pause = map(dist, 0, 50, 500, 1000); \/\/ Converts distance into how long the middle servo pauses between presses\r\n\r\n  if (int(millis() - mTimeSince) &gt; pause) { \/\/pressing the middle servo motor\r\n    if (mSwitch == false) { \/\/ Pressing the Lever Switch\r\n      Morse.write(40);\r\n      mSwitch = true;\r\n    }\r\n    else { \/\/ Unpressing the Lever Switch\r\n      Morse.write(45);\r\n      mSwitch = false;\r\n    }\r\n\r\n    prsRate -= 10; \/\/ Automatically Subtracting from the Pressrate of the Lever Switch\r\n    Serial.print(\"Delay: \");\r\n    Serial.println(pause);\r\n    mTimeSince = millis();\r\n  }\r\n\r\n  if (digitalRead(BTN) == 1) { \/\/ Detecting LEvel Switch Input\r\n    prsRate += 20;\r\n  }\r\n\r\n  if (prsRate &gt; 100) { \/\/ Capping the pressrate before its conversion to angle to prevent servo failure\r\n    prsRate = 100;\r\n  }\r\n  if (prsRate &lt; 0) {\r\n    prsRate = 0;\r\n  }\r\n\r\n  int angle = map(prsRate, 0, 100, 30, 20); \/\/ Converting the Pressrate of the Lever Switch to an Angle\r\n  if (millis() - pTimeSince &gt; 500) {\r\n    Pressure.write(angle); \/\/ Moving the output motor to that angle\r\n  }\r\n\r\n  if (int(millis() - lTimeSince) &gt; lcdDelay) { \/\/ LCD Display delay\r\n\r\n    \/\/ Converting Middle values into 0-99 range for LCD\r\n    int input = map(dist, 0, 50, 0, 99);\r\n    int middleA = map(pause, 500, 1000, 0, 99);\r\n    int middleS = map(prsRate, 0, 100, 0, 99);\r\n    int output = map(angle, 20, 30, 0, 99);\r\n\r\n    lcd.setCursor(0, 0);\r\n    lcd.print((String)\"i:\" + input + \" m:\" + middleA);\r\n    lcd.setCursor(8, 2);\r\n    lcd.print((String)middleS + \" o:\" + output);\r\n\r\n    lTimeSince = millis();\r\n  }\r\n}<\/pre>\r\n<p>&nbsp;<\/p>\r\n<p>&nbsp;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>\u00a0 Double Transducer IRL: Daniel Zhu: Sunjana: &nbsp; TinkerCAD: Final Project Images: Daniel Zhu: Sunjana: Close Up Images Simple Narrative Description: As the distance between the Ultrasonic Distance&#8230;<\/p>\n","protected":false},"author":170,"featured_media":12600,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[86,1],"tags":[],"_links":{"self":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts\/12315"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/users\/170"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/comments?post=12315"}],"version-history":[{"count":12,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts\/12315\/revisions"}],"predecessor-version":[{"id":12638,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/posts\/12315\/revisions\/12638"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/media\/12600"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/media?parent=12315"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/categories?post=12315"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2021\/work\/wp-json\/wp\/v2\/tags?post=12315"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}