Arduino analog input reading xbee pwm signal

Hi.

I want to read the voltage of the transmitting xbee connected to a pot, that is sent to the receiving xbee connected to a logic level converter to the Arduino. I am using two xbee series 1 modules in transparent mode, and one arduino rev 3. A pot is connected to the transmitting xbee. The arduino is connected to the receiving xbee. I have a logic level converter between the arduino and xbee.

Everything works great if I use an LED connected to the receiving xbee instead of the arduino. Wirelessly The LED dims and brightens as expected. I also can measure the voltage with a volt meter and can read 0 to 5 volts on the receiving xbee pwm output. Everything changes when remove the LED connected directly to the receiving xbee, and attach the PWM signal from the receiving xbee to the ardino analog input.

My wild guess is that the arduino analog input is sampling the xbee pwm output, and perhaps the PWM frequencies diferences are causing problems? If so How would I correct this. Ultimately I would like to make use of a motor controller and build my first robot. This is my beginning. I am learning API and xbee, but it seems the transparent mode is simpler.

My code:

float val = 0;
float result = 0;


void setup()
{
  pinMode(val,INPUT);
  Serial.begin(9600);
}

void loop()
{
  result = analogRead(val);
  delay(100);
  Serial.println(result/4);  // gives me 0 to 255 in prep for analog write to a motor controller
  
  delay(500);
}

Thank you so much for your help.

Scott

The PWM signal is a rectangular wave signal that repeats itself. This may look like an analog signal on a LED, because your eyes are working like a filter. The Arduino analog input pin doesn’t have that. All it reads is a signal that is either high (whatever voltage comes out of the logiclevel converter) or low (something near GND).

To input a true analog signal into the Arduino input you need to insert a lowpass filter. The simplest form is a resistor in between, with a capacitor to ground behind it. The product of resistance and capacitance determines the timeperiod/ frequency cutt-off point. Which should be below the period of the PWM repetition rate. (around 15 kHz, or 66 microseconds iirc)

I’m sure there are other Lowpass filtering PWM tutorials on the net though, that can better explain it than me.

Valen,

Thank you. I will try a low pass filter.

Scott

Hi

Sorry, but i will try the same onyl with the xbee’s and a led. but the led remains on, nothing happens when i change the value of the poti.

but i can see on the x-ctu terminal window of the rx xbee the value changes from tx xbee. the led goes off when i disconnect the power of the tx xbee.

plase can you give me a little hint?

thanks

pat