Wireless (XBee) Parkade Car Counter

Hello forum!

I’m working on a project that has multiple data sources which I am trying to send wirelessly to one location (see the image and the project information below). But I don’t know how to “ensure” that the data was received from the base station. I’ve been doing quite a bit of research however I don’t know if such a thing is possible with Serial communication. Could anyone point me in the right direction?

Thank you for your time and any assistance you can offer!


//// Project Information ////

What I’m up to is counting cars entering or leaving a parkade using pressure tubes (much like the ones you drive across occasionally on the highway) and an Arduino UNO as the microcontroller. When a car enters the parkade I need the XBee to take an integer value (say 1) and send it to the home base XBee. However to ensure that the data was received I need the home base XBee to then say “I received the data” in return and then have the sender to say “okay, it was received, I don’t need to send it again” (I’ve attached a picture for visuals :P)

It gets a bit more complicated when we add a second entrance/exit. Because now we have two sources of information and one place where it’s received. I am using XBee pro 900’s so I was thinking I could have XBee 2 send the information to XBee 1 and then have XBee 1 send it to the base station but this could be pretty problematic. Before I go any further, any advice?

//// Code ////

/* Author: David Penny + Jacob Berman
 * Start Date October 19, 2012
 * Project description: XBee Base Btation Code
 *        -----------------------------------                                       
 *    s      |              |                  p    
 *    t      |   <- tube    |   <-tube         a 
 *    r      |      one     |     two          r      
 *    e      |              |                  k   
 *    e      |              |                  a   
 *    t      |              |                  d       
 *        ----------------------------------   e
 *        Inputs: - integer values from serial communication
 *        Output: - after data is received, code sends back a value over serial to
 *                  to inform sender that the value was indeed received and that it
 *                  doesn't need to send it again.    

int carCount = 0;

void setup(){
  //Starts serial communications

void loop(){

  //Do nothing while you have no data
  while(Serial.available() == 0);

  //Remove the zero that is sent with serial code and convert to integer
  int data = Serial.read() - '0';

  //Add the value sent from serial to the current carCount
  carCount = carCount + data; 

  //Only reads the first character and flushes the rest that may have been sent over serial

  //write to serial the character r, to indicate that the data was received

  //Stability delay


When a car enters the parkade I need the XBee to take an integer value (say 1) and send it to the home base XBee. However to ensure that the data was received I need the home base XBee to then say "I received the data" in return and then have the sender to say "okay, it was received, I don't need to send it again"

The XBee itself takes care of sending the data again and again, until a number of tries has failed, or until it gets a "OK, OK, I got it!" from the destination XBee. I don't see that you are adding value.

I also don't see what the problem is, if you want to redundantly perform acknowledgement.

Before I go any further, any advice?

Yes. Get the XBee library that Andrew Rapp developed, and learn to use it. Sending data in API mode (which the library manages) means that each packet sent can be sent to a specific XBee, so the remote XBees can talk to the base XBee, and the base XBee can talk to just one of the remote XBees (at a time).

Also, Rob Faludi's "Wireless Sensor Networks" is an excellent resource.


I will look deep into it and report what I find.

Thanks for the speedy reply!

Regards, Dave

Hello! I’m back.

So I’ve taken a look at what you’ve suggested and have learned a bunch about API. Now my only question: is my XBee pro 900 compatible with the XBee library? I’ve been trying to get the two to talk (I have one XBee on a simple breakout board and the other on a explorer board), but they wont seem to work. I’ve gotten them to send tons of basic serial stuff very well. But not with the sketch below. I have a basic TM36 temperature sensor hooked up to pin5 on the XBee.

My two configurations are show in the pictures and I am indeed in API mode 2. :slight_smile:

Any tips?

Thanks again!

 * Copyright (c) 2009 Andrew Rapp. All rights reserved.
 * This file is part of XBee-Arduino.
 * XBee-Arduino is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * XBee-Arduino is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with XBee-Arduino.  If not, see <http://www.gnu.org/licenses/>.

#include <XBee.h>
#include <SoftwareSerial.h>

This example is for Series 2 XBee
 Sends a ZB TX request with the value of analogRead(pin5) and checks the status response for success

// create the XBee object
XBee xbee = XBee();

uint8_t payload[] = { 0,0 };

// SH + SL Address of receiving XBee
XBeeAddress64 addr64 = XBeeAddress64(0x0013a200, 0x40a25466);
ZBTxRequest zbTx = ZBTxRequest(addr64, payload, sizeof(payload));
ZBTxStatusResponse txStatus = ZBTxStatusResponse();

int pin5 = 0;

int statusLed = 13;
int errorLed = 13;

void flashLed(int pin, int times, int wait) {

  for (int i = 0; i < times; i++) {
    digitalWrite(pin, HIGH);
    digitalWrite(pin, LOW);

    if (i + 1 < times) {

void setup() {
  pinMode(statusLed, OUTPUT);
  pinMode(errorLed, OUTPUT);


void loop() {   
  // break down 10-bit reading into two bytes and place in payload
  pin5 = analogRead(5);
  payload[0] = pin5 >> 8 & 0xff;
  payload[1] = pin5 & 0xff;

  //send your request

  // flash TX indicator
  flashLed(statusLed, 1, 100);

  // after sending a tx request, we expect a status response
  // wait up to half second for the status response
  if (xbee.readPacket(500)) {
    // got a response!

    // should be a znet tx status            	
    if (xbee.getResponse().getApiId() == ZB_TX_STATUS_RESPONSE) {

      // get the delivery status, the fifth byte
      if (txStatus.getDeliveryStatus() == SUCCESS) {
        // success.  time to celebrate
        flashLed(statusLed, 5, 50);
      } else {
        // the remote XBee did not receive our packet. is it powered on?
        flashLed(errorLed, 3, 500);
  } else if (xbee.getResponse().isError()) {
    //nss.print("Error reading packet.  Error code: ");  
  } else {
    // local XBee did not provide a timely TX Status Response -- should not happen
    flashLed(errorLed, 2, 50);


BAH! When I was almost finished my post, I realized that I had my end device listed as a "Coordinator" and my Base Station as a "end device" (ie. they were backwards). Yet I thought I should post it since I know someone else may have the same problems (and since the internet is an awesome place to learn!).

Lessons learned: - XBee Pro 900's ARE compatible with the XBee libary (even if they are not explicitly labled as a Series 1 or series 2). - Double check your configurations. LOL.

Now to add and differentiate a second device!