Wire logic high, multiple sensors.

Hi all,

I'm trying to get 6 Maxbotic sensors to work in daisy chain. I've been trouble shooting for a few days and can't seem to get things working. I have a thread here http://arduino.cc/forum/index.php/topic,65727.0.html from a few weeks back but thought I need to simplify my questions a little to see where my understanding is letting me down.

In the sechematic on this http://www.maxbotix.com/documents/LV_Chaining_Constantly_Looping_AN_Out.pdf wiring diagram it says wire BW to high. I understand why I need to do this, to set the sensor to pulse mode, but how do I do it? At the moment I have 6 wires connected from 5v on the arduino (via breadboard) to set the logic high.

So my question: Is there enough power in that set up to set all 6 BW on the sensor to logic high? If not what should I be doing?

Thanks a lot for any help.

The data sheet for the sensor will tell you how much current it draws. No link was given for the sensor, so, I don't know what that value is.

The data sheet for the Arduino will tell you how much current the +V pin can provide, assuming that the power source is up to the task. Generally, this is about 500 mA. If your sensors draw less than 80mA each, and they are the only things connected to the +V pin, then, yes the Arduino can supply enough current. If the sensors draw more then 80mA, or there is other stuff connected to +V, there is the potential for problems.

Ah sorry, datasheet is here http://www.maxbotix.com/documents/MB1010_Datasheet.pdf

The current draw is just 2mA typical, moving to 3mA at 5v so well within the capable limit of the arduino. The confusion for me comes from the fact that I'm also wiring the logic high on the "BW" of the sensors. Is this drawing current too, and if so how much?

In actual fact I have 12 wires coming from the 5v pin on the arduino: 6 to the Vcc of the 6 sensors and 6 to the "BW" of each sensor which needs to be written high to tell the TX to pulse. My best guess to date is that this isn't happening for some reason as the sensors seem to get a lot of interference from the others and rarely give an accurate read-out, especially not at long distances.

So the question now is, what would be the correct way to tie the "BW" pin high, I understood it was just through putting 5v into it, but is there a better way, especially given that I'm doing it 6 times?

The BW pin goes to a logic input pin on your module, it does not 'consume' any current worth mentioning. It's just used by the modules internal processor firmware to decide how to utilize it's data TX output. You are free to ground the BW pin to establish a constant logic LOW voltage or leave it unconnected to create a constant logic HIGH value depending on what mode you want the module to operate with.

Lefty

Ok, so does this wiring diagram, modified from the one in the maxbotic recommendation, look right? Bear in mind that I have six sensors.

http://twitpic.com/5s0yp9/full

If this is all right then perhaps I have to start looking at the code. I have been through and checked each sensor separately and all of them still work fine. The wiring appears to be good. I spent a lot of time getting the soldering precise.

Here is the code:

int ultraSoundSignalPins[] = {0,1,2,3,4,5}; // 2 Ultrasound signal pins 
int ultraSoundTriggerPin = 7;        // output pin to start Ultrasound signals 
int arraysize = 5;  //quantity of values to find the median (sample size). Needs to be an odd number
int rangevalue[] = {0, 0, 0, 0, 0};    //declare an array to store the samples. not necessary to zero the array values here, it just makes the code clearer


void setup() { 
   Serial.begin(9600); 
   printArray(rangevalue, arraysize);
   for(int i=0; i < 6; i++) { 
       pinMode(ultraSoundSignalPins[i], INPUT); // Switch signalpin to input 
   } 
   pinMode(ultraSoundTriggerPin, OUTPUT); // set this pin to output 
  //give the sensors time to boot up 
   delay(250); 
   // send RX pin high to signal to chain to ping 
   digitalWrite(ultraSoundTriggerPin, HIGH); 
   delayMicroseconds(30); 
   digitalWrite(ultraSoundTriggerPin, LOW); 
   pinMode(ultraSoundTriggerPin, INPUT); // electrically disconnects the pin 
   delay(50); 
} 
void loop() 
{ 
   unsigned long ultrasoundValue; 
   unsigned long echo; 
   delay(30); 
   for(int i=0; i < 6; i++) 
   { 
     
     for(int x = 0; x < arraysize; x++){
//Now the values from each sensor can be read: 
       rangevalue[x] = analogRead(ultraSoundSignalPins[i]); //Listen for echo 
//       Serial.println();
//       Serial.print("UltraSound Value");
//       Serial.print( ultraSoundSignalPins[i]);
//       Serial.print(  "= ");
//       Serial.print(ultrasoundValue);
          
   delay(30); 
     }
     
     
     
//     Serial.print("unsorted ");
//   printArray(rangevalue, arraysize);
//   Serial.println();
//   isort(rangevalue, arraysize);
//   Serial.print("sorted ");
//   printArray(rangevalue, arraysize);
//   Serial.println();
     
   // now show the medaian range
    int midpoint = arraysize/2;    //midpoint of the array is the medain value in a sorted array
	//note that for an array of 5, the midpoint is element 2, as the first element is element 0
     Serial.print("median range value for sensor ");
     Serial.print(ultraSoundSignalPins[i]);
     Serial.print(" : ");
     Serial.print(rangevalue[midpoint]);  
    Serial.println();  
   }
   
    Serial.println();
     Serial.println();  
  
} 

//*********************************************************************************
// sort function
void isort(int *a, int n)
		   //  *a is an array pointer function
{
  for (int x = 1; x < n; ++x)
  {
    int j = a[x];
    int k;
    for (k = x - 1; (k >= 0) && (j < a[k]); k--)
    {
	a[k + 1] = a[k];
    }
    a[k + 1] = j;
  }
}
//***********************************************************************************
//function to print array values
void printArray(int *a, int n)
{

  for (int x = 0; x < n; x++)
  {
    Serial.print(a[x], DEC);
    Serial.print(' ');
  }

  Serial.println();
}

