Project1 DuckTone
Inspired by previous lab of mapping the input voltage to sound frequency, I was having this idea of making an instrument. I also found the Theremin interesting because you can play it with bare hand. The idea was to implement this mechanics by a distance sensor.
Picking the sensor
The first thing I did was to find the right sensor for measuring the distance. There are two type of distance sensor, which are ultrasonic or Laser(Infrared). Here are the main differences between these two. Comparison from a video.
Ultrasonic | Laser | |
---|---|---|
I/O | 1 or 2 digital Pin | I2C |
Response Speed | Slow | Fast |
Size | Larger | Small |
Field of View | Wider | Narrow |
Price | Cheap | Expensive |
Example | HC-SR04 | VL53L0X |
Since I need it to be precise and fast, The laser one suits better. But there are still so many choice of this kind of sensor, VL6180X, VL53L0X, VL53L1X, TOF10120. (still don’t know the difference.) I just picked the most common one. Look how tiny it is compare to the arduino board.
Prototyping
I struggled so much on this Arduino nano 33 IOT which works pretty bad with tone() function and doesn’t support many community libraries. I believe that’s the price of using a modern fast MCU. Therefore, I replaced it with an pro micro board that solved most of the problems since the Nano 33 IOT does not offer any advantages in this specific usage.
With its own library, the VL53L0X sensor was pretty easy to use. It works very well within half meter, but start glitching them. I thought it was caused by its narrow angle and the ambient light. It was already good enough for this instrument though.
After making the fundamental part work, I started to dig in more features and discovered ’Mozzi’ which is a synth library for Arduino. It makes way better sound than the tone() function. Unfortunately, it conflicted with the essential Wire library due to some timer issues. I had to abandon it because of the lack of time, but I’ll definitely try this in future projects.
I included a third party library - ’toneAC’. Besides controlling the frequency of the sound, it can also controls the volume. A force sensor were added for this usage which increase the dynamic of this instrument.
Frequency calculation
Musical notes follow exponential growth, more specifically, the frequency doubles over the course of a full octave. Here is the function that convert the distance to frequency that make sure the distance between each notes are equal. Formula from: Equations for the Frequency Table
/*
distance range from 80 to 500
divide to 2 octave
start @ E4: 329.63hz
*/
float distance2frequency(int distance) {
float step = float(distance - 40.0) / (500 - 40) * 24;
return 329.63 * pow(2, step / 12);
}
Implementation
I have to admit that I haven’t got any idea for final form of this instrument at first. After I finnish the circuit, it just came to my mind that this toy duck on my sofa could be a nice container. It’s also very intersting to make sound from a toy animal, for instance, the duck. By then, this project is officially named ‘DuckTone’.
Final Result
duck.play("the-swan")