Arduino with Xbee Modules

Can somebody help me with a simple code. I want to read the serial data coming into a Arduino by way of a Xbee module and convert the received serial to a pwm on a digital output pin. Bassicaly im trying to send 0-5 VDC into one transmitter Arduino and get 0-5 VDC back out of the second receiving Arduino uning Xbee modules.

Bassicaly im trying to send 0-5 VDC into one transmitter Arduino and get 0-5 VDC back out of the second receiving Arduino uning Xbee modules.

Which XBees do you have?
How are they configured?
How are they attached to the Arduinos?
How is the sender sending the data?

Reading the data is easy once the above questions have been answered.

Thanks...

  1. I am using XBee-PRO ZB S2B modules.
  2. I have one module connected to a Arduino Uno board, i and using Xbee shields.
  3. I have the Xbee modules programmed and comunicating to each other just fine.
  4. I and using a poteniometer to input 0-5vdc on A0 of the transmitter Arduino. I am using this example http://arduino.cc/en/Tutorial/AnalogReadSerial.
  5. I can see the serial data coming into the receiving Arduino/xbee on the serial momitor.

I do not know how to read and convert this incoming information into a PWM output that comes out of a digital pin on the receiving arduino/xbee.

I do not know how to read and convert this incoming information into a PWM output that comes out of a digital pin on the receiving arduino/xbee.

So the sender is sending something like 560.

The receiver needs to use Serial.available(), Serial.read(), a char array, and in index.

Whenever there is data to read, read a character. If it is not a carriage return or line feed (\n or \r), add it to the array, increment the index, and store a NULL at the index position of the array.

If the char is a carriage return or line feed, use atoi() to convert the value in the array to a number, and write that to a PWM pin. Then, set index to 0 and write a NULL at the index position of the array.

Yes, what i see in the serial monitor is...
500
499
400
345
283
111
As i change the voltage input by turning the pot.
Do you know of any example code? I dont fully understand your response. I am just starting to work with coding. Thank you for helping.

In 11 minutes, you can't possibly have tried anything. What parts of my post didn't you understand?

Create a char array:

char inData[20];

Create an index:

byte index;

Test for and read serial data:

while(Serial.available() > 0)
{
   char inChar = Serial.read();
   if(inChar != '\n' && inChar != '\r') // If it isn't a cr or lf
   {
      inData[index++] = inChar; // store the char and increment the index
      inData[index] = '\0'; // add a null
   }
   else
   {
      int potVal = atoi(inDate); // Convert it to a number
      analogWrite(somePin, potVal/4); // Write to a pin

      index = 0;  // Reset index
      inData[index] = '\0';
   }
}