QC

Theremino

A theremin composed of two ultrasonic sensors.

Devices and components

Arduino Uno Rev3

Non-volatile digital potentiometer, 10 kohm

Ultrasonic sensor - HC-SR04 (generic)

Operational amplifier, operational amp + comparator + reference

LED (generic)

Breadboard (generic)

Jumper wires (generic)

Speaker: 3 W, 4 ohms

Resistance 475 ohms

Materials and tools

Hot glue gun (generic)

Project description

Frequency:

Amplitude:

Output:

Arduino Theremin

arduino

Is this code for arduino theremin

1//In this project we create a theremin with two ultrasonic sensors, one for volume and another for tone. We use the digital potentiometer X9C103P.
2/*
3 * Potentiometer conecctions:
4 * 1 - INC - Arduino pin 2
5 * 2 - U/D - Arduino pin 3
6 * 3 - VH - 5V
7 * 4 - VSS - GND
8 * 5 - VW - Output
9 * 6 - VL - GND
10 * 7 - CS - Arduino pin 4
11 * 8 - VCC - 5V
12 *
13 */
14//Note: we include two libraries: NewPing and TonePlayer because if we use the library NewPing with a tone function, the sketch doesnot compile.
15#include <NewPing.h>
16#include <TonePlayer.h>
17#define MIN_DISTANCIA 35
18TonePlayer tone1(TCCR1A, TCCR1B, OCR1AH, OCR1AL, TCNT1H, TCNT1L);
19
20NewPing sonar(10, 11, 35); //The first and the second number are the pins of the sensor of volume, the third is the maximum distance
21
22// name pins for sensors and the potentiometer
23int echo = 12;
24int trigger = 13;
25int INC = 2;
26int UD = 3;
27int distancia;
28int actual, anterior;
29// necessary variables
30unsigned long tiempoRespuesta;
31float distancia2;
32float tono1;
33
34void setup() {
35// set all the pins
36Serial.begin(9600); //use of monitor serie for check the distance
37pinMode(trigger, OUTPUT); //Tone sensor
38pinMode(echo, INPUT); //Tone sensor
39pinMode(2, OUTPUT); //Potentiometer
40pinMode(3, OUTPUT); //Potentiometer
41//pinMode (speaker, OUTPUT);
42
43for(int j=0; j<90; j++){ //As we do not know in what value the potentiometer is, we place the value at the minimum
44 decremento();
45 }
46
47}
48
49void loop() {
50
51 digitalWrite(trigger, HIGH);
52 delayMicroseconds(10); // Pulse of ten microseconds
53 digitalWrite(trigger, LOW);
54 tiempoRespuesta = pulseIn(echo, HIGH); // Echo of the pulse
55 distancia2 = tiempoRespuesta/58; //Calculation of the distance in centimeters
56
57 if (distancia2 < MIN_DISTANCIA) {
58 //Conversion of distance into a value for a sound
59 tono1 = 50.0*pow(2,(distancia2/12.0)); //pow alculates the value of a number raised to a power
60 pinMode(9, OUTPUT);
61 tone1.tone(tono1); //Generates the tone with the previous value (220 Hz)
62 delay(10);
63 }
64
65distancia = sonar.ping_cm(); //Calculation of the distance in centimeters (with the library NewPing)
66Serial.print(distancia); //Check the distance
67//Change the value "distancia", to values that are useful for the rise and fall of the potentiometer
68actual = map(distancia, 0, 35, 0, 200);
69
70//Compares the mapped values to raise or lower the potentiometer
71if(actual > anterior){
72 for(int i = 0; i< (actual - anterior); i++){
73 decremento();
74 }
75}
76
77else{
78 for(int i = 0; i <= (anterior - actual); i++)
79 {
80 aumento();
81 }
82}
83
84anterior = actual; //The value is updated with each loop
85delay(1);
86
87
88}
89
90//The U/D input controls the direction of the wiper movement and whether the counter is incremented or decremented
91//The INC input is negative-edge triggered. Toggling INC will move the wiper and either increment or decrement the counter in the direction indicated by the logic level on the U/D input.
92//The next two functions produce these toggling in the two directions (increment, decrement)
93
94void aumento(){ //aumento == increment
95digitalWrite(UD, HIGH);
96digitalWrite(INC, LOW);
97digitalWrite(INC, HIGH);
98delay(10);
99digitalWrite(INC, LOW);
100}
101
102void decremento(){ //decremento == decrement
103digitalWrite(UD, LOW);
104digitalWrite(INC, LOW);
105digitalWrite(INC, HIGH);
106delay(10);
107digitalWrite(INC, LOW);
108}
109

Downloadable files

Theremin circuit

Is a schematic for the Arduino theremin. Just copy the configuration.

Theremin circuit

Theremin circuit

Is a schematic for the Arduino theremin. Just copy the configuration.

Theremin circuit




Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.

SendData

Điều khiển trạng thái qua Firebase Trạng thái hiện tại: Đang tải... ĐỔI TRẠNG THÁI