Dancing Toys
0. Overall
The project’s goal is to make toys that can express their feelings on music and ambient sound by dancing on the sound’s beats. Another goal is to make toys as easy as possible to add or remove on the dancing stage so that from a single dancer to a dancing troop is possible.


1. Processing
Minim sound library is used to detect sound beats. Minim library’s beat detection algorithm is here. However, the problem is, as the author mentioned, that ‘beat’ is a more abstract concept which is not easy to be explained in known mathematical equations. The initial plan was to detect three different beats only in frequency domain but I found that simple detecting algorithm in time domain is better than in frequency domain. (The basic algorithm in both domains is the same but specific frequency bands to detect beats can be selected in frequency domain. Even though there are some sophisticated beat detecting algorithms, most of them was not plausible for this project because they need whole data of a song to find out beat patterns which disables on-the-fly detecting.)
As a result, detecting in the time domain and two pre-selected frequency bands (40~80Hz, 100~400Hz) are used in this project. One byte of beat information, whose lower 1st~3rd bits are designated to each beat and set to 1 if that beat is detected, is composed and sent to Arduino every frame via serial cable. Only the master toy receives this data from Processing and dances along with it.

2. Arduino
Each toy has one Arduino board and 3 servos, 1 IR emitter and detector are connected to the board. More specifically, servos and IR emitter are wired to MCU Port outputs and IR detector is wired to MCU comparator’s input. The master toy is directly connected to Processing and slave toys communicate each other via IR signal.

In terms of the master toy, each servo is mapped to each beat bit of received byte. If the bit is 1, the servo rotates small angle (15°) or rotates for a short time(80ms) switching its direction. When a byte is received, the master toy sends IR signal to the slave toy. IR signal’s duration is proportional to the byte’s value. As it is designed that value 1 has 5ms duration, IR signal duration varies from 0ms to 35ms (max 00000111 byte = 7*5ms)
As IR detector’s output is analog, it is connected to slave toy’s MCU comparator input in order to make use of comparator output edge interrupts. On the rising edge of comparator’s output, the slave toy’s interrupt function is called to save the time using millis() function and its IR emitter is turned on to send signal to other slaves. The same thing is done on the falling edge (IR emitter is turned off) and the time difference between two saved times is converted to the servo control signal. The inevitable delay from the master to a slave is maximum 35ms but there’s no delay between slave toys because of interrupts driven IR detector and emitter.

However, I found that the continuous servo is not appropriate for this kind of project that servos rotates for a short time and switches its direction frequently. The torque of continuous servo while it is rotating was so weak that the bottom servo couldn’t support the whole weight of a toy and two other servos. Moreover, unlike 180° servos, continuous servos were very hard to accurately rotate and stop as much as it is programmed. For these reason, the bottom servo, which is mapped to 100~400Hz beats, was disconnected in the presentation.


