send message thru xbee

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
jonmackie
 
Posts: 2
Joined: Sat Dec 17, 2011 4:05 am

send message thru xbee

Post by jonmackie »

hi guys.

i currently have this set up

arduino uno + xbee sparkfun shield + xbee

and

xbee + xbee adaptor connected to my PC


code as follows:

Code: Select all

#define THRESHOLD 100 // the threshold value
#define SENSOR_TIME 5000 // the amount of time (in milliseconds) that the sensor value has to stay below the threshold (or hold value)
int ledPin = 10; // The digital pin the LED is on
boolean triggered = false; // The "state" of the LED
unsigned long sensor_time; // The last millisecond that the sensor transitioned from being above the threshold and being below it (or the sensor's time stamp)
int sensorPin = 0; // The analog pin the sensor is on


void setup() { // Setup function
  pinMode(ledPin, OUTPUT); // Set the pin mode of the LED pin to output
  Serial.begin(9600); // Initialize the Serial port to a baud rate of 9600bps
}

void loop() { // Loop function
  int sensorValue = analogRead(sensorPin); // Read the value of the sensor

  if (sensorValue > THRESHOLD){ // If the value of the sensor is above the threshold value
    if (sensor_time == 0) { // If the sensor's time stamp hasn't been updated already
      sensor_time = millis(); // store the current millisecond into memory
    }
    else if (millis() - sensor_time > SENSOR_TIME){ // If the sensor's time stamp subtracted from the current millisecond is greater than the hold value
      digitalWrite(ledPin, HIGH); // Set the LED pin high (change to LOW for active low LEDs)
      Serial.print("THE BIN IS FULL");
        delay(10000);

      triggered = true; // Record that the LED has been triggered
    }
  }
  else {
    digitalWrite(ledPin, LOW); // Set the LED pin low (change to HIGH for active low LEDs)
    if(triggered) { // If the LED has already been triggered
      sensor_time = 0; // Reset the sensor's time stamp to 0
      triggered = false; // Reset the state of the LEDs triggered value
    }
    else {
      // Do nothing
    }
  }
}
both my xbees are configured properly.
but my problem i am facing now is that I cant get the xbee at the arduino to send the message to my xbee connected to the computer.

any advice?

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: send message thru xbee

Post by Franklin97355 »

How do you have the shield/xbee connected? I would think Serial.print would send data to the communications port on the uno and not to the xbee but I don't know how the sparkfun shield works. You might try their forums since the part is theirs.

HooctAwnFonix
 
Posts: 77
Joined: Tue Sep 13, 2011 11:47 am

Re: send message thru xbee

Post by HooctAwnFonix »

If you remove the Xbee shield and have a direct USB connection between Arduino and computer, do you get serial output?

If you do, your Xbee configuration must be off. If you don't, then it's your code.

Also, I had a lot of trouble when I was starting out with Xbee's because I wasn't always writing the configuration to the non-volatile memory by type ATWR when you're in +++ mode. If you neglect to do so and reset your Xbee (eg: take it from your Xbee adaptor and into your shield), then it won't be properly configured anymore!

Another tip is to look for the LED's - if your Xbee shield is transmitting there will be a blinking LED (I forget which one but I reckon its labelled RX). That way you'll know it's most likely your coordinator chip.

jonmackie
 
Posts: 2
Joined: Sat Dec 17, 2011 4:05 am

Re: send message thru xbee

Post by jonmackie »

hey guys
thanks for your reply.

i do get serial output when my arduino and computer is directly connected.

both xbees are configured properly already using xctu. i tried sending messages across to each other and it works.

however, when attached to my uno and sparkfun xbee shield. I have no idea why it doesnt work...
will uploading a pic of my set up help?

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”