Need help/tutorial for IR sensor.

Hi there does anyone know how I might go about getting this little guy http://www.coolcomponents.co.uk/catalog/product_info.php?cPath=36&products_id=312 to work with arduino and max msp?

for arduino to max/msp connection, check out arduino2max (google it and its the first hit). out of the box you'll have the arduino transmitting all analog and digital pins to max via the serial port.

for your particular sensor, you only need to connect it to ground, power and an input pin. to control the powering up of the device you can hook it up to a digital output pin.

for the input, because it is open collector, you'll want to enable the input pin's pullup resistor. This can be done by setting the pin as a digital input, and then writing a 1 to it (as you would to turn on an output pin). writing a 1 to a digital input enables the internal pull-up resistors.

and once everything is hooked up, all you need to do is create a loop that does the following:

  1. power up the sensor by writing a 1 to the output pin thats connected to the power.
  2. delay for 1-2 seconds
  3. read the input pin
  4. send the input pin value through the serial port to be read by max.
  5. turn off the sensor by writing a 0 to the output
  6. wait a bit?

rinse and repeat.

i'm sure there are more elegant solutions, but the above should work.

Hi thanks for your reply!

for your particular sensor, you only need to connect it to ground

It says this on the site about power which kind of confused me.

You can also install a jumper wire past the 5V regulator on board to make this unit work at 3.3V. Sensor uses 1.6mA@3.3V.

The arduino is 3.3v correct? So does this mean I have to install a jumper wire past the 5v regulator?... What exactly is this, and how do I do it?

I currently have the firmata firmware running on Arduino, with the maxduino software, which is letting me read and write to the pins.

My question here is you know the loop you describe below? Am I able to do that now in the Maxduino Patch? Or do I have to write this loop in Arduino? If at all possible I would like to stay away from Arduino since I dont have a clue how to program in it.

For example

  1. power up the sensor by writing a 1 to the output pin thats connected to the power.

Can I just send a 1 message to the output pin via max and would this be the same?

Many thanks for your help.

if you're using the arduino usb (Duemilanove/Diecimila), you'll have access to both 3.3V and 5V. for that sensor I'd use 5V (since 5V appears to be on the lower limit of what it takes... I'm not sure if 3.3V will actually work for this sensor).

edit i just re-read the docs. so the sensor takes anywhere between 5 and 12 volts externally, and has a 5V regulator built in which coverts to 3.3V. internally it operates on 3.3V. So what it means is if you have a 5~12V supply, you can hook it up to the external power pin and the onboard regulator will covert to 3.3V. If you only have 3.3V, you can hook it up directly to the board itself by jumpering the power input to bypass the regulator. 3.3V will not be able to power the regulator, but will be fine for the sensor itself.

as to the programming, if you can control the timing/loop etc on the MAX/MSP end - that would be ok as well - i imagine it wouldn't be too hard using metro/delay objects and toggle switches etc. I'm not familiar with firmata, but as long as you can read and write to the pins on the Arduino from MAX, it should be fine.