Skip to content

Measuring XBee signal strength from the RSSI pin

2010 April 7

In my thesis I wanted to read the signal strength of incoming packets and store it in a variable on a microcontroller without using the XBee’s API Mode (In API Mode, you construct packets to command the XBees explicitly, as opposed to just sending serial data in AT or “Transparent Mode”).  XBee modules have an RSSI (Received Signal Strength Indicator) pin that outputs a PWM signal representing this value.  But how do you turn that PWM duty cycle into a useable integer on your microcontroller?  Luckily Arduino has a function made for just this application: pulseIn.

  1. Connect the RSSI pin (pin 6) to a digital pin on your microcontroller.
  2. Use this line of code in your Arduino loop:
    rssiDur = pulseIn(digitalPin, LOW, 200);

pulseIn returns the duration of a pulse (specified HIGH or LOW) in microseconds (µs).  The 200 is a timeout value in µs—it waits this long to see if there’s going to be a pulse.  Since the XBee’s RSSI PWM period is 200µs, we want to wait at most that long to see if there’s a pulse at all.

Since this function gives you a duration, it’s up to you to map that to a value relevant to your program.  Since the maximum duration of the pulse would be 200µs, you could map that to your logical maximum.

Keep in mind that if you were planning on using API Mode anyway, every API Mode packet has the latest RSSI within it.

Related Posts:


  • Jerome

    Hello, I am doing on a project that require us to measure the distance. We thought of using Xbee to measure the signal strength whether it is high or low value.

    A question to ask if whether the Xbee signal strength is proportional to the distance between 2 Xbee module?

    Your attention is appreciated =)

    • http://www.liminastudio.com Tedb0t

      Generally speaking, yes, but there are many more factors than just distance. If you were in an empty void the signal strength would fall off according to the inverse square law. In reality, the signal will also be affected by reflections and transmission through different materials. We’ve found that XBee signal strength is not a reliable way to measure distance with any accuracy, but as a gestural approach, it works great.

  • Jerome

    Lets just say we are working in a clear line of sight without any obstruction and interference at about 10 feet (3 metre), would there be a significant difference in RSSI?

    Thanks for your attention

    • Ted Hayes

      In my experience, there would not be a significant difference, possibly not even a measurable difference, but I recommend you try it out. It also depends largely on the antenna type; chip antennas will be subject to more variation.

  • Victor

    hello guys.. how to compute RSSI? i look in to my AP and CPE.. rssi from the CPE is -65 den from my AP is -71..

    what i did is 100 – 71 = 29 on my AP
    100 – 65 = 35 on my CPE

    so meaning 29% is my signal strength from my ap and 35% on my cpe.. am i computing it right???

    thanks in advance guys for ur help =)

    • http://www.liminastudio.com Tedb0t

      Victor: No. RSSI is measured in dBm (decibels referenced by milliwatt).
      What are you trying to “compute?” Why not just use the values as-is?

      Jerome: In my experience, there would not be a significant difference, possibly not even a measurable difference, but I recommend you try it out. It also depends largely on the antenna type; chip antennas will be subject to more variation.

  • thothefali

    Dear,
    I’ve been playing with XBee Series 2 module tied to a microcontroller ATMEL89c52
    I have problem to measure PWM, I connect the PWM pin in my xbee series 2 with the (external interrupt & timer) pin in the microcontroller, I’m using assembly language.
    It would be great if u provide me some code samples for doing this.

    I will wait on ur reply
    I appreciate your prompt acknowledgment.

    Thanks

    • http://www.liminastudio.com Tedb0t

      Sorry, I’m afraid I don’t have any assembly skills ;)

  • http://www.p23.biz pete

    I just wanted to say thanks for posting this info. It would have taken me a lot longer to figure out how to do this. I got everything wired up and working. I am writing signal strength to an LCD screen, and it’s fun to walk around my house and see what my connection is.

    • http://www.liminastudio.com Tedb0t

      No problem! I’m glad you found it useful!

    • Danny Bertner

      could you share your example?

  • http://www.rehayurdakul.com reha

    Ted
    many thanks for this post. Really worked for my case (I was trying to measure dutycyle to estimate RSSI db) . Before this I tried interrupt (certainly digitalRead was too slow) and I was about to start look for solutions other then Arduino.. thank you again.. reha

    • http://www.liminastudio.com Tedb0t

      Awesome! Glad I could help!

    • Monsur

      Can you please explain the method of carrying this process out, will be much appreciated.

  • rik

    Hi I am only getting results between 0 – 40 milliseconds no matter how far I go away. I am using the standard 300 feet chip antenna xbee so I would expect to have decent measure between 0 and 200.

    Someone any ideas?

  • Mr. T

    Hi. I have questions on converting RSSI value observed on Pin6 to dB value.
    I’m using XBee Series 2 (ZB) connected to PIC18LF2553. It looks that I’m getting the RSSI values based on the 2400 count or 200us measurement.
    When I compare the RSSI measurements that I took using Pin6 based RSSI (%) and AT command based RSSI (dB), there are quite different. AT command based RSSI decreases as the distance between XBees increase as expected, but the pin6 based RSSI does not show the data in such way. If I measure the value for the distances from 3ft to 18ft with 3ft-increament, % decreases up to 6ft and increase to the same or greater than the value at 3ft and then decreases a bit. In other words, the measurements are something similar to thie: 3ft-49%, 6ft-28%, 9ft-48%, 12ft-35% 16ft-32%.
    The %s that I calculated are based on the duty cylce counts for the period of 2400 counts (200us), and the data I get is quite consitently follow such trend.

    Now one of my questions is that even at the distance of 3ft, RSSI % seems to be very low. If the value is converted to dB, it is about -85 where AT command based dB shows -40. Am I getting the correct counts for the duty cycle?

    When I check the value from pin6, up to 6ft, the one square wave had 2400 counts (high & low) in total but after that, one wave length became a half (1200 counts).
    Another question is that if I have to consider such change of the length in any ways or if I’m essentially not getting the right measurements?

    I hope someone can point me out to the right direction.
    Thank you in advance.

  • http://www.facebook.com/people/Ram-Kumar/100000557765994 Ram Kumar

    hello there… how can i measure the value of Rssi xbee in dbm using microcontroller(arduino uno) using xbee shield.. the output from pin six of xbee shield is 3.3v and when i give it to analog pin it shows 750′s value. As the distance change i get more zeros and few 750′s value. if i use your code and give it to digital it gives 60′s  and 50′s till 20′s according to distance. not dependable at all.. can you pls tell a way to get the RSSI in dbm using the microcontroller. It will help a lot. thank you.

  • Utaman

    Hello can provide full code..i had tried a month no matter how i tried also can nt get the result?

  • lokesh

    hey Tedb0t i want to know how one calculate rssi value using pwm siognal

    will u please explain in detail?