Project showcase
Ultrasonic Theremin

Ultrasonic Theremin © GPL3+

This is an arduino based theremin which uses two ultrasonic sensors to control the volume and frequency of the sound output.

  • 2 views
  • 0 comments
  • 0 respects

Components and supplies

Necessary tools and machines

Hy gluegun
Hot glue gun (generic)
09507 01
Soldering iron (generic)

About this project

Thisisasimpleprojectforcreatingathereminwhichusesultrasonicsensorsforuserinput.Itworks.

Code

Theremin CodeArduino
//In this project we create a theremin with two ultrasonic sensors, one for volume and another for tone. We use the digital potentiometer X9C103P.
// Two ultrasonic sensors are used to create a theremin. One sensor controls volume, the other controls frequency.
// This project is an iteration on a previous project I found for a theremin. The previous project had library conflicts (two libraries used the same timer) and used a different type of poteniometer. I have also added some other small features.
// Project which provided original inspiration: https://create.arduino.cc/projecthub/opus9/theremino-f72d32
// Resource on controlling similar potentiometer using SPI protocol, provides example code and electrical setup: http://www.learningaboutelectronics.com/Articles/MCP4131-digital-potentiometer-circuit.php

 *
 */
//NewTone is used to avoid the timer incompatibiliy of Tone with NewPing. 
#include <NewTone.h>
#include <NewPing.h> 
#include <SPI.h>
#define MIN_DISTANCE 35 

NewPing sonar(5, 6, 35); //sonar(pin, pin, distance), this controls volume 

// name pins for sensors and the potentiometer


// For SPI
byte address = 0x00;
int CS= 10;

int echo = 3;                            
int trigger = 4;

int distance;
int PotValue;

unsigned long TimeResponse;
float distance2;
float tone1;

void setup() {
// set all the pins 
Serial.begin(9600); 
pinMode(trigger, OUTPUT); //Tone sensor                    
pinMode(echo, INPUT); //Tone sensor    
pinMode (CS, OUTPUT);
SPI.begin();

//This has the speaker emit a start up sound from Low to High to Low
digitalPotWrite(255);
for (int i = 50; i <= 400; i++)
{
pinMode(9, OUTPUT);
  NewTone(9,i);
  delay(10);
}
delay(500);
for (int i = 400; i >= 50; i--)
{
pinMode(9, OUTPUT);
  NewTone(9,i);
  delay(10);
}

  
}

void loop() {
  
  digitalWrite(trigger, HIGH);           
  delayMicroseconds(10);   // creates a 10 microsecond pulse                      
  digitalWrite(trigger, LOW);                   
  TimeResponse = pulseIn(echo, HIGH);  // records how long it took to receive echo of the pulse
  distance2 = TimeResponse/58;  //calculates distance in centimeters


  if (distance2 < MIN_DISTANCE) { 
  //Conversion of distance into a value for a sound 
  tone1 = 50.0*pow(2,(distance2/12.0));  //calculate frequency, range of about 50-360 Hz
  pinMode(9, OUTPUT);
  NewTone(9,tone1);
    }
  else {
    pinMode(9, OUTPUT); // This sets the sound to a high pitched noise when no distance is detected
  NewTone(9,400);
  }
 
distance = sonar.ping_cm(); //Uses the library NewPing to calculate distance

//distance is converted to Potentiometer relevant values

int PotValue = map(distance, 0, 35, 240, 255); // I only use a range of resistance which is very low otherwise the speaker is too quiet becuae it is only a 4 ohm speaker

if (distance == 0) // sets volume to max when no hand is detected or if hand is too far away
{
  PotValue = 255;
}

digitalPotWrite(PotValue);
delay(10);

  
}

int digitalPotWrite(int value)
{
digitalWrite(CS, LOW); //This uses SPI protocol to communicate with the potentiometer and sets the resistance
SPI.transfer(address);
SPI.transfer(value);
digitalWrite(CS, HIGH);


}

Schematics

Theremino Circuit
Thereminocircuit bb qvuiw5iedn

Comments

Author

Default
jvmccall
  • 1 project
  • 0 followers

Additional contributors

  • I used the theremin project by opus9 as a starrting point. i used different libraries to avoid a timer conflict, used a pot which is controlled using spi, and added other improvements. . by opus9

Published on

June 12, 2020

Members who respect this project

Default

and 2 others

See similar projects
you might like

Similar projects you might like

Ultrasonic Theremin

Project tutorial by squrril

  • 2,316 views
  • 2 comments
  • 8 respects

Theremino

Project showcase by opus9

  • 3,132 views
  • 7 comments
  • 8 respects

Arduino Theremin with A Minor Pentatonic

Project tutorial by pollux labs

  • 1,317 views
  • 0 comments
  • 6 respects

Real Theremin Using Open.Theremin Shield for Arduino

Project showcase by Urs Gaudenz

  • 21,760 views
  • 9 comments
  • 27 respects

Door Alarm With Ultrasonic Sensor

Project showcase by MattG

  • 19,283 views
  • 7 comments
  • 21 respects

Simple Ultrasonic Distance Measurer With LCD Display

Project showcase by onatto22

  • 16,892 views
  • 6 comments
  • 38 respects
Add projectSign up / Login