A Dancing Robot That Listens to Music and Moves to the Notes

by donutsorelse in Circuits > Robots

1321 Views, 4 Favorites, 0 Comments

A Dancing Robot That Listens to Music and Moves to the Notes

This Robot Listens to Music and Dances to the Notes

I like making music as well as silly robots, so I figured it only made sense to have those worlds collide. The idea is that the robot listens to the different frequencies of whatever song is played and moves based on whatever notes it hears, so it'll dance differently for any given song. I have different maneuvers written into the code based on the given note, but I've included 3 octave ranges and noted which frequencies correlate to which note, so you can very easily setup your own dance moves if you're following along!

Supplies

robot.png
PXL_20221111_201808957.jpg
  • Tank Robot
  • Raspberry Pi/Romeo BLE (I used the latter)
  • Arduino compatible microphone
  • Proximity Sensor

It's Alive!

PXL_20221111_175218980.MP.jpg
arduinoDancing.png

Step one is assembly! I've included the schematics for the electronics in this step. This is a simplified version that doesn't include the tank robot wiring (also depicted) in order to make it more readable.

There are only a couple of extra parts to plug in, so we can keep the wiring nice and simple with no need for a breadboard. Conveniently, it's recommended for microphones like these to use 3.3v, whereas the proximity sensor uses the fully 5v.

For the proximity sensor, plug the VCC into 5v, Trig into pin 11, Echo into pin 12, and GND into GND. For the microphone, plug VCC into the 3.3v, GND into GND, and OUT into A0.

Important note: it does seem that the setup works best with out plugged into A0, but you may run into issues uploading your code from the Arduino IDE while it's plugged in. If that occurs, unplug from A0, upload your code, then plug back into A0.

If you're using the same devastator robot I used, I would strongly suggest getting the code fully up and running before putting on the top and wheel attachments, because it's kind of inconvenient to get the Arduino plugged back

Safety First!

dont run into walls.png

Before we get into making the robot dance, let's make sure it doesn't dance its way into walls. That's where the proximity sensor comes into play. While the robot is moving around the room, it'll also be on the lookout for obstacles and will avoid them accordingly. I have just one forward facing proximity sensor, so the code is very simple for obstacle avoidance, but it would be very easy to add a little more vision to the robot by adding a servo to the sensor so it can look around and/or a second proximity sensor at the back of the robot.

For a setup like mine, just mount the proximity sensor to the front of the robot.

The code for the project is included in this step.

Developing Listening Skills

PXL_20221111_181348464.MP.jpg
FrequencyChart.png
frequency2.png

The goal is to figure out what note is most prominent during any given beat. For the duration of a whole note at 120BPM, we listen for the frequency with the highest intensity. We then figure out what note correlates to that frequency, and have the robot move accordingly. The way I tackled the frequency to note logic is more tedious than I'd have preferred, with 3 octaves worth of if statements, but it accomplishes the goal of determining what the robot needs to do based on the current frequency.

As part of the logic, I found the frequency of the room without music playing to keep the robot from dancing if it hears something different. There are a lot of subtle factors that go into the microphone readings, so it's likely you'll get slightly different results. As such, it likely makes sense to see what readings your microphone picks up for your room as a baseline, and it'd be interesting to see what kind of readings you get with music before getting rolling with the fully mobile tank robot.

It's pretty nice to be able to just mess with the audio testing without all the extra stuff involved in a tank robot, hence the image of the Elegoo Uno with just the microphone setup.

Another important note is that the robot isn't particularly quiet itself, so the microphone may pick up noises from itself and dance based on those. As such, I added a stand on top of the robot so that I could have the mic up and away from the wheels.

It's Time for a Dance Party

robot ready to roll.png

The robot should now be well equipped to dance to any song. It'll also more or less do the same dance to any given song, which is pretty sweet. If it's not reacting to the notes of the song well enough, you may need to increase the volume or move the music closer to the robot, because it's prioritizing whatever note it hears most and may be hearing its own wheels moving.

The code can be easily modified to add in more or different dance moves, so enjoy taking a stab at your own dancing robot if that's your jam and, if that's not your cup of tea, thanks for reading along and hopefully you enjoyed anyway!