A theremin is an electronic musical instrument which is played by the performer without physical contact. By the use of the hands suspended in the air over antennas, one hand controls the volume and the other controls the pitch or frequency. The player plays different frequency ranges at different volumes by moving the hands at different distances.
My idea was to mimic a pseudo-theremin by using ultrasonic sensors and a buzzer. I arranged two ultrasonic sensors at different orientations to track the distance of the hand. I then mapped the two ultrasonic sensors to frequency and volume by mapping the values read from the sensors to specific frequency and volume ranges.
The schematic and code:
/* Name: Mbebo Nonna Date: 10/14/2022 Project: Pseudo-theremin build input: (2,3) (6,7) 2 ultrasonic sensors output: (9,10) buzzer */ #include <NewPing.h> #include <toneAC.h> //defining the max_distance of the theremin const int max_d = 35; //ultrasonic sensor to control frequency; const int trig_f = 3; const int vol_f = 2; //ultrasonic sensor to control volume; const int trig_v = 6; const int vol_v = 7; NewPing freq(trig_f, vol_f, max_d); NewPing vol(trig_v, vol_v, max_d); void setup() { // put your setup code here, to run once: Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: //read the distance from the ultrasonic sensor for frequency int f = freq.ping_cm(); Serial.print("freq "); Serial.println(f); //read the distance from the ultrasonic sensor for volume int v = vol.ping_cm(); Serial.print("vol "); Serial.println(v); //map the values to specific ranges int volume = map(v, 0, 15, 0, 10); int frequency = map(f, 5, 30, 1000, 15000); //play the sound on the buzzer with the frequency and volume toneAC(frequency, volume); //delay for 200ms delay(200); }
Video of me playing the pseudo-theremin:
Reflections:
I used two new libraries, NewPing.h and toneAC.h. NewPing makes working with ultrasonic sensors easy and toneAC makes working with buzzers or speakers simple. In generally, it was really fun playing the instrument and experimenting with different delays and frequency ranges.