This project consists in the sonification of distance of a surface from an ultrasonic sensor. Distance data is then transformed into an audible MIDI note which in turn is played by the Sonic-pi.
This project was inspired from this tutorial.
The ultrasonic sensor is plugged into the Raspberry pi ports and receives 5V power supply. The output signal needs to be converted to 3.3v to not damage the Raspberry pi. For this, I built a voltage divider circuit (see picture above).
A useful tutorial on how to assemble the circuit and a slightly different architecture of voltage dividers could be found here.
For this project I used the ultrasonic sensor to obtain information about the distance of an object from the sensor. I then mapped this information into a playable MIDI note, and send this information to Sonic-pi.
As Sonic-pi listens on port 4560, I used the python-osc library to send MIDI data to the sonic-pi. The documentation on receiving OSC messages could be found here.
- Breadboard
- 3 x 1 Ohm resistor, 1 x 0 Ohm resistor
- HC-SRO4 ultrasonic sensor
- Raspberry pi power supply
- Dupont wires
- Optional: base for holding your ultrasonic sensor - I recycled an used pepper container and covered it with papier-mâché
- I found useful to work entirely from my laptop, enabling an ssh connection to comunicate to the raspberry pi. Once the ssh connection is enabled, I copy data from my computer to the raspberry pi via the scp command.
scp -i ~/.ssh/<your-raspberry-pi-private-key> \
<path-to-the-origin-file> \
pi@<ip-of-the-pi>:<path-to-the-destination-folder>
Thank you very much to Auro Michele Perego for invaluable suggestions on voltage dividers and scaling techniques.