A theremin is an electronic musical instrument controlled without physical contact by the thereminist (performer). It was patented by Leon Theremin in 1928 and its controlling section usually consists of two metal antennas that sense the relative position of the thereminist's hands and control oscillators for frequency with one hand, and amplitude (volume) with the other. In the following project we try to emulate the functioning of this instrument using two ultrasonic sensors which are able to detected distances and as a function of this we tell the Arduino to emit sound at different frequencies and amplitudes through a loudspeaker. Here's a detailed explanation.
Frequency:We use an ultrasonic sensor with four pins. Two are for voltage input and ground. Another one called trigger is used to send an ultrasonic pulse through a digital write on the program. The last pin is called echo and it recieves the ultrasonic pulse when it bounces back. The time it takes the pulse to go back to the board is read and stored in a variable, then we convert it to distance units (cm). Finally we use the TonePlayer library to convert each distance to a different frequency. We're using the equal temperament system to calculate exact musical notes, so for every different value of distance we have a different musical note.
To control the amplitude we use another ultrasonic sensor but this time we decided to use the NewPing library and the sonar.ping_cm() function which sends a ping, returns the distance in centimeters or 0 (zero) if no ping echo within set distance limit. This information is stored in the variable distance. Then we made two special functions called incremento and decremento. This functions tell the digital potentiometer if it should increase or decrease the value of its resistance based on the distance information. If the distance is increased so is the resistance, if the distance is decreased then the resistance will decrease too.
A common loudspeaker is connected directly to the output pins of the digital potentiometer. The different values of resistance will be perceived as volume variations. Optionally we can use an amplifier for the speaker but it really isn’t necessary.
Remarks:
1) We used a common led as an indicator of the variation of resistance.
2) You gotta use the special TonePlayer library (link provided) cause any other similar library will crash Arduino whenever if runs with the NewPing library.
3) Tone functions only works on Arduino Uno. I'm not exactly sure why.
Here's the final result:
Comments
Please log in or sign up to comment.