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:

22 Responses
  1. Jerome permalink
    October 5, 2010

    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 =)

    • October 6, 2010

      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.

  2. Jerome permalink
    October 25, 2010

    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 permalink
      July 14, 2012

      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.

  3. Victor permalink
    October 26, 2010

    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 =)

    • October 27, 2010

      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.

  4. thothefali permalink
    November 9, 2010

    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.


    • November 10, 2010

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

  5. July 12, 2011

    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.

    • July 13, 2011

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

    • Danny Bertner permalink
      October 28, 2012

      could you share your example?

  6. November 12, 2011

    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

    • November 12, 2011

      Awesome! Glad I could help!

    • Monsur permalink
      March 25, 2014

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

  7. rik permalink
    December 16, 2011

    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?

  8. Mr. T permalink
    December 23, 2011

    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.

    • Ana permalink
      March 17, 2016

      You can get the value in db? I appreciate your prompt acknowledgment. Thank you.

  9. April 4, 2012

    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.

    • liu permalink
      June 29, 2016

      I get some zeros when i change the distance,the far i’m going away,the more zeros i get.when the distance is within 2 meters,it did OK.Can you pls tell me why?Have you solved the problem of yours?And How?

      Thank you !

  10. Utaman permalink
    January 27, 2013

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

  11. lokesh permalink
    May 29, 2013

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

    will u please explain in detail?

  12. xoxo permalink
    November 11, 2015

    I am using Arduino Uno and i am trying to get the RSSI value from the frame at the rx side.
    My config is like this:
    TX —>> AT mode
    RX —>> API mode (XBEE in api mode)

    but at the rx side i don’t get what i send, i get some strange characters…so no way to get the RSSI from the beginning…since i don’t get the frame.

    Do you have any idea how to fix this?

Comments are closed.