The Linux Robot – Dancing Beat Recognition

I haven’t had a chance to post anything here in quite a while now, partly due to lack of time, and partly due to lack of interesting or original material.

SEE VIDEO BELOW! I found myself with some spare time over the past few days and decided to try and get the robot to dance autonomously. I initially started looking at software algorithms to detect BPM (beats per minute) in music, either by using phase shifting which is challenging to write and not hugely accurate, or by analyzing amplitude peaks at a given [usually bassy] frequency, which is easier to write, and even less accurate.


I decided to go with the easier amplitude peak method, but instead built this into the hardware. I split the output cables from the USB sound adapter to the flat nokia speaker that you see at the top of the robot. Contained within, are ground, left and right channel cables.

I connected ground and left to Phidget Kit 2 analog input 6 (ground to ground, left to signal), and I connected ground and right to Phidget Kit 2 analog input 7 (ground to ground, right to signal). Luckily, I had these two inputs free, and still have one remaining. The +5v pin on the Phidget Analog Input can be discarded in this case as we are providing our own voltage.

The Phidget Kit analog input will take a voltage of up to +5v, and as we are measuring a voltage up to about 1.2v max, this is ideal.

In line with the existing tcpserver and library written, I can use commands PS15 and PS16 to read the value of these sensors. I read them both simultaneously and expect to detect an amplitude peak in them both to rule out error. I will also discard any peak found within ‘x’ milliseconds of the last accepted peak to rule out mistimed samples. Ideally, this would be controlled by external hardware, and an interrupt would occur on each beat, rather than having to take constant samples as this would be far more CPU friendly. There are ICs that contain banks of op-amps such as the LM3914/3915/3916 which are incredibly easy to use. The reference values can be adjusted via a 5k pot.

The cinematography of the video is pretty poor but hopefully you get the idea!

Tagged with: , , , , , , , , , , , , ,
Posted in Projects, Robot

Leave a Reply