Please Help! Motion Sensor to Audio On/Off

johnmcswain@gmail.com's icon

I'm terribly new at this. I'm trying to control something which should be very simple, I just don't know where to begin. I would like to have a song turn on and off by a motion sensor or sonar sensor or whatever works best. The distance, for now, is not important. Is there a Max/Msp script already written for this?

Further, what kind of sensor am I looking at? Can this be controlled by a normal security motion sensor? And can the audio be output by something as simple as an audio player on my laptop?

I've searched through threads and other sites and can't make much sense of it.

Thank you so much.

mzed's icon

Quote: johnmcswain@gmail.com wrote on Tue, 02 May 2006 13:36
----------------------------------------------------
> I'm terribly new at this. I'm trying to control something which should be very simple, I just don't know where to begin. I would like to have a song turn on and off by a motion sensor or sonar sensor or whatever works best. The distance, for now, is not important. Is there a Max/Msp script already written for this?
>

This is totally do-able. The MaxMSP end is trivial, and depends slightly on what harware you'll be using.

> Further, what kind of sensor am I looking at? Can this be controlled by a normal security motion sensor?

Yes. You have a ton of choices, so I'd need more information to help you decide.

What exactly do you need? Do you want to sense if somebody is in a specific place, or of they're in a general area? Can the trigger be walking though a doorway?

If you're totally new to this field, I would have a good look at the products by Making Things:

