Jump to content

Infrared distance sensor


Recommended Posts

By using the lpc17Core's analog inputs, it is possible to connect a sharp infrared sensor, so that the distance between the sensor and maybe a hand is converted to midivalues.

The sensor:

Sharp 2D120x f 9z

around 10 euro (Watterott)

size: appr. 5x1x1cm

operating voltage: 5V

output: analog voltage

range: 4-30cm

Minimal setup:

Lpc17Core with midio128v3.006

SDcard (to enable the Ain)

I bought and additional cable which fitted in the sensors plug. As the sensor requires 5V to operate, its ground and source are connected to

J2, with and 100nF capacitor to reduce jittering. The analog output is connected to an analog input of the core (Note: there is a version of

the sharp which has a digital output).



I used the distance to control a value in Traktor (by a hand), it worked well, except the highest 5% of the values are unreachable, but this is not so problematic on the first run. I could achive higher values by using something more reflective as my hand, a paper. The jittering is lower than I expected, the value jumps approximatly every 5 seconds. The area in which the sensor will work is about 10cm diameter at a distance of 30cm to the sensor.

I hope this is usefull to someone, I had a lot of fun playing around with it and will use multiple sensors in my (traktor-)midicontroller.

Greetings Geth

Edited by geth
Link to comment
Share on other sites

That looks like fun!

Such a sensor might slip into the cart, on my next order.

I always wanted a midi-out on my Alesis AirFX, but this might be a good alternative.

I recommend a CD as reflective object, it's great for fast LFOs, if grabbed on one edge and wobbled around.

Link to comment
Share on other sites

some information concerning your issue with the "unreachable upper 5%":

Ausgangsspannung: ca. 0.4V @ 30cm, ca. 2.7V @ 4cm

This information was extracted from the product description on watterot.com.

i am not familar with modifying core32 applications, but it should be possible to output the full range of midi values by doing a small mathematical error computation.

here is my idea:

the core32 ADC has a maximum range from 0 to 3.3 Volts, if i remember right.

therefore, the ADC has a gain of 3.3, offset is 0.

the output range of the IR sensor is 0.4 to 2.7 Volts.

IR gain is 2.3, offset is 0.4

In order to convert the captured real data into the expected range we have to write a small function which does the following calculation:

adcProcessed = (adcConverted -0.4) * (3.3/2.3)

i am not sure if a similar option is allready included into the code, i just wanted to share the general concept of dealing with this kind of problem (without the need of aditional electronic parts).

contra of this solution: reduces resolution.

Cheers, Nasrudin

Edited by Nasrudin
Link to comment
Share on other sites

hi, just a short update:

Concerning the jittering: When I played around today I found out that the jittering is greater (probably like an unused open pot) without the 100nF capacitor on the connection of the yellow and the grey wire, I guess I was to tiered for proper testing...

With this cap solderd back the jittering is gone again, but when I wait long enough it comes again, I suppose this is because the otherside is not connected to ground, I will test that when I have more time.

Thanks for the replies, I totally forgot to check the outputvoltages :frantics: . I will definitly go for the software-correction of the 5%-problem in the custom code of my controller, so thanks for your clear instructions.

By the way, it seems intelligent to me to add a switch to each infrared sensor, to prevent unwanted triggering.

Greetings Geth

Link to comment
Share on other sites

By the way, it seems intelligent to me to add a switch to each infrared sensor, to prevent unwanted triggering.

Hehe, yes. That's why i added a bypass switch to my AirFX. I don't know why Alesis didn't include it in the first place, it's so easy to trigger by accident.

Link to comment
Share on other sites

Hi, I found some time to check the sensor again.

So my current wireing is like this:

5+ Volt and ground from the sensor to J2 with a 100nF cap between them. And the sensor output to an Ain frome the core, with another 100nF cap between this and ground. Now the input is jittering, but this comes from the sensor, if I put my finger over the photodiode of the sensor, the jittering stops and the output drops to zero. The infrared LED seems to be very strong, because if I put my finger (directly) over the photodiode and the LED, the output has still one fourth of its maximum value.

So I will definetly use an additional switch to toggle this sensor on and of (otherwise mapping in traktor would be a pain), and recommend this to everyone else using this sensor.

Greetings Geth

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...