Designers

Tabi Silver

Jocelyn Shiue

Jean Huang

Under the guidance of James Battat.

With the help of Amy Banzaert, Dave Barrett, and Larry Knowles.

Project Description

We built a dancing narwhal that utilizes an analog low-pass filter for beat detection. Beat detection input is initially gathered by a microphone, whose millivolt signal is re-centered around 1.5 V and amplified to fill the 0~4 V range before reaching the Arduino Uno. Movement is provided by 6 servos, 4 below and 2 above a mobile platform: the lower servos provide vertical bopping and twisting motions and the upper servos in conjunction with a 3D-printed joystick provide side-to-side and forward-to-backward rocking motions.

This project was inspired by the Keepon Interaction Robot but designed as a budget-friendly alternative that does not involve color CCD cameras or isolated degrees of freedom for motion. As GoogleDocs is incapable of embedding videos, follow the links for video footage of the Dancing Narwhal in action to a metronome at 60bpm and an EDM beat.

Parts List

Materials used amounts to a total budget of $57.40. This budget does not include the purchase price of the tools used, including:

  1. Foam cutter
  2. Drill press
  3. Table Saw
  4. Sander
  5. Tap and driver
  6. Laser Printer
  7. Frequency generator
  8. BNC cords (2) and wire clip to BNC connectors
  9. Screw cutters
  10. Oscilloscope
  11. Hot glue gun

Project Construction

There are three main components to the construction of this dancing robot (accentuated in the block diagram below): A) audio signal input, B) beat detection to pulse formation, C) structural design.

Component A: Audio Signal Input

Although not included in the Parts List, an oscilloscope is helpful for troubleshooting microphone circuitry. The mini-grabbers for the oscilloscope input channels will show up in the circuit images throughout this section.

The basic circuitry interacts with the sound input in three sections before sending the audio signal to the Arduino Uno:

circuit diagram source: PHYS 310 Electronics Lab 9

To avoid damaging any hardware, disconnect the power source when tweaking circuitry.

Component A-i: Sound Input

Pretty straight forward connection of the positive terminal of the microphone to the voltage source through a 2.2kΩ resistor and then the negative terminal of the microphone to ground. The microphone terminal that is marked by three radiating lines is the ground terminal. The 2.2kΩ resistor does not serve the purpose of preventing a surge of current to the microphone. The microphone itself is equipped with a field effect transistor that is able to serve this purpose by buffering the microphone with high input impedence. Instead, the 2.2kΩ resistor is a pull-up resistor - it ensures that the voltage is well-defined at +5V even during silence. What comes out of the microphone in response to our audio signal is an AC signal on the mV scale. You can check this with an oscilloscope.

Component A-ii: Level Shift

As mentioned at the end of the previous section, the microphone produces a mV scale AC signal superimposed on top of a +5V DC output. The level shift component is inherently a high pass filter as its goal is to block the large DC voltage from the microphone but pass the (higher frequency) audio signal. The ratio of R1 and R2 as a divider determines how large of a DC offset is applied to the audio signal. For reasons to be explained in “Component A-iii: Signal Amplification,” we want to apply a DC offset of ~2V to the audio signal.

V

Specifically for our beat detection purposes, a further restriction is placed on R1 and R2 (and C): most song tempos are set within the range of 100~180bpm, which in turn corresponds to a frequency range of 1.7~3.0Hz. To prevent losing this information, we must determine R1, R2, and C with a low cutoff frequency (like 1Hz) in mind.

Hz

We went with C=10µF, R1=560kΩ, and R2=220kΩ for a fc~1.5Hz and a Vout~1.4V. Keep in mind that R=R1||R2 for a divider.

To check your work, wire up the oscilloscope as follows (red mini-grabber to the top of the image connects to CH1 on the oscilloscope vs. that to the right of the image connects to CH2 on the oscilloscope):

The yellow signal of CH1 should correspond to the output of the microphone (CH1 set to AC coupling, 10.0mV scale). The blue signal of CH2 should reflect the microphone output after applying level shift. All oscilloscope traces shown in this documentation correspond to a 60bpm metronome input signal.

In the image above, CH2 is set at AC coupling and 10.0mV scale to match the settings of CH1. The signals have been vertically staggered for clarity and the signals look no different from each other. We chose to include this image due to the limited range of the oscilloscope’s y-axis which will become clear in the next image where we try to emphasize the effect of the level shift.

