How to read two analog inputs from XBee series 2?

I would like to know how I can control the data from two analog in put in my XBee Series 2. I have a sensor that sends data using a LDR (AD0) and a LM35(AD2) temperature sensor. I do not know how can I get the correct analog samples from the LM35. The LDR data seems to be correctly but the second two bytes that belong to LM35 data are read wrong.

I think that when the XBee sends the I/O data frames (with two analog inputs) it sends first the two bytes from AD0 and then the two bytes from AD2. Should I control other bytes like analog channel mask?

Here I copy the wrong piece of code:

void loop()
// In API mode, the frame type is I/O data sample.So, if we have everything in the buffer
if (Serial.available() >= 23) {
// Looking the starter byte (0x7E)
if ( == 0x7E) {
//blink debugLED when data is received
digitalWrite(debugLED, HIGH);
digitalWrite(debugLED, LOW);
//We have already read the start byte and then we discard bytes we are not using (20 data bytes are discard).
//We want to read only analog data from the sensor.
for (int i = 0; i<20; i++) {
byte discard =;
// Copy analog samples
int analogHigh =; // data from LDR
int analogLow =; // data from LDR
int analogHighT =; // data from LM 35
int analogLowT =; // data from LM 35
analogValue = analogLow + (analogHigh256);
analogValueT = analogLowT + (analogHighT
miliV = (analogValueT*1200)/1024.0;
celsius = miliV/res;

Thank you in advance

Just to clarify,

Are you using only one arduino?
(arduino + xbee as receiver and sensors + xbee as sender?)
What shield are you using? Please attach link

I’m currently working on 3 XBees–1 coordinator and 2 routers.

I have a code to compute LM35 temp reading but I’m having some problem in the 64bit source address. I don’t know if I am the only one getting the wrong byte. If we can help each other, it will be great.

Yes, the configuration is exactly as you mentioned

I use the following XBee shield:

I could solve the problem yesterday. The code was OK but the analog input AD02 read wrong values of the temperature. Now my XBee pin configuration is AD12 and AD22 and other pin configured as digital (AD04) to place a LED indicator.

Maybe your problem is in the X-CTU configuration with the PAN ID or preparing the routers radio addresses. My next work will be with 2 XBeess as routers and 1 as coordinator.

You can attach the frame type to see the byte configuration and check possible errors.
Otherwise, I recommend you this book: Building Wireless Sensor Networks (maybe you would know about it).

Hm, We’re using the same shield.
How do you connect the shield to the router Xbee? Do you connect a power supply to the ICSP header or do you use an arduino to supply it–(bypassing the ucontroller)?
I use the latter.

I’m afraid the Xbee configuration is not my problem. I posted the XCTU config and code in the arduino forum but they can’t find the problem, that’s why I went here.

Also, I’ve read the book you recommended but got stuck on ch5 because I can’t use processing but want to pursue the “arduino + xbee as receiver and sensors + xbee as sender” connection.

I think we have the same problem because I can read values from the routers but the temp reading is also wrong–negative values.

Could you run this code and post the serial output? Let’s see if the packet matches your enabled pins.


void setup(){

void loop(){
if (Serial.available() &gt;= 21){
if( == 0x7E){
for(int i=1; i&lt;24; i++){
Serial.print(": ");


Serial.println(discardByte, HEX);

I also use the latter one (changing the jumper to XBEE position when I want to receive ‘data’). Finally, everything is OK and my GLCD displays the correct sensor values from the LDR and LM35.

If your XBee config. and arduino code works great, we can focus on physical aspects that belongs to the temperature sensor (LM35). Maybe the measure is wrong because of this stuff.

I recommend you two steps:

1- Trying the communication only between the coordinator and ONE XBee. You can add a simple debug code to check if you are receiving data (using digital PIN 13 in the Arduino board where a small LED is placed). If it is blinking it seems to be receiving.

int debugLED = 13;
if (Serial.available() >= 23)
if ( == 0x7E)
digitalWrite(debugLED, HIGH);
digitalWrite(debugLED, LOW);

2- Check the temperature sensor :

  • Using a multimeter you can check if the LM35 middle leg has correct values (10mv/C).
  • Add a 10 KOhm resistor in the middle leg to avoid bias current.
  • Right temp. conversion:
    miliVolts = (1200.0*analogSample)/1023.0
    celsius = miliVolts/10

Otherwise, I have run the code you posted and I have added to mine. I post the results obtained (it seems to be correct):

1: 0
2: 16
3: 92
4: 0
5: 13
6: A2
7: 0
8: 40
9: 8A
10: 1C
11: C6
12: F0
13: 24
14: 1
15: 1
16: 0
17: 8
18: 6
19: 0
20: 0
21: XX
22: XX
23: XX
24: XX
25: checksum

have you added some level shifting circuit between the two? The ADC input of the XBee is 0 - 1.2V where as your LM35 runs between 4 - 30V.

Could you please explain why such a circuit would be needed? LM35 according to the data sheet needs Vs input of 4-30V but does this mean that the analog output is at these values?