They sell a Passive Infrared Detector (that's the sensor in the security motion detector) and the necessary harware to make it speak to your computer. And they're nice people, who I'm sure could guide your purchase.

Also serch for sensor threads on this list, and look at Cycling '74's hardware products.

More information:

A security motion sensor will work. (also search for pyroelectric sensor). Some of the sharp IR sensors on this page:

are great, if you want to detect prescence in a defined area. There is an ultrasonic sensor there, too. Usually, those are more pricey than the IR sensors.

Then, you'll need a way to get the data into your computer.

The cheapest way would be to hack a game controller. You could use a $10 Logitech USB gamepad. If you were using a security motion detector, it is basically a switch. Wire that into one of the buttons on the pad, and you're in business.

You could hack a Playstation to USB interface:
http://www.radioshack.com/product/index.jsp?productId=203626 0&cp=&pg=1&origkw=usb+playstation&kw=usb+pla ystation&parentPage=search

Another alternative is a webcam. USB ones are adequate and cheap, or you could get a nicer one. Maybe you already have one. Then, you wouldn't need an interface. You would need software like Jitter (and cv.jit, which is free) or softVNS, which would be expensive for one project, but maybe a good investment.

And can the audio be output by something as simple as an audio player on my laptop?
>

MaxMSP has a bunch of ways to play audio. Email once you've got your harware together, and this is a simple patch. Or, check out the tutorials.

Or sign up for the sensor workshop I'm teaching this summer:
http://www.cnmat.berkeley.edu/Max_MSP2006.html

good luck,

mzed

generalh's icon
wippen's icon

The first two answers are very good already. I just want to add that you are looking down a well travelled path. For a few years now, I've been giving classes in the use of sensors with music and dance. In order to keep abreast of recent changes, I read what I can and do alot of searching in the internet. I am repeatedly delighted by what I find; there are alot of interesting people doing interesting things.

Short of writing a whole essay on how to connect electronics to a computer and get the information into Max/MSP, let me offer this tip:

There are two inexpensive ways to get switch and potentiometer information into Max/MSP. One is to buy a cheap joystick or gamepad (USB) and use the HI-object. Screw the device apart (when it isn't connected), use an ohmmeter to figure out where the negative and positive conections for each switch or potentiometer are and solder whatever external stuff you want to onto the circuitboard.

The other alternative is if you have a soundcard with a joystick-plug (remember those?). Look for a pinout diagram in Google. It will show you the positive connections for three (or four?) potentiometers and a number of switches and the ground (negative). The unfortunate part of this easy approach is that you may actually spend more money on the plug and wires than you would by buying a whole usb joystick.

You will be suprised how much fun you can have with a few light-sensitive diodes and an old joystick.

Dayton

snathan's icon

Hi, I have a similar question. I am interested in hacking a USB joystick to get data into Max. However, I would like to get data from distance sensors, which would be more complicated than just the on/off information mentioned in the previous post, right? One precedent I found was this::

...involving a whole world of technical expertise that I don't have. I feel capable of hacking a joystick, though. I guess I'm also a little unclear on how the sensors are powered. Is there a way to hack a joystick to get distance information from 4 sensors? And if not, any idea what my (cheap?) alternatives are? (I've looked at all the phidgets and arduino devices, but I still feel too uneducated to make the right choice). Thanks!

seejayjames's icon

--> Is there a way to hack a joystick to get distance information from 4 sensors? And if not, any idea what my (cheap?) alternatives are? (I've looked at all the phidgets and arduino devices, but I still feel too uneducated to make the right choice). Thanks!
----------------------------------------------------

I've gotten an analog ultrasonic sensor to work well via Arduino into Max, it was pretty easy once I got the Arduino side up and running. I think the Phidgets do some of this work for you by providing Max objects with their hardware, so that might be the way to go in this case. The sensor was about $20 and is good from about 1 foot to 15 feet, though with that low cost it's not totally precise... plus you have the "jittery data" problem which any analog signal will give you (there are a bunch of ways around it, but they take a bit of work).

snathan's icon

thanks seejay! i think between the two, i would probably choose the phidgets for ease (i am pretty new to this still). part of the reason i was hoping someone could comment on the joystick conversion is that i am currently living in shanghai, china. thus, it is a huge time and money hurdle for me to order anything from the states. plus there is the possibility of mail confiscation if the government thinks i'm trying to make a bomb or something stupid like that. also, usb joysticks are ubiquitous and amazingly cheap here. i would gladly sacrifice some degree of precision for cheapness/convenience at this point.

but assuming it isn't an option to use a joystick...what are the specifics of wiring sensors the the arduino/phidget boards? is there a website that would be informative about this? specifically, can i take the 4 ultrasonic sensors i already have from a car parking sensor kit and wire them directly to a phidget board? thanks for any help!

seejayjames's icon

-->
but assuming it isn't an option to use a joystick...what are the specifics of wiring sensors the the arduino/phidget boards? is there a website that would be informative about this? specifically, can i take the 4 ultrasonic sensors i already have from a car parking sensor kit and wire them directly to a phidget board? thanks for any help!
-->

Not totally sure, just check on the Phidget website, or send them an email. Probably most sensors work similarly, in other words, they send an analog voltage which corresponds to the distance. So this voltage is read by the internal ADC functionality (it reads the level by a kind of successive approximation per bit). The value is stored in one of 4 variables (for four sensors) and these can then be sent to Max via the digital out/serial out or whatever config the boards have. Then you've got your data and the fun stuff begins :)

snathan's icon

I have ordered an arduino board. Looking at this http://arduino.cc/en/Tutorial/Ping it seems that the sensor has both a 5V and ground wire. The sensors I have only have 2 wires, the 5V and signal. I am pretty inexperienced with electronics...does anyone know if this is going to be a problem? Also, could the example on that site be adjusted to contain 2 or more sensors instead of just the one? Obviously, there are multiple signal inputs, but only one 5V. Can this power multiple sensors? Thanks!

David Beaudry's icon

snathan@vt.edu wrote on Tue, 09 June 2009 18:24I have ordered an arduino board. Looking at this http://arduino.cc/en/Tutorial/Ping it seems that the sensor has both a 5V and ground wire. The sensors I have only have 2 wires, the 5V and signal.

It depends on the sensor. Some sensors have 3 wires, power, ground, & signal. This is the case with the "ping" sensor. A potentiometer would be another example (e.g. a volume knob). Some sensors have only two wires, in which case you need to set up a voltage divider:

Hook one wire up to 5V, the other wire you split into 2: one connects to the signal input on the Arduino, the other goes to a resistor then to ground. The trick is finding the right value for the resistor, which depends on the sensor. Basically you want your resistor to sort of fall in the middle of the range of resistance that your sensor produces. You can usually find this one in the specs, or even better, hook up a multimeter and measure yourself. What sensor are you using?

Quote: Also, could the example on that site be adjusted to contain 2 or more sensors instead of just the one? Obviously, there are multiple signal inputs, but only one 5V. Can this power multiple sensors? Thanks!

For many systems like this, all your sensors can use the same 5V, and within a given electrical system, all devices should use the same ground (called a common ground). The issue is current. Using a bunch of tiny sensors will be fine, but if you start using a bunch of sensors that require a lot of current (usually measured in milliamps for these types of applications), then you need to be careful and look into having more than one power source. I think the max on an arduino is 250mA? Anything higher than the stated max and you could fry your board. But again, most sensors don't require much, so this is more me being an alarmist.

Hope this helps some!

Cheers,
David

seejayjames's icon

David's comments should get you where you need to go, they're very good. Pretty much everything electronic uses current in some way, and to use current you need some sort of voltage drop or differential in order to have flow. Usually this is from the power source to the ground, but in many cases (like this one), you need a resistor between the sensor and the ground, to make the drop less severe. Messing this up could give you no readings, bad readings, or a fried sensor, so do read up on the numbers carefully, and err on the side of a more powerful resistor (less accurate but further away from frying). Online there are multiple places to find the details, and try to check several sources. You could also try hooking up an LED instead, using the outs, to get a feel for using (and reading the little bands on) a resistor on a device... so that if you fry it, it's pennies instead of the sensor cost. Or try a super-cheap sensor first, if you have some to spare. For testing you won't need to solder the resistor, just wrap it together and put a little electrical tape on the connection if you want. but do watch what it comes in contact with... that is, it shouldn't!

One other quick note, look into the difference between the specs for using USB versus an external power source. The Arduino can handle a certain amount of overall current, but this is considerably higher (I think) when using external power (battery pack or a wall-wort). So depending on what you're using, you may need to use this rather than the USB. And I'm sure you read that you shouldn't use a low-power USB port or a hub, for this reason... plus, power aside, hubs can make your serial data flaky, so avoid them for this reason too.

snathan's icon

Thank you both so much!

This is the product that I currently own:

I couldn't seem to find any specs on the individual sensors, only the system as a whole. I don't think these sensors are sold individually. The stamp on the sensors reads "ST810-1", but I can't find any additional info. Also, one wire is significantly fatter than the other. I figured the larger one was the 5V, but is that not so? I've become skeptical that I can make this work with these sensors, so I am also ordering a Ping))).

I'll take a second to explain my project. My idea was to create a sort of "urban density jacket" as part of my architecture thesis for next year. This would involve installing the 4 parking sensors on the front, back, left and right of a jacket which would roughly detect intrusions of the wearer's "personal space bubble". A max patch would register these readings in a graphical format using LCD. I already have a GPS sensor and have successfully finished a patch to track my movements around the city using (with my laptop in a backpack). I understand that this would not be very precise, but that's fine. Maybe you can think of some other unforeseen difficulties that may arise?

So if I can't get the cheap parking sensors to work, I know I can get it working with one Ping))). It wouldn't really give me what I want, but it would be a good start. Anyway, it will be a couple days before I get the arduino, although I wish I could start now... Thanks again for the help.

slatepipe's icon

hi

i just finished my degree project last week. i made a large interactive painting which housed 6 maxbotix ez4 distance sensors. i wired them all into an arduino and from used some downloadable code from the arduino site to read them and send the results into maxmsp (its called arduino2max), then i incorporated the results into my own max patch and it all ultimately worked very well.

it took a fair bit of work to develop the patch and get the sensors working properly (see some of my other posts on this forum) as when i started the project last year i knew almost nothing about max and the arduino. i had to improve my soldering skills too

if i can be of any help then ask away. ive asked plenty questions here and on other forums over the last year so it'd be good to give some advice back

snathan's icon

thanks for the help, slate! i think maybe one difference is that your sensors used the analog pins, and the ping requires a digital connection.

i believe my problem is that i am now having to upload two separate sketches to the arduino, which i guess can only house one sketch at a time? when i upload the ping sketch, the ping works great, and has a blinking LED, and streams distance data into the arduino interface. when i upload the arduino2max sketch onto the arduino board, the blinking and data streaming stop.

in the arduino2max max patch, when the ping sketch is uploaded, there is no response in max. when the arduino2max sketch is uploaded, the results are quite strange. the analog number boxes spew out random numbers, although there are no connections on the analog pins. Some of the digital number boxes lazily fluctuate between 0 and 1, but no response from pin 7, the only one in use.

while i don't really understand what's going on, i feel that in order to get this to work, i will have to somehow merge both sketches into one. i reckon this wouldn't be very difficult if i was familiar with the arduino language...does this sound feasible? any other possible explanations or solutions? thanks!