The parameters for CH1 remain the same but CH2 is now set to DC coupling and on the 500mV scale. Both signals are now zeroed at the same point. Due to the larger scale, the beat pattern is not visible on CH2. However, we can confirm successful DC offset of ~1.25V.

Component A-iii: Signal Amplification

An operational amplifier can be used to amplify the mV offset output to span a V scale range. The ‘358 op amp is a single-supply op amp and when powering it with +5V supply, its operating range is more or less 0~4V. The potentiometer allows for adjusting the gain of the amplifier by the turn of a knob as opposed to replacing resistors.

Check for proper wiring and functionality by hooking up the oscilloscope as below (CH1 still microphone output but CH2 is now op amp output):

Signal with maximum gain:

Signal with minimum gain:

Some amount of gain in between the extrema:

Optional Enhancements:

Recall that our desired signal frequency range is 1.7~3.0Hz. Optional hardware RC filtering can filter out high frequency noise if the cutoff frequency for a low pass filter is set to ~3Hz. We did not elect to do so - we opted for analog filtering on the Arduino - but these two methods do not conflict with each other so both can be implemented simultaneously for the best results.

Also, the power supplies can be replaced by a battery pack, but make sure resistance and capacitance values are still valid.

Component B: Beat Detection to Pulse Formation

Final code that we ended up using can be found here. The input signal undergoes a bass filtering, envelope filtering, and then low pass (3.0Hz cutoff) filtering process before analysis. All of this filter code was taken from the LED belt tutorial which can be found here. The Arduino is instructed to make a detection every 200 ms. The detection checks if the state of the signal has changed from low to high. If so, it marks the time and waits until the next low to high interval to find the beat. The threshold between what is considered as low versus high is determined by a resistor-potentiometer divider to allow for physical adjustment without re-uploading code (we used 1kΩ resistor-10k~100kΩ pot divider). This output of this divider is plugged into the A1 slot of the arduino. Based upon the beat time interval detected by the low to high change, all servos move accordingly from 0° to 90°.

Best troubleshooting method for Arduino code

Throughout implementing the code it is best to be able to see what is successful and not. This is easily done by having the oscilloscope CH1 connected to amplification circuit output (which is the Arduino input) and CH2 connected to Digital Pin 2.

It is important to utilize print statements for debugging (don’t forget Serial.begin), however keep in mind that print statements slow down the loop process. Creating too many print statements may lead to more issues than if there were none if things are very time dependant.

It is important to check that variables are defined in the same way if information is being passed from one to the next. (Example: integer = float; will make information incorrect)

Optional Enhancements

If one is interested it making the signal for the beat detection very stable such that random noise (ex a loud clap) doesn’t influence the way the narwal dances, one could write code to alleviate this issue. In case the signal is inconsistent meaning that the beat detection isn’t consistent (this would be seen on the oscilloscope) you can incorporate a way to calculate the median amongst the past 10 numbers. This would involve creating an array and using quicksort method to find the median.

        As of right now the narwal doesn’t do a great job of stopping after dancing, and the program continues to run after a song is completed. A good way to do this is to create a break code that would set all of the servos to the resting position of 0° after the song has completed.

Finally, you can incorporate more dance moves and utilize a random generator to decide when to use which dance move

Component C: Structural Design

Schematic for structural design:

There are two seperate motor controlled sections that create the overall movement of the robot:

The lower section is a spinning and rising disk that uses a pin-in-hole mechanism to stabilize itself while also moving freely around the axis. The motion is powered by four circularly facing servo motors (face same direction in a circular pattern) that are permanently attached to the bottom half of the CD case forming the foundation of the robot. The equidistant placement of the servos on the bottom platform is important to obtain a balanced and smooth vertical and spinning motion. When the servos work in unison it results in a rotation and lifting of the mobile disk. The stationary purple disk was hot glued to the cardboard and the servos were placed and hot glued in their specific locations. All four servos used the one sided extenders pictured here:

A layer of cardboard was placed between the servo and the mobile plastic CD case in order to improve stability. The structure that formed the hole for the pin was made from a brass fastener head facing down with its two tails wrapped around a tight wire ring made from a paperclip. The head of the fastener was glued to the bottom layer of cardboard. The pin was made from the rest of the paper clip and attached to the mobile purple disk.

