MIDI device using HC-SR04 Sensor troubleshooting

Hi there. To preface I'm very new to Arduino, but am willing to do a lot of research to make this work.

The idea: Create a Thermin type device using an ultrasonic sensor (HC-SR04) that sends MIDI data to my DAW (AbletonLive10) to affect parameters

What I have thus far: ripped code from Moritz Simon Geist

Link to code: Midi-theremin/Midi_theremin_v1.ino at master · Sonicrobots/Midi-theremin · GitHub

Code:

// MIDI THEREMIN
// Moritz Simon Geist
// www.sonicrobots.com
// v.1.0 14 March 2014
////////////////////////////////
// This sketch uses an HC-SR04 Ultrasonic Sensor and produces an MIDI out signal, according to the measured distance form a object
// Be sure to include the latest MIDI Library  (here 4.0)
// http://playground.arduino.cc/Main/MIDILibrary#.UyNutYUn2Hs
//
// Wiring: Ping pin from the HC-SR04 Ultrasonic Sensor --> arduino Pin 13, 
// Echo pin from HC-SR04 Ultrasonic Sensor --> Arduino PIN 12
// MIDI-Out --> TX according to this sketch http://arduino.cc/en/uploads/Tutorial/MIDI_schem.png

#include <MIDI.h>
int pingPin = 13;
int inPin = 12;
long duration;
int cm_new = 20;
int cm_old = 20;
int sens = 5; // sensivity range when to launch a new  note

void setup() {

  Serial.begin(31250); // MIDI Begin
  pinMode(pingPin, OUTPUT); // setup the Pins
  pinMode(inPin, INPUT); // setup the Pins

}
 
void loop()
{


// The PING is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:

digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(10);
digitalWrite(pingPin, LOW);
duration = pulseIn(inPin, HIGH); // the singal from the Sensor is measured. The length of the pulse describes the distance form an object to the sensor.
 
cm_new = map(constrain(duration, 20, 3000), 50, 2000, 96, 48); // contrain --> set a threshold to cut values of the sensor that are to far away of to short (20 .. 3000) MAP --> Map the sensor range to a note values vom 96 (A high C) to 48 (a low C)

if (cm_new != cm_old) // only if a new sensor value is detected, a new nite will be send. IF the object stays stable infront of the sensor, no note will be send.
{
  MIDI_CREATE_DEFAULT_INSTANCE();
 MIDI.sendNoteOff(cm_old,0,1);   // Stop the old note
 MIDI.sendNoteOn(cm_new,127,1);  // Send a new Note (pitch , velocity 127, on channel 1)
cm_old = cm_new;
}
delay(30); // for staiblity
}

I've got everything uploading and compiling just fine... I just don't know how to send this data to affect parameters in Ableton. I've done about 10hrs of research thus far and haven't come up with anything useful yet- even forum posts about essentially the same thing.

Any push in the right direction would help. Thanks!

Are you able to send keystrokes to your synthesizer like the code looks to be doing?

What is working now?

I just googled “ midi set parameter on synth “ to confirm a suspicion I had that modern synthesizers accept parameter adjustments encoded as midi messages.

At a glance, confirmed. Do you have a midi to Arduino interface?

Or better, google “midi set parameter abelton”.

a7

Theremins normally create notes not "affect parameters". And that's what your code does. So a few basic questions. What Arduino? What is Ableton running on and what MIDI connection are you making to it? If you have a working MIDI connection you should be able to play notes in Ableton. Can you?

Exactly what parameters do you plan to modify, in what instruments within Ableton? They don't all behave the same way. Do you know what MIDI commands are needed for these changes? I'd guess they use CC (Control Change) messages but I don't know, and I don't use Ableton myself (Reaper for me!).

Steve

Preface: Arduino Uno. OSX operating system.

Hey Steve. Thanks for the reply. After doing some more research I've scrapped my idea of parameter controlling and decided to stick with note triggering- thank you for pointing me in the right direction (I thought that they were the same signal).

I think I found what my problem is. Midi notes are being generated when I trigger my sensor, and it's sending the signal to the "TX" channel on my board. I believe some people when creating devices like this will wire a physical midi connection to that channel (ex: http://arduino.cc/en/uploads/Tutorial/MIDI_schem.png). I, however, am using a midi serial bridge called "Hairless". This is supposed to capture the midi signal coming from my board and digitally communicate it to an input channel instead of physically (you probably already know what I'm talking about). My problem is the serial bridge doesn't recognize my signal as midi. Here's a picture of the error message sent when the sensor is triggered:

. And for reference, here is what it should look like when something is triggered: #3 Build a MIDI controller with an Arduino: The DIY MIDI Controller Workshop 2.0 - YouTube (timestamp 12:50)

I'm not having any problems with the routing from the Arduino device to a channel in Ableton, it's just that it isn't being communicated as midi (When the channel is armed in Ableton, I can even see it receive data when the sensor is triggered... just not midi data:/). Do you have any suggestions on this?
Thanks!

P.S. all the power to you for using Reaper. I tried it for a week or two and have a ton of respect for people who are proficient in it haha.

Hey a7. No I'm not receiving midi keystrokes, and yes I have a midi to Arduino interface ("hairless"). Please see my reply to Steve below for a more in-depth response.

I replied to you comment, but I guess I messed up in cc-ing you. Apologies. My reply is below

You don't need to cc anyone, just use the reply button and your response will be added to the thread. These are not private conversations. Users can see all replies,new posts etc.

I've never used Hairless but that looks like a speed mismatch. MIDI_CREATE_DEFAULT_INSTANCE(); creates a connection at 31250 the default speed for physical DIN MIDI connections but I think Hairless has a much faster default (115200? Look in there it will tell you). So you'll need to do it differently as described on the Hairless MIDI page (Google "MIDI.h hairless"), Note the MIDI.begin and Serial.begin(115200 or whatever) should be in setup() not called every time round loop().

Steve

Steve. Thank you so much. It now works! Words can't describe how happy I am. This was my first build. Truly. Thank you.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.