Hi

I am trying to read my distance sensor using arduino from my IMU board. I have connected my sonar in the pitot tube port and I have writtten code to read from the sensor. However i do not know which pin I should use to read.

Anyone that can help me would be great.

Views: 369

Reply to This

Replies to This Discussion

Which arduino? or which board? On the 168/328P the I2C peripheral is fixed on pin 27/28 (SDA, SCL). http://arduino.cc/it/Hacking/PinMapping168

I am using the arduino AtMega2560. Here's the actual boards I am using:

http://code.google.com/p/arducopter/wiki/AC2Assembly

 

This is the code I am using but need to find the pin ?????

 

const int anPin = ?????;

long anVolt, cm;

void setup()
{
 Serial.begin(115200);
}

void loop()
{
  pinMode(anPin, INPUT);
  anVolt = analogRead(anPin);
  cm = anVolt * 2.54;
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  delay(500);

The title says I2C sensor... if your sensor speaks I2C protocol and if you've plugged it into an I2C port (SDA, SCL) then you'd need to use the Wire library to talk to it. 

What sensor brand/model is it?

It is a MaxBotix XL Maxsonar EZ MB1200. Here is the link:

http://www.maxbotix.com/products/MB1200.htm

Please bear with me this is my first time using this type of hardware.

Ok, a MaxBotics EZ0. I have played with the EZ1; same interface. It doesn't support I2C at all. It supports asynch TTL Serial, as well as Analog and pulse width timing.

Let's go back to the analog interface you were pursuing. You need to read an analog value from some pin. You don't know what pin name to use in your code.

On this page, you might notice that the left side of the IMU shield (below) has silkscreen labels on a row of otherwise unconnected pin header holes. I wonder what those labels say... (hint)

Analog (ADC) pins may sometimes be labeled ADCx or ANx where x is, say 0 thru 15. (hint)

Suppose you were to connect the MaxBotics analog pin (see datasheet pdf) to one of the exposed analog pins on the  board... In Arduino analog pins are also given names as you know. And you'd reference them as indicated when using analogRead()

Hope the hints help point you in the right direction.

I have tried using your 'hints' and i have written some code to go along with it:

int ADC0;

long anVolt, cm;

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  pinMode(ADC0, INPUT);
  anVolt = analogRead(A0);
  cm = anVolt/1024;
  Serial.print(cm);
  Serial.print("cm");
  Serial.println();
  delay(500);
}

 

Unfortunatley it still does not seem to work. I have cycled through all the analog pins 0-15 and I keep getting 0.

Try measuring output of sensor with a voltmeter between signal and ground...  Then measure hooked up to Arduino, measurement should be with range of sensor output...

I notice you're using ADC0 to set pinMode() but you're reading from A0.

Which analog pin is the EZ0 is plugged into on the blue board? What does the silkscreen label next to the pin say?

How is the sensor getting power?

I was still using the Pitot tube pins (They are on the right of the board in the picture you have provided). There is GND, +5V and IN. I also posted below

 

OK my bad I was using the wrong pins thats why my code wasn't working. I am going to go and solder on some header pins to the pins you have mentioned however where is the V+ 5V? All I can see is GND and the analog signal pins.

RSS

Contests

Season Two of the Trust Time Trial (T3) Contest has now begun. The third round was a reliablilty/aerial photography round for both planes and copters, which is now closed. Stay tuned for the next round, beginning soon.

A list of all T3 contests is here

 

© 2012   Created by Chris Anderson.

Badges  |  Report an Issue  |  Terms of Service