Pololu Robotics & Electronics
My account Comments or questions? About Pololu Contact Ordering information Distributors

Pololu Forum

Arduino analog input pin receiving xbee pwm output

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. I get inconsistant voltages as I turn the transmitting pot.

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 the pololu motor controller VNH 5019 which I bought 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()

void loop()
  result = analogRead(val);

Thank you very much!

The volt meter, and your eyes, do filtering of the PWM output, turning it into an average analog voltage of the PWM duty cycle.
Similarly, your eyes act as filters for the LED, which is actually flashing very quickly.
The analog inputs on the AVR microcontroller run too fast, and sample either the “on” or the “off” part of the PWM signal. Thus, you’re seeing what is effectively aliasing in the sampling.

You need to add a filter when you connect the signal to the analog input. A simple RC filter should be sufficient. There is some trade-off between response time, and how much aliasing you still let through in the reading. I’d start by tying the PWM output to a 4.7 kOhm resistor, followed by a 1 microfarad capacitor tied to the analog input and ground. This should give a decent trade-off between responsiveness and noise (filter corner at about 34 Hz.)

HI Jwatte,
Thank you. I will give it a try.