Photo of the entire project. Magnet switch and magnet on the left, flex sensor and servo in the bottom center, and vibration motor on the right.

The servo and flex sensor mechanism. We extended the arm of the servo to increase the range of motion we bend the flex sensor through.

The transducer in action. A magnet activates the reed switch, which rotates the servo, which flexes the flex sensor, which activates the vibration motor.

Description:

A magnetic switch waits for the presence of a magnet. When the switch is activated, it triggers a motor to spin a lever. The spinning lever twists the flex sensor, which causes it to activate the vibration motor.

Progress:

Testing the US1881 Hall Effect Sensor. We found this sensor to be about as sensitive as the physical reed-switch.

Our first tests of the servo and flex sensor mechanism. We discovered that the values of the flex sensor didn’t cover a very wide range, and were susceptible to noise.

The original vibration motor we chose for our output. The leads proved to be too small to solder easily, so we selected a different motor with larger connections.

Discussion:

We investigated two different methods of detecting a magnetic field for our input: a physical reed switch, and a semiconductor Hall-Effect sensor (US1881). We found both of them to have similar sensitivity, though the Hall-Effect sensor had an interesting latching behavior. Once activated by a magnetic field, it would continue to send an “on” signal until it detected another magnetic field in the other direction. We decided to use the reed switch instead, as it would be simpler for the group providing our input to change the presence of a magnetic field rather than the direction.

Our servo and flex sensor mechanism proved to be an interesting construction challenge. Specifically, we needed a system which could flex the sensor in as wide a range of motion as possible. Because of this, we extended the arm of the servo to rotate over a wider range. We also faced challenges using the flex sensor, from its low range of output values to its fragile design. Specifically, we faced the problem of loose connections on the sensor, as the motion of the system would occasionally pull the sensor pins from the wire plugs they were inserted in. We mostly resolved the connection issue by reconstructing the mechanism with tightly wrapped tape and connections, however the issue of sensitivity remained. To help make our transducer easier to use, we included a calibration dial, to manually determine the set-point at which we consider the sensor flexed. This helped us to avoid making last-minute software changes to adjust the sensor in the case of analog drift.

Our output, a vibration motor proved to be the simplest element of our transducer. We did have some difficulty soldering connections to the part due to its size, however by choosing a different motor, we were able to find one which could be connected to the standard breadboard jumpers. This proved mostly effective until later into in-class testing, when we discovered that the vibration of the motor had managed to loosen its own connections, which we manually reconnected.

Altogether, while our transducer did work as intended, the majority of issues we faced we related to physical problems, rather than electronics or software. Evidently, this shows that the tangible construction of a device can be the limiting factor in terms of its effectiveness. Because of that, we intend to place more attention on the physical layout of our projects in the future to ensure that our electronic and software components can operate without the limitations of poor wiring or construction.

Schematic:

Code:
  1. <span class="com">#include</span><span class="pln"> </span><span class="str"><Servo.h></span><span class="pln">
  2. </span><span class="com">/* Project One
  3. * George Ralph (gdr), Beccy Zheng (rebeccaz)
  4. * 2 hours 30 minutes
  5. *
  6. * Collaboration: Discuss with other groups to coordinate our inputs and outputs.
  7. *
  8. * Challenge: One challenge was attaching the flex sensor to the servo motor.
  9. * The flex sensor pins would get detached and read 0 instead of the actual value.
  10. * Another challenge was getting the vibration motor to work. We originally
  11. * tried to solder another type of motor, but it was too small to make a connection.
  12. * We eventually found a larger motor that was easier to use.
  13. *
  14. * Next time: We will plan ahead for how we will assemble the entire project. This
  15. * includes a better idea of the physical form.
  16. *
  17. * Summary: Magnetic Field -> Flex -> Vibration
  18. *
  19. * We read a magnetic switch and use that value to drive a servo motor. The motor
  20. * twists a flex sensor and we use that reading to control a vibration motor. We also
  21. * have a potentiometer to adjust the threshold of activation we use for the flex sensor.
  22. *
  23. * Inputs:
  24. *
  25. * Arduino Pin | Input
  26. * 2 Magnet
  27. * A0 Flex Sensor
  28. * A1 Potentiometer
  29. *
  30. * Outputs:
  31. *
  32. * Arduino pin | Output
  33. * 3 Servo Motor
  34. * 4 Vibration Motor
  35. */</span><span class="pln">
  36. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> MAGNET_PIN </span><span class="pun">=</span><span class="pln"> </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
  37. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> SERVO_PIN </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">
  38. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> VIBRATION_PIN </span><span class="pun">=</span><span class="pln"> </span><span class="lit">4</span><span class="pun">;</span><span class="pln">
  39. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> FLEX_PIN </span><span class="pun">=</span><span class="pln"> A0</span><span class="pun">;</span><span class="pln">
  40. </span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> POT_PIN </span><span class="pun">=</span><span class="pln"> A1</span><span class="pun">;</span><span class="pln">
  41. </span><span class="typ">Servo</span><span class="pln"> servo</span><span class="pun">;</span><span class="pln">
  42. </span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  43. </span><span class="com">//Initialize servo connection</span><span class="pln">
  44. servo</span><span class="pun">.</span><span class="pln">attach</span><span class="pun">(</span><span class="pln">SERVO_PIN</span><span class="pun">);</span><span class="pln">
  45. </span><span class="com">//Initialize other IO</span><span class="pln">
  46. pinMode</span><span class="pun">(</span><span class="pln">MAGNET_PIN</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  47. pinMode</span><span class="pun">(</span><span class="pln">VIBRATION_PIN</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  48. pinMode</span><span class="pun">(</span><span class="pln">FLEX_PIN</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  49. pinMode</span><span class="pun">(</span><span class="pln">POT_PIN</span><span class="pun">,</span><span class="pln"> INPUT</span><span class="pun">);</span><span class="pln">
  50. </span><span class="com">//Initialize the serial connection</span><span class="pln">
  51. </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">(</span><span class="lit">9600</span><span class="pun">);</span><span class="pln">
  52. </span><span class="pun">}</span><span class="pln">
  53. </span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  54. </span><span class="com">//Check the magnet switch</span><span class="pln">
  55. </span><span class="kwd">bool</span><span class="pln"> magnetState </span><span class="pun">=</span><span class="pln"> digitalRead</span><span class="pun">(</span><span class="pln">MAGNET_PIN</span><span class="pun">);</span><span class="pln">
  56. </span><span class="com">//If the switch is on, move the servo to 90 degrees, otherwise to 0</span><span class="pln">
  57. servo</span><span class="pun">.</span><span class="pln">write</span><span class="pun">(</span><span class="pln">magnetState </span><span class="pun">?</span><span class="pln"> </span><span class="lit">90</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  58. </span><span class="com">//Wait .5s to give the servo time to move</span><span class="pln">
  59. delay</span><span class="pun">(</span><span class="lit">500</span><span class="pun">);</span><span class="pln">
  60. </span><span class="com">//Read the flex sensor and the dial (setpoint)</span><span class="pln">
  61. </span><span class="kwd">int</span><span class="pln"> flexVal </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">FLEX_PIN</span><span class="pun">);</span><span class="pln">
  62. </span><span class="kwd">int</span><span class="pln"> dialVal </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">POT_PIN</span><span class="pun">);</span><span class="pln">
  63. </span><span class="com">//Print both values as debug information</span><span class="pln">
  64. </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="pln">flexVal</span><span class="pun">);</span><span class="pln">
  65. </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"\t"</span><span class="pun">);</span><span class="pln">
  66. </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">dialVal</span><span class="pun">);</span><span class="pln">
  67. </span><span class="com">//If the sensor is above the setpoint, turn on the vibration motor</span><span class="pln">
  68. digitalWrite</span><span class="pun">(</span><span class="pln">VIBRATION_PIN</span><span class="pun">,</span><span class="pln"> flexVal </span><span class="pun">></span><span class="pln"> dialVal</span><span class="pun">);</span><span class="pln">
  69. </span><span class="pun">}</span>
<span class="com">#include</span><span class="pln"> </span><span class="str"><Servo.h></span><span class="pln">

</span><span class="com">/* Project One
 * George Ralph (gdr), Beccy Zheng (rebeccaz)
 * 2 hours 30 minutes
 *
 * Collaboration: Discuss with other groups to coordinate our inputs and outputs.
 * 
 * Challenge: One challenge was attaching the flex sensor to the servo motor.  
 * The flex sensor pins would get detached and read 0 instead of the actual value.
 * Another challenge was getting the vibration motor to work. We originally
 * tried to solder another type of motor, but it was too small to make a connection.
 * We eventually found a larger motor that was easier to use.
 * 
 * Next time: We will plan ahead for how we will assemble the entire project. This
 * includes a better idea of the physical form.
 * 
 * Summary: Magnetic Field -> Flex -> Vibration
 * 
 * We read a magnetic switch and use that value to drive a servo motor. The motor 
 * twists a flex sensor and we use that reading to control a vibration motor. We also
 * have a potentiometer to adjust the threshold of activation we use for the flex sensor.
 * 
 *  Inputs: 
 *  
 *  Arduino Pin | Input
 *     2          Magnet      
 *     A0         Flex Sensor
 *     A1         Potentiometer
 *  
 *  Outputs:
 *  
 *  Arduino pin | Output
 *      3         Servo Motor
 *      4         Vibration Motor
 */</span><span class="pln">

