Billy Bass in the Toronto Tool Library surgery room.
- Big Mouth Billy Bass*
- Echo Dot 2nd Generation
- Arduino Uno
- Arduino Motor Driver Shield
- LM386 Amplifier
- 3.5mm Audio Cable
- At least 4x C Cell Batteries
*This Billy Bass seems closest to mine, any should work but some may contain only two motorsBilly Bass Teardown
1. Billy Bass should have some pretty obvious screws on the back. Trust your instincts and simply unscrew those (saving the screws), and pull the back off the fish. This should open up to reveal motors on the fish side, and a battery pack on the back plate.
2. You will see a PCB inside with all the wires attached. Track the wires coming from the motors, and cut them free from the Billy PCB board leaving yourself as much wire as you can (there should be plenty). Tape or mark these wires. Identify the wires coming from the battery, and cut those free from the PCB as well. These will be used later to provide power to your Arduino through the Motor Shield.
3. (Optional) Identify the switch used to toggle the motion sensor for the fish on and off. Cut its wires and solder the positive lead from the battery terminal to pass through this switch instead, allowing it to be used for turning on and off Billy's power to the motors. This is for convenience and not strictly necessary.
4. Attach your motor shield to your Arduino, and connect the positive and negatives wires from the motors to the first three motor ports on the motor shield (labelled M1, M2, M3). Connect the positive and negative leads from Billy's battery pack to the terminals labelled EXT_PWR.
Motor shield with 3 motor wires attached - two at the bottom, one at the top, along with power from the battery pack on the right hand side with the black and red wires. The white wire is connected to the audio amplifier described in the next section.
With all the wires attached, now you can upload your first sketch to the Arduino and confirm the motors are working as expected. You will first need to install the Adafruit Motor Library for controlling your motor shield by following the instructions on their site. Once that is done, you can upload this Motor Diagnostic sketch to your Arduino which should drive M1, M2, and M3 in sequence.
You should remain on this step until you are able to control the head, mouth, and tail by the motors of the same name in the Arduino sketch. This will be needed when we add more sophisticated actions.
If this is not working, you may have to assign the head, mouth, and tail variables in the sketch to a different motor number based on how you connected them. Additionally if the mouth, tail, or head seem to move the wrong direction, you can reverse the two wires attached to the motor shield.Echo Dot Teardown and Audio Detection
1. Peel the rubber off the bottom of your Echo Dot (2nd Generation), which will reveal a clear adhesive layer which you can also peel off. This will reveal four torx screws. Unscrew and remove these four screws, and your dot should come apart into multiple pieces.
We are interested in the two circuit boards. Be careful with the ribbon cable connecting the two PCBs. This came unplugged for me about 20 times, so you may want to attach this to the fish case immediately (see photos near the end of this post for how I attached mine).
2. Cut your 3.5mm audio cable very close to the jack. Peel away the rubber to reveal the contacts at the base of jack. This will contain a left, right, and ground cable (in the form of many small loose wires). Solder a length of wire to both L and R (converting the signal to mono), and twist the loose wires together to form a ground wire. For more info on the audio jack, checkout this very helpful post. At this stage you can test that the audio output still works using a portable speaker.
3. Connect the signal wire (L and R mono) to the IN pin on the LM386 amplifier board, and connect the ground pin to the audio signal ground. Run wires from the Arduino 5V output / GND to the amplifier's VCC and 2nd GND pin (can also use Billy Bass battery pack for VCC and GND). Now attach the wires from Billy Bass' speaker to the amplifier.
At this point you should be able to plug the 3.5mm audio jack into the Echo Dot, and hear Alexa through the speaker. If you can not hear music, try turning the small screw (potentiometer) on the amplifier to increase the gain. This will introduce noise however, so try to keep the gain as low as possible.
4. With the 4 pins on the amplifier oriented at the bottom, you'll have the two speaker wire terminals at the "top". Attach an additional wire to the top left speaker terminal, and connect this to Analog pin 0 on your Arduino. For testing purposes this can be done without the motor shield attached. Once it is working however, you will have to solder this to the motor shield connection marked A0 (actually, I accidentally used A1 - any analog pin will suffice).Audio Diagnostic Arduino Sketch
If you have followed the above steps correctly, there are two tests to confirm you are on the right track. You should make sure these two checks are working before proceeding to the next step!
1. When you play music from your Echo ("Alexa, play Slayer"), you actually hear something.
If this is not working, check the power going into the amplifier is setup correctly, and check your wires from the 3.5mm audio are properly connected.
2. When you load this audio diagnostic sketch to your Arduino and open the Serial Monitor (9600 baud), you can see a log message indicating if music is playing or not. You can also watch the onboard LED for the Arduino which should be illuminated when music is playing, and off otherwise.
If step 2 isn't working, try connecting your analog wire to the other terminal on the speaker ports coming from the amplifier. You may also need to adjust the "quietThreshold" value in the sketch to correctly calibrate for no sound playing, though in the next step we will average this value to make it more stable.Putting It All Together
After independently determining we can make all the motors move, and that we can play music and measure from the Arduino when music is playing, we just need to combine the components.
This is done simply by connecting the amplifier signal to the A0 port on the motor shield, and plugging in all the motors. Pushing this sketch combining the audio signal reading with some more advanced motor movements to your Arduino should now trigger fish animations anytime music is playing.
Plug your Echo into a power supply and connect it to the 3.5mm audio cable, and you should see your fish take on the personality of Alexa! We're in the home stretch now.
Now all that's left is attaching the electronic components inside Billy's case and closing it back up. I used the plastic spacer tabs on Billy Bass to hold the Dot in place by gluing the lower PCB to the case, and attaching a screw through the top PCB to one of existing screw risers for the case which I cut in half. The amplifier was glued to the backing plate (as far from the speaker as possible, as there is a crackling noise when they are close together), and the Arduino was hot glued in the remaining space. Keep in mind you may want to take this apart again, so use either long or detachable wire connections.
Finally, you will probably want to drill some holes in Billy's plastic so audio can travel more easily to the the Echo Dot's microphone. I also cut a hole in the side of Billy's case so I could run two USB cables out of the body. One for programming the Arduino if I wanted to keep tinkering, and the other for powering the Echo Dot (using a portable USB battery pack). I think if you wired a USB cable to the battery pack on billy you could also power the Echo dot directly from that, but my one attempt was unsuccessful. I will update this page if I manage to get that done.
So here is one more blog post about how to make Billy Bass into a smart fish. By using the Echo Dot instead of a Raspberry Pi you get all the first party Alexa capabilities like drop-in calling. That being said, you can't be quite as intelligent about what kind of sounds Billy is making. It might be fun to revisit this with Alexa in a Raspberry Pi so I could write some different animations when voice is detected, or even add another layer of audio processing so it sounds like the fish is under water. But I'll have to leave that for a rainy day.
Hope you enjoyed the write up, and good luck hacking!