Sending Data through Xbee+Arduino to PC


I have an application where I am using a MCP3421 18bit ADC to read analog data. The setup is Xbee+Xbee Sheild+Arduino + MCP3421 as Transmitter. This I am reading and transmitting to a remote xbee+arduino module with LCD. The data is displayed fine on the LCD. however I want to receive the data on the Serial port. When i try tp Do a Serial.println(s); on the receiving code the data which i get on serial port is garbled. Would appreciate any help

Here is my Code


#include  <Wire.h>
#define TRUE 1
#define FALSE 0
void setup(void)
  Serial.println(">>>>>>>>>>>>>>>>>>>>>>>>");  // just to be sure things are working


void loop(void)

  byte address, Hi, Lo, Config;
  int ADVal;

    address = 0x68;
    Wire.write(0x88);   // config register %1000 1000
    // /RDY = 1, One Conversion, 15 samples per, PGA = X1


    Wire.requestFrom((int)address, (int) 3);
    Hi =;
    Lo =;
    Config =;

    ADVal = Hi;
    ADVal = ADVal * 256 + Lo;

    Serial.print("<"); // Sending a marker for value start
    Serial.print(">"); // sending a marker for value end


and this is the receiving code

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // initialize the library with the numbers of the interface pins
bool started = false;
bool ended= false;
char inData[10]; // Leave plenty of room
byte index;
float i;

//char inData[24]; // Or whatever size you need
//byte index = 0;

void setup(){
  // set up the LCD's number of columns and rows: 
  lcd.begin(16, 2);
  // initialize the serial communications:

void loop()
  while(Serial.available() > 0)
    char aChar =;
    if(aChar == '<')
      // Start of packet marker read
      index = 0;
      inData[index] = '\0'; // Throw away any incomplete packet
      started = true;
      ended = false;
    else if(aChar == '>')
      // End of packet marker read
      ended = true;
      break; // Done reading serial data for now
      if(index < 10) // Make sure there is room
        inData[index] = aChar; // Add char to array

        inData[index] = '\0'; // Add NULL to end


  // When we get here, there is no more serial data to read,
  // or we have read an end-of-packet marker
  if(started && ended)
    // We've seen both markers - do something with the data here
    i = atoi (inData);
    float s = (i * 0.3051851); //multiplying with calibration factor
    float value = ( s / 1000 );

    lcd.print(value,3); // print value after multiplying with calibration factor to LCD

    lcd.setCursor(0,1 );
    lcd.print(i); // Print raw ADC counts as recieved from transmitter

    index = 0;
    inData[index] = '\0';
    started = false;
    ended = false;

What I am doing here is reading the MCP3421 on I2C bus and transmitting the raw counts. with a start and end marker as This on recieving I am parsing to DATA enabling me to reject and incomplete data value .


however I want to receive the data on the Serial port.

I don't understand the "however" part of this. The receiving Arduino does get the data from the Serial port, thanks to the XBee putting it there.

When i try tp Do a Serial.println(s); on the receiving code the data which i get on serial port is garbled.

So, you want to talk to the PC and the XBee on the same phone line? How is the XBee to know that you aren't talking to it? How is the PC to know that you aren't talking to it?

Garbled how? Does opening the Serial Monitor affect what is displayed on the LCD? If not, the problem is not with the serial data. It is with the configuration of the Serial Monitor (mismatched baud rate).

Hello Paul,
Thanks for looking into my problem. I think I was not very clear in explaining. So here it is again . The receiving arduino do get the data through Xbee and it displays values perfectly on the LCD( Attached PIC). I also need to receive the data on a PC attached to the receiving arduino through its USB/Serial port.

When i try to use the serial monitor the display on LCD vanishes and the serial monitor displays garbled values. I thing the Serial.print(s) is sending back the data to the XBEE as both the DO and DI LED starts blinking on the XBEE SHIELD.

You are right the Xbee don’t know the PC is talking to it. Unfortunately my coding is very primitive and I do not know how to do both the things at the same time, ie receive data and display on LCD as well as put data out for PC to read it .

I have used X-CTU to configure both the Xbees to 9600 Baud rate.