Arduino Forum

Using Arduino => Sensors => Topic started by: frondeur on Feb 26, 2011, 03:12 pm

Title: MaxSonar Chaining not working
Post by: frondeur on Feb 26, 2011, 03:12 pm
Hi,

I am trying to use 6 Maxsonar ez1 ultrasonic sensors chained in daisy chaining fashion working in constant looping. I can get the analog values which change with the change in sensor distance but the problem is that these values are incorrect. Even if i cover the sensor it still gives an output of 65mV which translates to 5.98inches. I am unable to figure out the problem. If there is anyone who can help, please jump in and give some suggestion.

Waiting for kind solutions.

Best Regards,
Rafid
Title: Re: MaxSonar Chaining not working
Post by: frondeur on Feb 26, 2011, 04:55 pm
anyone there?
Title: Re: MaxSonar Chaining not working
Post by: GrooveFlotilla on Feb 26, 2011, 08:37 pm
Any code here?
Any schematic?
Title: Re: MaxSonar Chaining not working
Post by: frondeur on Feb 26, 2011, 09:08 pm
I am using the standard wiring of 'daisy chaining' of Max Sonar sensors

http://www.maxbotix.com/uploads/Chaining_Application_Notes__AN_Output_Constantly_Looping_.pdf

and simple code, just for testing:

Code: [Select]
float an0 =0;
float an1 =0;
float an2 =0;
float an3 =0;
float an4 =0;
float an5 =0;

void setup() {
  pinMode(ledPin, OUTPUT); 
  Serial.begin(9600);
  digitalWrite(9,HIGH);
  delayMicroseconds(50);
  digitalWrite(9,LOW);
}

void loop() {
  // read the value from the sensor:
  //an0 = (analogRead(0)*(5000.0f/1024))*0.26;
//an1 = (analogRead(1)*(5000.0f/1024))*0.26;
//an2 = (analogRead(2)*(5000.0f/1024))*0.26;
//an3 = (analogRead(3)*(5000.0f/1024))*0.26;
//an4 = (analogRead(4)*(5000.0f/1024))*0.26;
//an5 = (analogRead(5)*(5000.0f/1024))*0.26;
an0=analogRead(0)*4.88/9.8;
an1=analogRead(1);
  an2=analogRead(2);
  an3=analogRead(3);
  an4=analogRead(4);
  an5=analogRead(5);
 
Serial.print(an0);
Serial.print('\t');
Serial.print(an1);
Serial.print('\t');
Serial.print(an2);
Serial.print('\t');
Serial.print(an3);
Serial.print('\t');
Serial.print(an4);
Serial.print('\t');
Serial.print(an5);
Serial.print('\t');
Serial.println(' ');

  delay(100);                 
}
Title: Re: MaxSonar Chaining not working
Post by: GrooveFlotilla on Feb 26, 2011, 09:37 pm
Quote
Even if i cover the sensor it still gives an output of 65mV which translates to 5.98inches

What is the minimum range of this particular sonar?
Quote
To do this, pull the RX pin high on the first sensor for at least 20uS. Then the micro controller will have to return it's pin to a high impedance state so that the next time around the TX output from the last sensor will make it's way to the RX of the first sensor
Title: Re: MaxSonar Chaining not working
Post by: frondeur on Feb 26, 2011, 10:16 pm
Well i dont think there is any minimum range limit for such sensors because i had used single of them in the past and they return 0 if thing is too close but here we are talking about 65mv which is almost 6 inches because scale of the sensor is 9.8mV/inch at 5V Vcc. Vcc is stable at 5.0V.

