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:
Use a solderless breadboard to construct a potentiometer circuit.
Read and process and analog input as a user input.
Control a hobby servomotor module.
Create a timed pattern of movement using the Arduino Servo library.
Use the serial port output for debugging.
Reference Guides
Please review the following reference guides as needed:
Assigned video lecture clips, including specific commentary on this exercise.
Hobby Servos (course Reference Guide)
Programming (course Reference Guide)
Arduino IDE (course site)
Lecture Sample Code, servos section (course site)
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.
Please only rest the Arduino on a non-conductive surface. It has exposed metal on the back which can short-circuit.
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.
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.
Please perform all wiring changes with the USB cable detached and the Arduino unpowered.
Please carefully observe breadboard wiring discipline, double-checking all jumper wire locations.
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.
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.
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.
Please make sure you have an up-to-date installation of the current Arduino software system (the IDE).
Please write an Arduino program which implements a user-controlled metronome. At minimum, this will include:
importing the Servo library
declaring a Servo object
attaching the Servo object to a hardware pin
initializing the Serial port for debugging
reading the potentiometer signal using an analog input
translating the raw analog input to appropriately scaled timing values using map() or equivalent expressions
issuing write commands to the servo
regulating time using delay() or millis()
Please make sure the metronome produces a useful movement for every potentiometer position.
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).
Please record a brief (~20 second) video demonstrating the operation of the device.
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.
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:
a brief video (~20 seconds) demonstrating operation over a range of inputs
your Arduino sketch uploaded as a single .ino file
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.
Try creating a smoothly controlled trajectory instead of step commands.
Try adding more user inputs, e.g. a pause button.
Try adding a secondary visual display.