{"id":14979,"date":"2022-02-13T11:10:11","date_gmt":"2022-02-13T16:10:11","guid":{"rendered":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/?p=14979"},"modified":"2022-02-14T11:58:36","modified_gmt":"2022-02-14T16:58:36","slug":"double-transducer-rotational-speed-to-magnetic-field-strength","status":"publish","type":"post","link":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/double-transducer-rotational-speed-to-magnetic-field-strength\/","title":{"rendered":"Double Transducer: Rotational Speed to Magnetic Field Strength"},"content":{"rendered":"<h1><\/h1>\n<p>&nbsp;<\/p>\n<div id=\"attachment_15026\" style=\"width: 2195px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-15026\" loading=\"lazy\" class=\"wp-image-15026 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1052-scaled.jpg\" alt=\"Sid's Double Transducer\" width=\"2185\" height=\"2560\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1052-scaled.jpg 2185w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1052-256x300.jpg 256w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1052-874x1024.jpg 874w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1052-768x900.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1052-1311x1536.jpg 1311w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1052-1748x2048.jpg 1748w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1052-973x1140.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1052-508x595.jpg 508w\" sizes=\"(max-width: 2185px) 100vw, 2185px\" \/><p id=\"caption-attachment-15026\" class=\"wp-caption-text\">Sid&#8217;s Double Transducer<\/p><\/div>\n<div id=\"attachment_15028\" style=\"width: 2570px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-15028\" loading=\"lazy\" class=\"wp-image-15028 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1050-1-scaled.jpg\" alt=\"Andy's double transducer\" width=\"2560\" height=\"2388\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1050-1-scaled.jpg 2560w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1050-1-300x280.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1050-1-1024x955.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1050-1-768x716.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1050-1-1536x1433.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1050-1-2048x1911.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1050-1-973x908.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1050-1-508x474.jpg 508w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><p id=\"caption-attachment-15028\" class=\"wp-caption-text\">Andy&#8217;s Double Transducer<\/p><\/div>\n<div id=\"attachment_15029\" style=\"width: 2011px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-15029\" loading=\"lazy\" class=\"wp-image-15029 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1056-scaled.jpg\" alt=\"A 3D printed part for the stepper motor\" width=\"2001\" height=\"2560\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1056-scaled.jpg 2001w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1056-235x300.jpg 235w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1056-800x1024.jpg 800w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1056-768x982.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1056-1201x1536.jpg 1201w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1056-1601x2048.jpg 1601w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1056-973x1245.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1056-508x650.jpg 508w\" sizes=\"(max-width: 2001px) 100vw, 2001px\" \/><p id=\"caption-attachment-15029\" class=\"wp-caption-text\">3D printed spindle that reels up a string that is attached to a magnet.<\/p><\/div>\n<div id=\"attachment_15031\" style=\"width: 2570px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-15031\" loading=\"lazy\" class=\"size-full wp-image-15031\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1058-scaled.jpg\" alt=\"A protoboard with IR sensor attached to the right and a popsicle stick attached to a servo motor to the left.\" width=\"2560\" height=\"2357\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1058-scaled.jpg 2560w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1058-300x276.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1058-1024x943.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1058-768x707.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1058-1536x1414.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1058-2048x1885.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1058-973x896.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1058-508x468.jpg 508w\" sizes=\"(max-width: 2560px) 100vw, 2560px\" \/><p id=\"caption-attachment-15031\" class=\"wp-caption-text\">The IR sensor detects the movement in the servo motor and sends a signal to the Arduino.<\/p><\/div>\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-14979-1\" width=\"620\" height=\"1102\" preload=\"metadata\" controls=\"controls\"><source type=\"video\/mp4\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1054.mp4?_=1\" \/><a href=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1054.mp4\">https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1054.mp4<\/a><\/video><\/div>\n<h3><\/h3>\n<h3>Narrative Description<\/h3>\n<p><span style=\"font-weight: 400\">The double transducer receives input in the form of rotational speed and the final output is magnetic field strength. The intermediate output is an angular movement that alters the strength of the magnetic field. We measure rotational speed through a rotary encoder by calculating the number of rotations per second. This is communicated to the Arduino and used to calculate the degree of motion of a servo motor that moves within 20 degrees. The motion is observed by an IR Proximity Sensor which provides the input for a stepper motor to raise and drop a magnet with a string attached to a 3D printed spindle, therefore altering the magnetic field strength.<\/span><\/p>\n<h3>Discussion<\/h3>\n<p>This project has been eye-opening to the world of Arduino and hardware for both of us. The ideation stage was largely based on our individual creativity. Initially, for one of the plans, we thought about incorporating a mounted sensor on wheels to alter the distance as an intermediary step, but given the limited duration and our lack of technical awareness, we switched to a better alternative in the form of the servo motor. We also first thought about using a wire coil to change the magnetic field strength; however, Professor Zacharias informed us of the difficulty in that task and we had to find an alternative. We eventually landed on the idea of using a 3D printed spindle locked into a stepper motor with a string glued onto the spindle to raise and lower a magnetic which worked just as planned in the final demonstration.<\/p>\n<p>It took the combined efforts to create a workable prototype in time for the final deadline. We hit a lot of roadblocks while building the prototype. The unfamiliarity of the potential applications of various hardware slowed us down as we were experimenting with different motors and sensors. However, the guidance we received from professor Zacharias, TA Eric, and the online sources allowed us to meet project deliverables in time.<\/p>\n<p>There were a lot of problems we faced when we built out our individual prototypes especially with soldering and the wire connections to the respective sensors\/motors. We tried to solder most of the wiring into one protoboard, however, one of the boards ended up short-circuiting the Arduino and sensor due to the lack of scrutiny. It was frustrating as it was a day before the deadline and everything just went horribly wrong. The Arduino did not work in the first run and the IR proximity sensor was short-circuited on the second try. It made us realize the importance of starting early and scheduling the process for managing the workload. Additionally, we understood the significance of proper documentation and schematics and careful inspection before soldering which would have avoided all these problems. Besides the technical implementation, we had issues identifying the right ranges for the input\/output from the sensor to the motor. Initially, through trial and error, we used constants and equations to convert the IR proximity input to control the stepper motor. Nevertheless, the professor recommended using the map function in C, to control the stepper which streamlined the code and the implementation efficiently. Now looking back at the project, we could have used a calibration system similar to one that was used by some of our classmates to determine the range after the Arduino just starts up.<\/p>\n<p>Despite all these issues and unfamiliarity, we were able to develop our individual projects by the deadline which worked in tandem with all the other projects on the presentation day.<\/p>\n<div id=\"attachment_14991\" style=\"width: 1549px\" class=\"wp-caption alignnone\"><img aria-describedby=\"caption-attachment-14991\" loading=\"lazy\" class=\"wp-image-14991 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1015.jpg\" alt=\"A protoboard with a faulty circuit soldered onto it which led to short-circuiting.\" width=\"1539\" height=\"1956\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1015.jpg 1539w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1015-236x300.jpg 236w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1015-806x1024.jpg 806w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1015-768x976.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1015-1209x1536.jpg 1209w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1015-973x1237.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1015-508x646.jpg 508w\" sizes=\"(max-width: 1539px) 100vw, 1539px\" \/><p id=\"caption-attachment-14991\" class=\"wp-caption-text\">The three red power wires on the left side were misplaced which caused the IR emitter and the Arduino to shortcircuit.<\/p><\/div>\n<p>&nbsp;<\/p>\n<div id=\"attachment_14993\" style=\"width: 1522px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-14993\" loading=\"lazy\" class=\"wp-image-14993 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1005.jpg\" alt=\"A misaligned screw terminal that was not noticed during the soldering process\" width=\"1512\" height=\"2095\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1005.jpg 1512w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1005-217x300.jpg 217w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1005-739x1024.jpg 739w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1005-768x1064.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1005-1109x1536.jpg 1109w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1005-1478x2048.jpg 1478w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1005-973x1348.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1005-508x704.jpg 508w\" sizes=\"(max-width: 1512px) 100vw, 1512px\" \/><p id=\"caption-attachment-14993\" class=\"wp-caption-text\">In a rush, I (Andy) misaligned a screw terminal during the soldering process and couldn&#8217;t take out the terminal after realizing the mistake.<\/p><\/div>\n<div id=\"attachment_14996\" style=\"width: 2307px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-14996\" loading=\"lazy\" class=\"wp-image-14996 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1012-scaled-e1644806079733.jpg\" alt=\"Picture of the prototype right before Andy shortcuited the IR sensor, Arduino, and the LCD display.\" width=\"2297\" height=\"1516\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1012-scaled-e1644806079733.jpg 2297w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1012-scaled-e1644806079733-300x198.jpg 300w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1012-scaled-e1644806079733-1024x676.jpg 1024w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1012-scaled-e1644806079733-768x507.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1012-scaled-e1644806079733-1536x1014.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1012-scaled-e1644806079733-2048x1352.jpg 2048w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1012-scaled-e1644806079733-973x642.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1012-scaled-e1644806079733-508x335.jpg 508w\" sizes=\"(max-width: 2297px) 100vw, 2297px\" \/><p id=\"caption-attachment-14996\" class=\"wp-caption-text\">Picture of the prototype right before Andy short-circuited the IR sensor, Arduino, and the LCD display.<\/p><\/div>\n<div id=\"attachment_14997\" style=\"width: 1930px\" class=\"wp-caption aligncenter\"><img aria-describedby=\"caption-attachment-14997\" loading=\"lazy\" class=\"wp-image-14997 size-full\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1004-scaled.jpg\" alt=\"\" width=\"1920\" height=\"2560\" srcset=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1004-scaled.jpg 1920w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1004-225x300.jpg 225w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1004-768x1024.jpg 768w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1004-1152x1536.jpg 1152w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1004-1536x2048.jpg 1536w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1004-973x1297.jpg 973w, https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/IMG_1004-508x677.jpg 508w\" sizes=\"(max-width: 1920px) 100vw, 1920px\" \/><p id=\"caption-attachment-14997\" class=\"wp-caption-text\">Our first working prototype with all the components together.<\/p><\/div>\n<h3>Functional Block Diagram<\/h3>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-14985\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/P1-Schematic-and-block.drawio-2.svg\" alt=\"\" width=\"1447\" height=\"608\" \/><\/p>\n<h3>Electrical Schematic<\/h3>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-14986\" src=\"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-content\/uploads\/2022\/02\/P1-Schematic-and-block.drawio-1.svg\" alt=\"\" width=\"1183\" height=\"1151\" \/><\/p>\n<h3>Code<\/h3>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">\/*Project Title: Double Transducer: Rotational Speed to Magnetic Field Strength\r\n  Team Members: Siddharth Parthiban, Weiwen (Andy) Jiang\r\n  Description: Rotary encoder sends input to arduino to calculate rotational speed. \r\n             Based on input between the ranges of 20 and 60 rotations per second, the servo motor\r\n             is shifted to \u00b1 10 degrees from 90 degrees.\r\n             IR proximity sensor reads the change in motion and sends output to arduino.\r\n             The input from IR proximity sensor is mapped to the input for the stepper motor. \r\n             The stepper motor changes the height of the magnet based on the input. \r\n  Pin mapping:\r\n    Arduino pin | role   | description\r\n    ------------|--------|-------------\r\n    A0            input     IR proximity sensor\r\n    2             input     rotary encoder pin A\r\n    3             input     rotary encoder pin B\r\n    4             output    Stepper Motor\r\n    5             output    Stepper Motor\r\n    8             output    Servo motor \r\n    SCL                     SCL of LCD\r\n    SDA                     SDA of LCD\r\n  Rotoray Encoder Code adapted from https:\/\/dronebotworkshop.com\/rotary-encoders-arduino\/#Arduino_Motor_Encoder_Sketch DroneBot Workshop 2019\r\n*\/\r\n\r\n#include &lt;Servo.h&gt;\r\n#include &lt;Encoder.h&gt;\r\n# include &lt;AccelStepper.h&gt;\r\n#include &lt;Wire.h&gt;\r\n#include &lt;LiquidCrystal_I2C.h&gt;\r\n\r\n\/\/Initialising time and position variables\r\nunsigned long prevTime = 0;\r\nunsigned long prevMotorTime = 0;\r\nunsigned long prevServoTime = 0;\r\nunsigned\u00a0long\u00a0oldTimeDisplay\u00a0=\u00a00;\r\nunsigned\u00a0long\u00a0prevIRTime;\r\n\r\n\/\/Initialising other variables\r\nlong oldPosition  = 0;\r\nfloat rotatSpeed;\r\nfloat rotations;\r\nfloat prevRotation = 0;\r\nint\u00a0pos\u00a0=\u00a0800;\r\nint prevIRVal = 0;\r\nint\u00a0servoDegree\u00a0=\u00a090;\r\nint newDistance = 0, oldDistance = 0;\r\nint changeCheckNew = 0, changeCheckOld = 0;\r\nint\u00a0irVal\u00a0=\u00a00;\r\n\r\n\r\n\/\/Initialising pin ports for Arduino\r\nconst int DOORMOTORPIN = 8;\r\nconst int STEP_PIN = 4;\r\nconst int DIR_PIN = 5;\r\nconst\u00a0int\u00a0INFRAREDPIN\u00a0=\u00a0A0;\r\n\r\n\/\/Constant for Rotary Encoder to Servo motor\r\nconst int encodToDegree = 20 \/ 1800;\r\n\r\n\/\/Making servo and stepper objects\r\nAccelStepper myMotor(1, STEP_PIN, DIR_PIN);\r\nEncoder\u00a0myEnc(2,\u00a03);\r\nServo doorMotor;\u00a0\r\nint motorPOS;\r\nint MotorCur;\r\n\r\n\r\nLiquidCrystal_I2C screen(0x27, 16, 2); \/\/Declaring LCD screen object\r\n\r\nvoid setup() {\r\n  Serial.begin(9600); \/\/setting data rate\r\n  doorMotor.attach(DOORMOTORPIN); \/\/declaring pin for servo motor\r\n  \r\n  \/\/Setting up servo motor\r\n  doorMotor.write(servoDegree); \r\n  pinMode(INFRAREDPIN, INPUT);\r\n  \r\n  \/\/Setting up Stepper motor\r\n  myMotor.setMaxSpeed(1000);\r\n  myMotor.setAcceleration(500);\r\n\r\n  \/\/Setting up LCD screen\r\n  screen.init();\r\n  screen.backlight();\r\n  screen.home();\r\n}\r\n\r\nvoid loop() {\r\n  rotations = myEnc.read(); \/\/read rotary encoder input\r\n\r\n  \/\/Calculate rotational speed for every second\r\n  if ((millis() - prevTime ) &gt;= 1000) {\r\n    prevTime = millis();\r\n    rotatSpeed = ((rotations - prevRotation) \/ 80) * 60;\r\n    prevRotation = rotations;\r\n  }\r\n\r\n  \/\/Move servo motor based on rotational speed for every second\r\n  if (( millis() - prevServoTime) &gt;= 1000){\r\n    prevServoTime = millis();\r\n    if ((0 &lt;= abs(rotatSpeed)) &amp;&amp; (abs(rotatSpeed) &lt;= 60)) {\r\n      if (rotatSpeed &gt; 0) {\r\n        servoDegree = 90 + ((rotatSpeed) * 0.1667);\r\n        doorMotor.write(servoDegree);\r\n      } else {\r\n        servoDegree = 90 - ((rotatSpeed) * 0.1667);\r\n        doorMotor.write(servoDegree);\r\n      }\r\n    }\r\n  }\r\n  \r\n  \/\/Read IR proximity sensor input for every 1\/2 second\r\n  if ((millis() - prevIRTime) &gt;= 500) {\r\n    prevIRTime = millis();\r\n    irVal = analogRead(INFRAREDPIN);\r\n  }\r\n\r\n  \/\/Move Stepper motor based on input from IR proximity sensor every second\r\n  if ((millis() - prevMotorTime ) &gt;= 1000) {\r\n    prevMotorTime = millis();\r\n    motorPOS = map(irVal, 200, 350, 0, 5000);\r\n    myMotor.moveTo(motorPOS);\r\n    myMotor.run();\r\n    MotorCur = myMotor.currentPosition() \/ 200;\r\n  }\r\n  myMotor.run(); \/\/ run Stepper motor\r\n\r\n  \/\/Display values to LCD screen\r\n  if (millis() - oldTimeDisplay &gt;= 250) {\r\n    oldTimeDisplay = millis();\r\n    screen.clear();\r\n    screen.setCursor(0, 0);\r\n    screen.print(\"i: \" + (String) (int)rotatSpeed);\r\n    screen.setCursor(7, 0);\r\n    screen.print(\"m:\" + (String) (int)servoDegree);\r\n    screen.setCursor(7, 1);\r\n    screen.print (irVal);\r\n    screen.setCursor(11, 1);\r\n    screen.print(\"o: \" + (String) MotorCur);\r\n  }\r\n\r\n}<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; Narrative Description The double transducer receives input in the form of rotational speed and the final output is magnetic field strength. The intermediate output is an angular&#8230;<\/p>\n","protected":false},"author":206,"featured_media":15025,"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\/s2022\/work\/wp-json\/wp\/v2\/posts\/14979"}],"collection":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-json\/wp\/v2\/users\/206"}],"replies":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-json\/wp\/v2\/comments?post=14979"}],"version-history":[{"count":11,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-json\/wp\/v2\/posts\/14979\/revisions"}],"predecessor-version":[{"id":15041,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-json\/wp\/v2\/posts\/14979\/revisions\/15041"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-json\/wp\/v2\/media\/15025"}],"wp:attachment":[{"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-json\/wp\/v2\/media?parent=14979"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-json\/wp\/v2\/categories?post=14979"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/courses.ideate.cmu.edu\/60-223\/s2022\/work\/wp-json\/wp\/v2\/tags?post=14979"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}