Exercise: Servo Metronome

This exercise is chiefly an introduction to physical prototyping. It assumes you have Tinkercad simulation experience with the Arduino, the hobby servo, and potentiometer circuits, and are now ready to integrate this knowledge using physical components.

Objectives

After this exercise, you should be able to:

  1. Use a solderless breadboard to construct a potentiometer circuit.

  2. Read and process and analog input as a user input.

  3. Control a hobby servomotor module.

  4. Create a timed pattern of movement using the Arduino Servo library.

  5. Use the serial port output for debugging.

Reference Guides

Please review the following reference guides as needed:

Warnings

You will likely be using the Arduino as the power supply for this exercise, meaning your computer will be supplying servo power. USB ports have limits on current and most computers will reliably shut down the port if the power draw is too high. But to avoid any possible problems, please observe the following.

  1. Please only rest the Arduino on a non-conductive surface. It has exposed metal on the back which can short-circuit.

  2. Please generally refrain from touching the exposed electrical connections with your fingers. There are no dangerous voltages, but electronics can be damaged from static charges on your body.

  3. Please limit any circuits supplied by USB power to only one micro-servo. For multiple micro-servos or DC motors, please use the external 5V power supply in your kit.

  4. Please perform all wiring changes with the USB cable detached and the Arduino unpowered.

  5. Please carefully observe breadboard wiring discipline, double-checking all jumper wire locations.

  6. The most common errors are off-by-one insertions of a jumper wire into a position adjacent to the desired tie point. For this reason, I recommend not using the busses +/- as marked, but instead keeping the +5V and ground busses widely separated.

  7. If in the future you use +12V, please keep the higher voltages carefully isolated and triple-check all wiring. Students have damaged laptops in the past by inadvertently shorting +12V signals into the Arduino pins; please avoid this expensive mistake.

Steps and observations

The overall objective is to create a metronome using a repetitive servo movement with a user-controllable tempo.

  1. Please construct a physical breadboard circuit with the required minimum components: an Arduino, solderless breadboard, a potentiometer wired to an analog input, and a micro hobby servo wired to a digital output.

  2. Please make sure you have an up-to-date installation of the current Arduino software system (the IDE).

  3. Please write an Arduino program which implements a user-controlled metronome. At minimum, this will include:

    1. importing the Servo library

    2. declaring a Servo object

    3. attaching the Servo object to a hardware pin

    4. initializing the Serial port for debugging

    5. reading the potentiometer signal using an analog input

    6. translating the raw analog input to appropriately scaled timing values using map() or equivalent expressions

    7. issuing write commands to the servo

    8. regulating time using delay() or millis()

  4. Please make sure the metronome produces a useful movement for every potentiometer position.

  5. Please make sure the metronome varies over a useful tempo range. For reference, a traditional mechanical metronome typically provides tempos from 40 to 208 beats per minute (BPM).

  6. Please record a brief (~20 second) video demonstrating the operation of the device.

  7. Please test using the serial output for debugging using the Serial Monitor in the Arduino IDE. You may need to set the baud rate in the monitor to match your code.

  8. Please be sure to apply Auto Format from the Tools menu to your code before submission to make sure it is consistently indented.

Deliverables

The result of your explorations should include the following three Canvas file submissions:

  1. a brief video (~20 seconds) demonstrating operation over a range of inputs

  2. your Arduino sketch uploaded as a single .ino file

  3. a brief paragraph describing any problems you encountered, submitted as a text file

Challenges

If you would like to explore more, please consider the following optional challenge questions.

  1. Try creating a smoothly controlled trajectory instead of step commands.

  2. Try adding more user inputs, e.g. a pause button.

  3. Try adding a secondary visual display.