How to measure distance between two Xbee's ?

Hello everyone !

Firstly I want to apologize if my English isn't perfect yet, I'm French and already tried to post a message in the appropriate section but no one could answer my question, and I hope that it will have more answers here. :slight_smile:

So I'm going to ask it very quickly, then explaining in detail :

  • How to measure the distance between two Xbee's cards, which one being connected to an Arduino card ?

I was thinking about using the RSSI on the pin 6 of the Xbee, to exploit it later on (the signal strength is approximatively related to the distance between the two cards, I've seen that it can be very accurate on some videos).
But the problem is that I can't find any way to make it work, and videos are telling that it's possible to...

Knowing that I have this material at the moment :

  • 2 Xbee's
  • one Arduino Mega (I would like the RSSI to be workable by this card)
  • one Arduino Uno
  • one UartsBee usb/xbee adapter from Seeedstudio
  • one Xbee shield for Arduino from libelium (but it seems to be useless and "weird" to use)
  • wires and breadboard

In fact I have problems with configuring the Xbees with X-CTU and with the programs to enter in the different Arduino cards.

I've been searching a lot before asking here : I'm not able to follow the tutorials that explain how to configure Xbee's because they don't use the same adaptators as I do (and sadly I can't change it because it belongs to my school) and it changes a lot of parameters in X-CTU that I don't understand...

Also I tried another way : one arduino sends constant information through the Xbee (Serial.println("Junk")) and the other one is able to receive it and we can see on the adaptater that the led corresponding to RSSI is lit (meaning that it is connected to the other I imagine). But as I try to plug the 6th pin of Xbee (RSSI one) into a digital pin of the Arduino and to get its value with the appropriate function I think (pulseIn(pin, LOW, 200) -I saw on a webpage that we could use this one because RSSI acts like a PWM-), I can't get it to work again : it returns me either 0s or random numbers. So is there a certain way to plug it or is it just a direct cable between Xbee's pin and Arduino's one ?

The method I tried (but seems to be not working) is the following one :

I connect the first Xbee to the Arduino Uno with help of the libelium shield, letting default values in the Xbee (in X-CTU).
The code I enter in the Arduino Uno is this one :

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

void loop()
{
  Serial.println("Junk");
}

Nothing complicated, it should just send constant messages.

In the Arduino Mega this time, I used the usb/Xbee adapter to connect it to the Arduino Mega : I put its pins on a breadboard, then connect +3.3V and Gnd to the Mega (I don't need to retrieve the messages, only the RSSI : so I don't connect RX and TX) and connect the pin of Xbee corresponding to the RSSI to the digital pin 2 on the Mega, then enter the following code :

void setup()
{
  pinMode(2, INPUT);
  Serial.begin(19200);
}

void loop()
{
  int rssi = pulseIn(2, LOW, 200);
  Serial.print("RSSI : ");
  Serial.println(rssi);
}

On Baud 19200, it returns me : "RSSI : 0". What did I do wrong ?

So I would be very happy to get some help from you, even better could you explain me exactly what to do etc.
And also if you think that it's better to talk in real time, maybe we can exchange some Skype adresses.

So, thanks a lot and have a nice day ! :slight_smile:

Best regards, Thooto

There might be a problem with reading RSSI pin because arduino recognizes +5v as high, and xbee is a 3.3v device. You'll need to use a level converter to change 3.3v into 5.
On the other hand, I would suggest a bit different approach. RSSI pin is essentially a PWM output, so it is theoretically possible to put a RC filter there and read output as analog data. The higher RSSI - the higher value you'll read.
Another option would be to use API mode. In this mode XBee can sent it's RSSI value over serial port.

Keep in mind that RSSI is a poor measure of distance. The RSSI value is affected by many things. Distance is far down on the list of things that affect RSSI. Sunspots rate higher.

Hello, and thank you for your answers. :slight_smile:

I'm then going to try building a level converter or then if it doesn't work, try the second method you suggested to me.
The problem with API mode is that I don't know how to get it... i've watched a lot of tutorials but I don't understand how to make it work.

I agree with you that RSSI is a really bad way to measure distance :stuck_out_tongue: but actually in my project we didn't have to mind about the precision of the thing, it's part of a school project, and we are limited in time and if we don't build something that is accurate, it's not a problem. But the reason why I used Xbees is because I though it would have been easier to get that RSSI value and I've already been able to get it (only on my computer via X-CTU so that doesn't interest me) and I was surprised that only one centimeter changes the strength (what we want basically). Also I could ajust it before exploiting it etc.

So thanks again and have a nice day :slight_smile:

Thooto