This is a didactic project for to learn how to connect an Ultrasonic Sensor to an Arduino UNO.
COMPONENTS REQUIRED
COMPONENTS | PRICE |
---|---|
Arduino UNO clone (Aliexpress) | $ 2.40 |
Ultrasonic Sensor (Aliexpress) | $ 0.75 |
2 Buttons (Aliexpress) | $ 0.64 ($ 0,32 x 2) |
Plastic box for cheese 🙂 | Free |
CONNECTIONS
ULTRASONIC SENSOR | ARDUINO |
VCC | 5V |
TRIG | D5 |
ECHO | D6 |
GND | GND |
BUTTON 1 | |
PIN1 | 5V |
PIN2 | - GND (resistor 10K ohm) - D12 (see the picture) |
BUTTON 2 | |
PIN1 | 5V |
PIN2 | - GND (resistor 10K ohm) - D13 (see the picture) |
In this schematic I drawn a connection to an external speaker but, if you prefere, you can connect the PIN 8 to a Panel Mount Jack (if you wish connect a earphones).
SOFTWARE (SKETCH)
To upload the software for the Poor Man’s Theremin you have to download and install the free ARDUINO IDE clicking here.
The Ultrasonic sensor sends very short pulses of ultrasound to measure the distance to an object. The distance is calculated in CM e converted in tones: distance = 0.034 * duration / 2;
I created an array to convert the CM in tones:Â tone(PIN8, tones[distance ]);
Copy and paste this code in a new arduino sketch!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
// The POOR MAN's THEREMIN // wwww.bleepbit.com // (C) 2018 const int triggerPort = 5; const int echoPort = 6; int noteoff = 1; long duration = 1000; int distance = 1; int distance2 = 1; int tones[] = {66, 70, 74, 78, 83, 88, 93, 98, 104, 110, 117, 124, 131, 139, 147, 156, 165, 175, 185, 196, 208, 220, 233, 247, 262, 277, 294, 311, 330, 349, 370, 392, 415, 440, 466, 494, 523, 554, 587, 622, 659, 698, 740, 784, 831, 880, 932, 988, 1046, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976 }; int type=1; int button1 = LOW; int button2 = LOW; void setup() { pinMode(triggerPort, OUTPUT); pinMode(echoPort, INPUT); } void loop() { button1 = digitalRead(12); button2 = digitalRead(13); digitalWrite( triggerPort, LOW ); digitalWrite( triggerPort, HIGH ); delayMicroseconds( 10 ); digitalWrite( triggerPort, LOW ); long duration = pulseIn( echoPort, HIGH ); distance = 0.034 * duration / 2; // BUTTON2 CHANGE EFFECT if (button2 == 1) { type = type + 1; // IF YOU ADD EFFECT INCREASE THE TYPE IN THE NEXT ROW if (type==5) { type = 1; } noTone(8); tone(8,1660); delay(150); noTone(8); delay(100); } // BUTTON1: WHEN PRESSED THE SOUND IS ON if (button1 == 1) { // Distance test if (distance < 41) { distance = distance; } else { distance = noteoff; } // TYPE 1 if (type==1) { for (int k=tones[distance]; k<(tones[distance]+(tones[distance]/5));k=k+1) { tone(8,k); delay(2); } noteoff = distance; } // TYPE 2 if (type==2) { distance2 = distance + 12; for (int k=tones[distance2]+300; k>tones[distance2];k=k-4) { tone(8,k); delay(2); } noteoff = distance; } // TYPE 3 if (type==3) { distance2 = distance + 12; tone(8,tones[distance2]); delay(5); tone(8,tones[distance2] * 5); delay(5); noteoff = distance; } // TYPE 4 if (type==4) { distance2 = (distance); tone(8,tones[distance2]); delay(50); tone(8,tones[distance2+12]); delay(50); noteoff = distance; } // ADD OTHER TYPES delay(10); } else { noTone(8); } } |
Enjoy it!
A $four Ultrasonic Theremin Seems Tacky on Objective - TRENDING HITS
[…] don’t assume [bleepbit] will take offense after we say the “poor man’s theremin” seems tacky — in spite of everything, it was in-built a cheese container. Really, it isn’t a […]
A $4 Ultrasonic Theremin Looks Cheesy on Purpose - itmix.cz | Informačnà Náskok
[…] don’t think [bleepbit] will take offense when we say the “poor man’s theremin” looks cheesy — after all, it was built in a cheese container. Actually, it isn’t a bad case […]
A $four Ultrasonic Theremin Appears to be like Tacky on Objective | Rumorfacts Breaking News Updates | Latest News
[…] don’t suppose [bleepbit] will take offense after we say the “poor man’s theremin” seems to be tacky — in any case, it was in-built a cheese container. Truly, it […]
A $4 Ultrasonic Theremin Looks Cheesy on Purpose
[…] don’t think [bleepbit] will take offense when we say the “poor man’s theremin” looks cheesy — after all, it was built in a cheese container. Actually, it isn’t a bad case […]
A $4 ULTRASONIC THEREMIN LOOKS CHEESY ON PURPOSE -Use Arduino for Projects
[…] don’t think [bleepbit] will take offense when we say the “poor man’s theremin” looks cheesy — after all, it was built in a cheese container. Actually, it isn’t a bad case […]