## arduino2max and maxbotix rangefinder

Oct 11, 2008 at 9:40am

# arduino2max and maxbotix rangefinder

I’m using a maxbotix ez4 utrasonic rangefinder, its sending signals to max using arduino2max and simplemessagingsystem, but I know very little about max and can’t get the variable signals from analogue channel 0 (a0, or a – zero) to
a) trigger sound playback
b)control sound playback volume

The question is – how do I get the numbers from the sensor to play sound and vary the sound in max when the proximity of the subject to the sensor changes?

I would appreciate some advice, I’m new to max/msp.

Thanks.

http://www.thingdom.com/docs/relayofjoy.html

#40283
Oct 12, 2008 at 1:44am

There are literally an infinite number of ways to take sensor information and create/affect sounds in max. Here’s a pretty simple idea:

Max plays a constant sine wave. The further the subject is from the rangefinder, the lower the frequency of the sine wave.

How do you make that happen in Max? Well, first you need to figure out the range of the numbers that your rangefinder is giving you. Since you haven’t told me, I’ll make up a range. Let’s say the rangefinder is giving you the distance to the subject in meters. Let’s say that it’s between 0-25 meters. Well, we need to scale that range so that we can use those numbers to control a [cycle~] object (which is the object that generates the sine wave).

Since the human audible frequency range is between 20-20000 Hz, let’s scale your distance range somewhere into the audible frequency range. If I multiply the distance in meters by 1000, then I would get a range of 0-2500. That range still doesn’t work because it includes numbers below 20. So, I’ll add 100 to it to make it between 100-2600. Perfect. Now, send those numbers into the left inlet of a cycle~ object, and voila.

If you build this patch successfully and try it out, you’ll notice that everytime the frequency of the cycle~ object changes, you get a nasty click. That’s because you’re trying to change the frequency of a wave instantaneously. If you want to get fancy and get rid of that click, try using a line~ object to smooth things out. See patch below and good luck:

– Pasted Max Patch, click to expand. –
#142330
Oct 12, 2008 at 6:19pm

Hello sweiser1

Thanks for your helpful reply. I am new to max, and intend to get some local help, I live in the UK. I have tried out your sample, and got some material on the Sensor. It operates at 42KHz, 6-inches out to 254-inches with 1-inch resolution. I am getting a reading varying from 12 closeup to 430 at about 4 metres. I get sound variation when connecting the ra0 values to line~ 100, but nothing from connecting to ~cycle.

I include below how far I am with it, if you could look at it I would be grateful.

Thanks!

– Pasted Max Patch, click to expand. –
#142331
Oct 13, 2008 at 1:52am

From my original patch, change the [* 1000.] to [* 10.]

Then, instead of connecting your [r a0] object to the [line~ 100] object, connect it to the left inlet of the [* 10.] object. The point of the * and + objects above the line~ object are to scale the data into a usable range so that you get a sound out of the cycle~ object.

#142332
Oct 13, 2008 at 4:27am

just a warning, when sharing ground between microcontrollers and your laptop
u can send it upsurge that will kill it.
“death by usb”
practice safe patching and connect your microcontroller via a usb hub for an
On Mon, Oct 13, 2008 at 3:52 AM, Scott wrote:

>
> >From my original patch, change the [* 1000.] to [* 10.]
>
> Then, instead of connecting your [r a0] object to the [line~ 100] object,
> connect it to the left inlet of the [* 10.] object. The point of the * and
> + objects above the line~ object are to scale the data into a usable range
> so that you get a sound out of the cycle~ object.
>

#142333
Oct 15, 2008 at 7:59am

Hello sweiser1

Thanks – its now working, and I am trying to play a sound (sound1.aif) instead of the cycle~ object, and control volume depending on proximity to the sensor. Any advice welcome – which objects should I begin with?

Thanks.

thingdom

#142334

You must be logged in to reply to this topic.