Sharp infrared proximity sensor sending MIDI

Hello dear friends,

I just bought a Sharp infrared proximity sensor 20-150cm and i want to use it to generate midi signal.
In sense of midi control, no note writing needed, i want to control filters or volume .
I already connected the sensor and it sends signal which is ok.I also found a program called Hairless MIDI, which should generally transform the byte signal from arduino serial port to MIDI.

I want to use it with Ableton live , however i still cannot really get the MIDI signal recognised in Ableton.

Does anyone have previous experience with this.
I use arduino uno .If i just want to send cc signal should i bother to install aruino midi library?

Thanks <3

:o :o :o :o

If i just want to send cc signal should i bother to install aruino midi library?

I wouldn't.

however i still cannot really get the MIDI signal recognised in Ableton.

Sorry I can't help on that one as I haven't got Ableton, but it is a matter fo configuration down stream of Hairless so not quite an Arduino problem.

Hello Mike,

I actually just figured it out.

I just enabled the IAC DRIVER as MIDI input in Ableton itself and now i receive MIDI from the Infrared proximity sensor via Hairless.

Which is great i didn’t bothered to install MIDI library and it works fine.

On the other hand I actually used one of your source codes i found on the forum just to test it and it works,
but it only triggers a certain parameter on or off.
I use only one sensor on analogue port0 i want to get the sensor to send values corresponding to the value the sensor gets by the movement or the proximity of the object towards it.

Can I please ask for some help on the coding, Im a musician I’m not really good at coding :slight_smile:

Here is the code uploaded:

// MIDI THEREMIN
// by Mike Cook
// v.1.0 03 March 2015
////////////////////////////////

#include <MIDI.h>
boolean playing = false;
const byte channel = 0;
const byte baseNote = 72;

void setup() {

  Serial.begin(9600); // MIDI Begin


}
 

void loop(){
  int av1 = 1027 - analogRead(0);
  int av2 = 1027 - analogRead(1);
  if(av1 <870 && av2 < 870){
     if(!playing)noteOn();
     else {
          trackNote(av2,av1);
     }
  }
  else {
    if(playing) noteOff();
  }
}

void noteOff(){
  playing= false;
  // note off + sustain off
  noteSend(0x80,baseNote,127);
  controlSend(64, 0);
}
void noteOn(){
 // note on + sustain on
  noteSend(0x90,baseNote,127);
  controlSend(64, 127);
  playing = true;
}

 void noteSend(byte cmd, byte data1, byte data2) {
  cmd = cmd | channel;
  Serial.write(cmd);
  Serial.write(data1);
  Serial.write(data2);
}

int trackNote(int freq, int volume){
  int pb = 0x2000 - (435 - freq);
  sendPB(pb);
  int vel = volume>> 3;
   controlSend(7, vel);
}

void controlSend(byte CCnumber, byte CCdata) {
  byte CCchannel = channel | 0xB0; // convert to Controller message
  Serial.write(CCchannel);
  Serial.write(CCnumber);
  Serial.write(CCdata);
}

void sendPB(int pb){ // send pitch bend message
  Serial.write( (byte)0xE0 | channel);
  Serial.write( pb & (byte)0x7f);
  Serial.write( (pb>>7) & (byte)0x7f);
}

So basically what that code does is to read one sensor to get the volume / note trigger point and once a not is triggered then it tracks the other sensor by sending pitch bend CC messages.

You don't want to do that you want to do something much simpler. You just want to read a sensor and send a CC message when it changes. Now do you want just a 7 bit data size on the CC or do you want to use two CC messages and combine them to give you 14 bits. ( well the A/D only gives 10 bits but you know what I mean.

This is something I just knocked up - no testing at all but it is the sort of thing you want. The "> 8" is by how much the reading has to change before you send another message.

byte CC1 = 32; // or what ever CC you want to send
void loop(){
  static int lastav1 = 0;
  int av1 = 1027 - analogRead(0);
  if(abs(av1 - lastav1) > 8) {
    controlSend(CC1, av1>>3); // >> 3 is a quick way of doing a divide by 8
    }
 lastav1 = av1;
}

void controlSend(byte CCnumber, byte CCdata) {
  byte CCchannel = channel | 0xB0; // convert to Controller message
  Serial.write(CCchannel);
  Serial.write(CCnumber);
  Serial.write(CCdata);
}

Thanks again.

Well now it constantly changes the value of the parameter even when the sensor is not triggered.

The value changes periodically , I will try to get into the code a bid.

But generally what i want to do is have 0% wet effect at 20 cm and wet 100% effect at 150 cm.

I will think about it a bit and will comment back once i figure it :)

Really appreciate your help :grin: :grin: :grin:

The sensor is always triggered, that is giving something. If you do not want this to happen and only want it to trigger when a certain level has been reached then include that in the if statement making it a compound if

if( abs(av1-lastav1) > 8 && av1 > 160 ) { // do stuff

Hello,

Well now i send some midi to cc5 but all it did is decreased my level to 0 and when i pull my hand back it won’t turn it up :o

Its q quite easy thing i want to do i just want to control the value of the parameter change according to the different distance the sensor gets… hmm will spend some time working around with that

Thanks its at least interesting to work on :3

#include <MIDI.h>
boolean playing = false;
const byte channel = 0;
const byte baseNote = 72;

void setup() {

  Serial.begin(9600); // MIDI Begin


}
 

void loop(){
  int av1 = 1027 - analogRead(0)
 
     }
  }
  else; {
 
  }


 
void noteOn(){
 
byte CC1 = 32; // or what ever CC you want to send
{
void loop();

  static int lastav1 = 0;
  int av1 = 1027 - analogRead(0);
  if( abs(av1-lastav1) > 8 && av1 > 160 ) {
    }
 lastav1 = av1;
}


void controlSend(byte CCnumber, byte CCdata); {
  byte CCchannel = channel | 0xB0; // convert to Controller message
  Serial.write(0xb0);
  Serial.write(0x5); 
  Serial.write( 0x7f);
}
}

Can you post the actual code that compiles and gives that fault you described. What you posted is just a nonsense.