
I know that looks like total garbage but, it's the super early prototype. I'm just getting everything to work and then I'll worry about building a finalized circuit on a custom PCB and 3D printing a nice body for this thing. I'm calling it a theramin but, it's more like a virtual 1 string guitar.
The way it works is you take a business card or something of that size and place it in front of the range finder. The distance the card is from the range finder is converted to a sound frequency relative to the "fret" the card is located at. You can take a guitar pick or your finger or really whatever you want to "pluck" the vibration sensor which activates the speaker to play the frequency for the location of the card.
I built all of this from ideas, trial and error. The only thing I had to find a tutorial on was how to properly hook up the trigger and echo pins for the range finder. It works pretty good. Sometimes it seems to get a little confused but, this is still a really early prototype. I've only had this arduino for 2 days and I started building this like 3 or 4 hours ago. It doesn't matter that the lines on my board are shit. The values from the range detector are recalculated to be from 0 to 11 and that value corresponds to an array index with the proper and exact frequency. Anywhere between any two consecutive lines is one solid note. However, even though my lines are shitty, they are super close. A few of them are a perfect break between notes. None of that matters though. I just needed some visual data so I could see basically where a note range falls.
Apparently, the language for arduino is C so, I guess I program in C now. At the very least I can do it on an arduino level. This project will get a lot better over time. I play numerous instruments and have been for 30 years. I have ideas on how to add some features that will let people get a lot more out of this than what one string would provide. One idea is to line the side of the neck with a few buttons that will allow you to play double-stops of 3rd, 5th, 7th, and 9th with another button that will flat and another that will automatically shift the pitch of the "string" by an octave. Right now it is hard set at open E4 frequency but, I intend to add a potentiometer to act as a tuning knob.
I have a few ideas how I will replace the current card method with something that can slide on a roller up and down the neck and that same roller housing will actually be what has all the buttons that I just mentioned. That way you can hold it like a guitar neck by the roller housing and all the buttons will be right at your fingertips. Ideally, what would generally be the body of the guitar will actually be an amp, effects processor and excellent speaker ... all of which I will essentially make from scratch (well, except for the speaker)
Why?
IDK, cause I can. I wanted to make something that touches on all of my talents. All of the elements of this project combined pretty much cover it.
My current code is shit. I'll clean it all up and nail down the best method as things progress
#include "Volume.h"
Volume vol;
#define MAX_DISTANCE 200
float timeOut = MAX_DISTANCE * 60;
int switchPin = 3;
int echoPin = 11;
int trigPin = 12;
float notes[] = {329.63, 349.23, 368.99, 392.00, 415.30, 440.00, 466.16, 493.88, 523.25, 554.37, 587.33, 622.25, 659.25};
bool isVibrate = false;
int soundVelocity = 340;
float nFreq;
void setup() {
vol.begin();
pinMode(switchPin, INPUT_PULLUP);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
attachInterrupt(digitalPinToInterrupt(switchPin), vibrate, FALLING);
Serial.begin(9600);
}
void loop() {
float v = constrain(analogRead(A0) / 10, 0, 100) / 100.00;
int x;
if (isVibrate) {
vol.setMasterVolume(v);
x = min(floor(getSonar()), 11);
nFreq = notes[x];
isVibrate = false;
vol.tone(nFreq, 250);
vol.delay(200);
Serial.print(nFreq);
Serial.print("n");
} else {
//this condition is bullshit and doesn't work properly
for (int i = ceil(v); i > 0; i--) vol.setMasterVolume(i);
vol.delay(200);
}
}
void vibrate() {
isVibrate = true;
}
float getSonar() {
unsigned long pingTime;
float distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
pingTime = pulseIn(echoPin, HIGH, timeOut);
distance = (float)pingTime * soundVelocity / 2 / 10000;
return distance;
}
|