arduino attachInterrupt and parallax xband sensor
Moderators: adafruit_support_bill, adafruit

arduino attachInterrupt and parallax xband sensor

by jedihonor on Sun Mar 31, 2013 11:15 pm

Can someone please help me....

I have an Arduino uno r3, and just bought an xband parallax sensor ( ... r-v1.1.pdf)

I would like to learn how to use the attachInterrupt to read the pulses and wrote this code which seems to work but a little slow.

Code: Select all | TOGGLE FULL SIZE
int xbandTrigger = 0; // interrupt pin #2
volatile int pulse = 0; // count the # of times the incoming xband
                       // pulse changes from low to high
int oldpulse = 0;                       

void setup()
  attachInterrupt(xbandTrigger, count, RISING);
  pulse = 0;

void loop()

void count()

My questions. 1. Does the interrupt work in the background and counts the pulse on each rise, even while processing the print statement in the loop section? or on each rising pulse the program goes to the count() function, and when there is no pulse the program is allowed to print?

2. When there is no movement, how would I reset the pulse to 0?

Thank you

Posts: 8
Joined: Tue Oct 11, 2011 12:23 am

Re: arduino attachInterrupt and parallax xband sensor

by adafruit_support_bill on Mon Apr 01, 2013 6:09 am

We don't carry this sensor and are not familiar with its operation. Parallax should be able to answer your questions.

The interrupt should invoke your count() function on the rising edge of each pulse - as long as interrupts are not disabled. Serial.println is also interrupt driven, so it will process an interrupt per character. Given the low serial output volume, you shouldn't experience much interference between interrupts and pulse counts.
User avatar
Posts: 35015
Joined: Sat Feb 07, 2009 10:11 am