Distance sensor sharp 2Y0A02

hello i am a beginner in the arduino world. I want to work with distance sensors and max/msp. i installed my arduino board to my pc and it works as i tried the tutorials with led. now i am trying to install the distance sensor in the arduino and then to work with it in max.msp I tried by reading forums and tutorial but i haven't solve it yet. I have download the patch between arduino and max/msp. It seems quiet difficult to me and I would appreciate if you can help me by explaining me what is the best way to solve it out.

I am sorry by I don't know many things about programming so maybe my expessions are not technical. thanks

hi

you should break down the tasks into two stages:

  1. get the arduino talking to MAX, and
  2. get the sensor connected properly to the Arduino.

I’d suggest starting with the switch tutorial, and making that talk to MAX.

What software did you downlaod for the Arduino and MAX?

Non-technical language is OK here :slight_smile:

D

I have the Arduino2Max, a max patch and I changed also the serial port in the patch.
I do not have serial but a port, and i made the changes in device manager etc.

In the patch, in the serial port settings when i press print it appears : ( port d: com4:)
and when i press on the the button under it shows a signal.
is that mean that works? :-/

hi

there is an Arduino Sketch ( the file that ends in .pde) with the Arduino2Max package… that file has to be uploaded to the Arduino. Did you do that part yet? Just open it in the Arduino software, and program it into the Arduino.

D

i did that and i upload it, it has no errors i can see also that the board receive and transfer. (tx and rx lights) So now the arduino board is talking to max/msp.. i tried the patch and it works, the numbers in the analog pins are changing and also one digital pin. so the first step is done!?

hey

sounds like it is working... now you just need to connect the sensor. There is a datasheet for it here. If you look at the first page, the diagram shows that the pins, from left to right (with the pins facing you, and the sensing part pointing up) are:

Vo (connect to Arduino analog input)

Gnd (connect to Arduino ground)

Vcc (connect to +5V supply on the Arduino)

That's all it takes... let us know if it works.

D

yes i did that, and it in the max/msp patch it seems to work as the number in the analog pin changes and some digital pins.

that means that the sensor works? or I need another code for the sensor now? The max/msp recognize the sensor as a number is that right?

sounds like it's working!

D

sorry.. :-X yes but where can i see that number?

so I can use it in a patch?! i haven't found the number of the sensor. do i need another code for that? it seems to receive and transfer but i can't see if it is from the sensors.

make a receive object in Max, just type "receive a0" or "r a0" into an object box. Connect a number box to that and you will see the numbers. You might want to read the help file for the max patch-- just option click on the arduinoreader object.

D

:D I am pretty sure that now works. it gives me a number from almost 500 to 20.

how many sensors can i have to arduino board?! for example for the other sensors i will put the ground in the same one?! does the question make sense? really thx a lot.

hey

that is great that you got it working. You can put another five sensors wired the same way, one to each of the analog pins.

You can also connect two-state sensors like switches to the digital input pins. In fact you can also conect things like the Distance sensor to the digital input pins, but the Arduino will only recognize two states from it: at a certian point as you get close, it will flip from sending a "0" to sending a "1".

hope this helps

D