The upper section creates a tilting motion that is powered by two servo motors which move a 3D printed joystick mechanism, reffered to sometimes as the double rainbow, (largest size was 57 mm). The joystick mechanism was printed out of ABS, Acylonitrile Butadiene Styrene, with dissolvable supports that were removed by placing the print in a lye bath overnight. We discovered the effectiveness of dissolvable supports after the first two prints failed. They were using PLA with and without undissolvable supports. It was concluded that dissolvable supports and ABS would be the most effective way to print the joystick mechanism. Even with dissolvable supports the lye bath couldn’t get to all of the dissolvable support out of the very small spaces between joints. It took a lot of extra effort to make sure that the print was free of supports so that the joint could move freely and smoothly. Once we were sure that the print was effective we started to figure out how to connect the two servos to the joystick mechanism. After attempting to use heat shrink, hot glue and screwed wood and failing, Larry and I developed a double ended screw method. First, I drilled 0.750 mm drill bit sized holes (one per a servo connection point with a 0.750 drill bit) into the center of the two cross shaped connection points (where we will connect the 2 servos later) using a drill press. Then I used a 0.80 mm tap and driver to make ridges inside the 0.750 drilled hole. Once the ridges were made, I screwed in the 0.80 mm screws as far as they could go. I then measured how deep the screw could twist onto the servo (this was a very short distance < 1 mm). The distance that the screw would go into the servo is the length sticking out of the joystick that I marked and then cut so that the servos would fit tightly against the joystick connectors. I had to tap the servos before screwing in the 0.80 mm screws as well. This double-ended screw apparatus was reinforced with epoxy glue because it was crucial that the servo rotations move the joystick connectors and not the body of the servo motor itself. After attaching the servos to the joystick mechanism it was time to mount the joystick. A chipboard platform with holes cut out on the bottom for the free movement of the rotating poles and double rainbow were laser printed and 4 mounting holes were drilled with the drill press. The 2” 8/32 screws were placed through the joystick’s mounting holes, through a washer (for space and extra joystick mobility), and finally through the mounting holes in the chipboard, and 1.5” 8/32 standoffs were screwed on below the chipboard to support it and the ends were hot glued to the purple platform. The presence of the chipboard under the servos kept them stable and supported The servos were hot glued to the chipboard in their appropriate places.

The brown, red, and orange pins of a servo must be connected to ground, power, and an arduino pin capable of pulse width modulation (pwm), respectively. If you choose to include more than 6 servos in your design, keep in mind that the Arduino Uno only has 6 digital pins capable of pulse width modulation (marked on the board with “~”). Furthermore, we are already powering the servos with an external breadboard as the Arduino Uno cannot handle that level of current demand.

The Dancing Narwhal itself was sculpted out of foam core using a foam cutter (a hot wire that is held taut and burns through foam leaving a smooth cut finish). The eyes and mouth of the Narwhal were improvised from salvaged stuffed animal facial features. The horn of the Narwhal was crafted from wikki stix and spray painted silver. It was assembled in an improvised rush but turned out pretty cute if I don’t say so myself (I built it ;D). Please feel free to instill the ability to dance upon your own spirit animal.

Optional Enhancements

The joystick structure that we 3D-printed is not capable of a large range of motion. For fluid motion, when one servo is moving, the other must be held at the center position. When both servos are moving simultaneously, the joystick is able to move across the diagonal, but if one servo is moving and the other is held at an angle, the joystick will be stuck. The 3D-printing of this joystick required removable supports in order to print in place and have compact mobile joint.

Project Timeline

Dependent on how ambitious you want to be - rather, the extent to which your ambitions differ from ours - the amount of time required to complete this project will vary. The project timeline will also depend on your available resources. If you follow our comprehensive documentation step-by-step and have all the materials on hand, this is an easy project for an afternoon (not including the time needed for 3D-printing the joystick and soaking the dissolvable supports in a lye bath overnight) because we’ve already done the grunt work for you. If you want to make any enhancements to the beat filtering and detection Arduino code, keep in mind our troubleshooting tips to save your sanity. Hope you have fun constructing the dancing spirit animal of your choice! The (functioning) final product is truly a rewarding companion.

ƪ(˘⌣˘)┐ ƪ(˘⌣˘)ʃ ┌(˘⌣˘)ʃ