Yes i applied the 20us (also tried 50us,20ms,500ms) high on RX to start the loop in the 'setup' function and this is the reason they are working but incorrectly which is the problem.
Title: Re: MaxSonar Chaining not working
Post by: GrooveFlotilla on Feb 26, 2011, 11:29 pm
And the high Z state?
Title: Re: MaxSonar Chaining not working
Post by: frondeur on Feb 28, 2011, 09:45 am
what do you mean by Z-state?
Title: Re: MaxSonar Chaining not working
Post by: frondeur on Feb 28, 2011, 09:54 am
I have noticed another thing that might help in finding the problem. It doesn't care which digital pin i connect its strobe and keeps on behaving the same manner. It only stops working if i disconnect the RX of the first sensor but otherwise it works although it is extremely incorrect. It mean that it is getting something from the digital pins on which i am not even sending any information.
Title: Re: MaxSonar Chaining not working
Post by: frondeur on Feb 28, 2011, 10:24 am
it stops responding if i use 'pinMode(9,OUTPUT)' in the setup. So then to make it work i have to strobe repeatedly in the loop. but still problem remains. just this means that it needs a constant pulse which is strange.
Code: [Select]
void loop() {
  // read the value from the sensor:
  //an0 = (analogRead(0)*(5000.0f/1024))*0.26;
//an1 = (analogRead(1)*(5000.0f/1024))*0.26;
//an2 = (analogRead(2)*(5000.0f/1024))*0.26;
//an3 = (analogRead(3)*(5000.0f/1024))*0.26;
//an4 = (analogRead(4)*(5000.0f/1024))*0.26;
//an5 = (analogRead(5)*(5000.0f/1024))*0.26;
digitalWrite(9,HIGH);
  delayMicroseconds(30);
  //delay(100);
  digitalWrite(9,LOW);
an0=analogRead(0)*4.88/9.8;
an1=analogRead(1);
  an2=analogRead(2);
  an3=analogRead(3);
  an4=analogRead(4);
  an5=analogRead(5);
  // turn the ledPin on
  Serial.print(an0);
Serial.print('\t');
Serial.print(an1);
Serial.print('\t');
Serial.print(an2);
Serial.print('\t');
Serial.print(an3);
Serial.print('\t');
Serial.print(an4);
Serial.print('\t');
Serial.print(an5);
Serial.print('\t');
Serial.println(' ');
  // stop the program for for <sensorValue> milliseconds:
  delay(100);                 
}

Title: Re: MaxSonar Chaining not working
Post by: AWOL on Feb 28, 2011, 11:48 am
Quote
Then the micro controller will have to return it's pin to a high impedance state

Quote
it stops responding if i use 'pinMode(9,OUTPUT)' in the setup

Quote
what do you mean by Z-state?


No, "high Z state", aka "high impedance".
Title: Re: MaxSonar Chaining not working
Post by: frondeur on Mar 05, 2011, 12:40 pm
I have figured out that these sensors actually have a lower limit but still the chaining is not working. If i am not mistaken, in daisy chaining constant looping it should not need strobe again and again but if i just strobe it for 20us in the setup once then it doesn't work so i have to put 20us ping in the loop of the code. After observing the values of the sensor it seems as if it is still intercepting the signal from other sensors. e.g.
143.46   17.77     52.05   77.44    140.92   44.43   
143.46   17.77  49.51   77.44    77.44   44.43   
143.46   17.77  49.51   77.44    77.44   44.43   


sensor '5' seem to be picking the signal from sensor '4' because after series of 140.92 it receives 77.44 for some time.
Code: [Select]
void setup() {
  // declare the ledPin as an OUTPUT:
  //pinMode(ledPin, OUTPUT); 
  Serial.begin(57600);
  pinMode(9,OUTPUT);
 
  digitalWrite(9,HIGH);
  //delayMicroseconds(20);
  delay(250);
  digitalWrite(9,LOW);
  delay(250);
}
void loop() {
digitalWrite(9,HIGH);
  delayMicroseconds(30);
  digitalWrite(9,LOW);
delay(50);
an1 = (analogRead(1)*(5000.0f/1024))*0.26;
an2 = (analogRead(2)*(5000.0f/1024))*0.26;
an3 = (analogRead(3)*(5000.0f/1024))*0.26;
an4 = (analogRead(4)*(5000.0f/1024))*0.26;
an5 = (analogRead(5)*(5000.0f/1024))*0.26;
Serial.print(an0);
Serial.print('\t');
Serial.print(an1);
Serial.print('\t');
Serial.print(an2);
Serial.print('\t');
Serial.print(an3);
Serial.print('\t');
Serial.print(an4);
Serial.print('\t');
Serial.print(an5);
Serial.print('\t');
Serial.println(' ');
}


Title: Re: MaxSonar Chaining not working
Post by: marsangoa on Mar 06, 2011, 12:15 pm
Hi,
have you already try with one sonar?
Does it works?

Marsangola

Title: Re: MaxSonar Chaining not working
Post by: frondeur on Mar 08, 2011, 10:05 am
Thanks, yes i tried with the one sonar and it works. Even the chaining works but with errors like randomly one sensor stops responding and starts to give lower values. Really a pain to chain these sensors.
Title: Re: MaxSonar Chaining not working
Post by: frondeur on Mar 08, 2011, 11:20 am
Some sensors just stick to a certain value,  it is mostly around 30 (e.g. 38,29,32...). I am not sure what could be the problem. If there is any sensor defective then still it is not easy to figure out. I have checked the wiring also and it seems ok.
Title: Re: MaxSonar Chaining not working
Post by: AWOL on Mar 08, 2011, 11:22 am
Have you tried doing two readings per sensor, discarding the first?