Those blue lines to the analog pins need explaining. Are you wiring each board to a separate pin? The wiring diagram is less than clear.

If this is all right then perhaps I have to start looking at the code.

What is the problem? Are you not getting data from the sensors wired as in the diagram?

Hi again,

Yes, sorry blue lines were a little lazy, each AN from the sensor is going to a separate Analog pin on the board. So Sensor 1 is going into ANalog pin 0 sensor 2 into Analog pin 1, etc.

The problem is that I'm getting inconsistent results wired using the code and diagram shown.

If I wire one sensor up I get 200 as a consistent reading from the location where I'm set up. All sensors are close together and pointing the same way.

When I start with the set up with six sensors I get results like below, where one sensor gets something close to an accurate reading and all others are way off. This would seem to be consistent with interferance or noise from the other sensors, I'm just lost on where the problem is. It seems like the pulsing isn't working for some reason.

I would expect these results all to read somewhere around 200 from testing each independently.

median range value for sensor 0 : 184
median range value for sensor 1 : 99
median range value for sensor 2 : 99
median range value for sensor 3 : 101
median range value for sensor 4 : 41
median range value for sensor 5 : 33

median range value for sensor 0 : 166
median range value for sensor 1 : 101
median range value for sensor 2 : 99
median range value for sensor 3 : 101
median range value for sensor 4 : 43
median range value for sensor 5 : 33

median range value for sensor 0 : 155
median range value for sensor 1 : 99
median range value for sensor 2 : 99
median range value for sensor 3 : 99
median range value for sensor 4 : 41
median range value for sensor 5 : 35

median range value for sensor 0 : 169
median range value for sensor 1 : 101
median range value for sensor 2 : 99
median range value for sensor 3 : 94
median range value for sensor 4 : 41
median range value for sensor 5 : 33

median range value for sensor 0 : 183
median range value for sensor 1 : 99
median range value for sensor 2 : 99
median range value for sensor 3 : 101
median range value for sensor 4 : 41
median range value for sensor 5 : 33

median range value for sensor 0 : 178
median range value for sensor 1 : 101
median range value for sensor 2 : 101
median range value for sensor 3 : 101
median range value for sensor 4 : 43
median range value for sensor 5 : 35

Thanks again. Jimmy.

int ultraSoundSignalPins[] = {0,1,2,3,4,5}; // 2 Ultrasound signal pins

The 2 ultrasounds are connected to 6 pins? Are these digital pins or analog pins?

   for(int i=0; i < 6; i++) { 
       pinMode(ultraSoundSignalPins[i], INPUT); // Switch signalpin to input 
   }

Analog pins are INPUT only, so there is no reason to set the pin mode for them. As a result, the pinMode() function only applies to digital pins. So, you just set digital pins 0 to 5 as input, including the ones managed by the Serial instance.

All sensors are close together and pointing the same way.

Then you are getting interference. The output signal from one sensor is being read as the return signal by other sensors. Point the things in different directions.

Hi Paul,

That commenting is wrong (left over from when I had two). As mentioned, I'm now running six, I'll correct the comment.

I'll correct those analogpin mistakes now too. Perhaps thats the issue.

I'm aware that interference is probably the problem, the idea of the TX pulse is to eradicate this problem by pulsing the sensors on and off in a daisy chain as explained here: http://www.maxbotix.com/documents/LV_Chaining_Constantly_Looping_AN_Out.pdf .

If I get this right it's my understanding that I should be able to put them as close as I like, as each sensor pulses in sequence then passes that pulse on to the next. I understand the logic of this process but can't seem to get the results to match it.

If I get this right it's my understanding that I should be able to put them as close as I like, as each sensor pulses in sequence then passes that pulse on to the next. I understand the logic of this process but can't seem to get the results to match it.

I guess the way I saw it was that you needed to generate a pulse that triggered the sensors to do their thing, and store the result, that you could then read.

Pull the RX pin high on the first sensor for at least 20uS.

I don't see that you are doing this part.

Thanks again for the help Paul,

Pull the RX pin high on the first sensor for at least 20uS.

I don't see that you are doing this part.

Am I not doing that here

   // send RX pin high to signal to chain to ping 
   digitalWrite(ultraSoundTriggerPin, HIGH); 
   delayMicroseconds(30);

Youre definitely right about it storing a result which can then be read, but I think the pulse is telling it to only be active whilst it has a pulse. The way the results are often halfing through the sequence does seem to point at all the sensors reading the results of an initial pulse though.

Why are you declaring pin 7 to be an INPUT pin after pulsing it? The comment with the pinMode statement is not even close to correct.

I got the impression, perhaps mistaken, that the pin needed to be pulsed each time you wanted the sensors to do their thing, not just once.

Ah, as I understood it, it needs to be pulse once, then turned to input to electronically disconnect it and make the sensor perform a constantly looping daisy chain independent of the arduino, then just read it's most recent result on the analog.

Making a pin an input doesn't cause the Arduino to reach out and pull the wire connected to that pin. Unless you have additional hardware and an overloaded pinMode() function.

Since you appear not to be getting good results pulsing the pin once, it might be worth trying pulsing the pin each time you want to activate the sensors. One pulse, one reading from each of the 6 sensors. Another pulse, another set of readings...

hi jimmy...can you give me your code if now your project is ok???
I have some problem with this, can you help me??

thank you

hi jimmy...can you give me your code if now your project is ok???
I have some problem with this, can you help me??

thank you..