</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> MAGNET_PIN    </span><span class="pun">=</span><span class="pln"> </span><span class="lit">2</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> SERVO_PIN     </span><span class="pun">=</span><span class="pln"> </span><span class="lit">3</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> VIBRATION_PIN </span><span class="pun">=</span><span class="pln"> </span><span class="lit">4</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> FLEX_PIN      </span><span class="pun">=</span><span class="pln"> A0</span><span class="pun">;</span><span class="pln">
</span><span class="kwd">const</span><span class="pln"> </span><span class="kwd">int</span><span class="pln"> POT_PIN       </span><span class="pun">=</span><span class="pln"> A1</span><span class="pun">;</span><span class="pln">

</span><span class="typ">Servo</span><span class="pln"> servo</span><span class="pun">;</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> setup</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="com">//Initialize servo connection</span><span class="pln">
  servo</span><span class="pun">.</span><span class="pln">attach</span><span class="pun">(</span><span class="pln">SERVO_PIN</span><span class="pun">);</span><span class="pln">

  </span><span class="com">//Initialize other IO</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">MAGNET_PIN</span><span class="pun">,</span><span class="pln">     INPUT</span><span class="pun">);</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">VIBRATION_PIN</span><span class="pun">,</span><span class="pln"> OUTPUT</span><span class="pun">);</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">FLEX_PIN</span><span class="pun">,</span><span class="pln">       INPUT</span><span class="pun">);</span><span class="pln">
  pinMode</span><span class="pun">(</span><span class="pln">POT_PIN</span><span class="pun">,</span><span class="pln">        INPUT</span><span class="pun">);</span><span class="pln">

  </span><span class="com">//Initialize the serial connection</span><span class="pln">
  </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">begin</span><span class="pun">(</span><span class="lit">9600</span><span class="pun">);</span><span class="pln">
</span><span class="pun">}</span><span class="pln">

</span><span class="kwd">void</span><span class="pln"> loop</span><span class="pun">()</span><span class="pln"> </span><span class="pun">{</span><span class="pln">
  </span><span class="com">//Check the magnet switch</span><span class="pln">
  </span><span class="kwd">bool</span><span class="pln"> magnetState </span><span class="pun">=</span><span class="pln"> digitalRead</span><span class="pun">(</span><span class="pln">MAGNET_PIN</span><span class="pun">);</span><span class="pln">

  </span><span class="com">//If the switch is on, move the servo to 90 degrees, otherwise to 0</span><span class="pln">
  servo</span><span class="pun">.</span><span class="pln">write</span><span class="pun">(</span><span class="pln">magnetState </span><span class="pun">?</span><span class="pln"> </span><span class="lit">90</span><span class="pln"> </span><span class="pun">:</span><span class="pln"> </span><span class="lit">0</span><span class="pun">);</span><span class="pln">
  </span><span class="com">//Wait .5s to give the servo time to move</span><span class="pln">
  delay</span><span class="pun">(</span><span class="lit">500</span><span class="pun">);</span><span class="pln">

  </span><span class="com">//Read the flex sensor and the dial (setpoint)</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> flexVal </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">FLEX_PIN</span><span class="pun">);</span><span class="pln">
  </span><span class="kwd">int</span><span class="pln"> dialVal </span><span class="pun">=</span><span class="pln"> analogRead</span><span class="pun">(</span><span class="pln">POT_PIN</span><span class="pun">);</span><span class="pln">

  </span><span class="com">//Print both values as debug information</span><span class="pln">
  </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="pln">flexVal</span><span class="pun">);</span><span class="pln">
  </span><span class="typ">Serial</span><span class="pun">.</span><span class="kwd">print</span><span class="pun">(</span><span class="str">"\t"</span><span class="pun">);</span><span class="pln">
  </span><span class="typ">Serial</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">dialVal</span><span class="pun">);</span><span class="pln">

  </span><span class="com">//If the sensor is above the setpoint, turn on the vibration motor</span><span class="pln">
  digitalWrite</span><span class="pun">(</span><span class="pln">VIBRATION_PIN</span><span class="pun">,</span><span class="pln"> flexVal </span><span class="pun">></span><span class="pln"> dialVal</span><span class="pun">);</span><span class="pln">
  
</span><span class="pun">}</span>