What is this PIND command I have a code that reads the value of a sensor and because it needs to be very fast it does not use digitalRead but a strange form of reading. In the top of the code it shows:

#define IRSENSOR PIND
int irpin = 2;


I have no idea why this PIND referes to my arduino pin 2, but it only work if my sensor is in pin 2. If I want to change to pin 9 and only change the irpin varialbe it does not work. Why?

To read the sensor I use this code:

while (IRSENSOR &amp; (1 &lt;&lt; irpin )) {


Have no idea why this work. Does anyone know this kind of programming with arduino?
PIND refers to the arduino's IO register for input in port D

Without arduino, one has to refer to pins by specific bits in 3 different sets of registers for each port (PIN*, DDR*, and PORT*; B,C, and D). 

The arduino code makes it simpler to pick out a single pin by hiding all of this, but it does make reading a pin take much longer.

In the code, the specific pin is being selected by masking off all but the "irpin" bit in PIND, so changing irpin will pick a different bit and thus a different pin.

Pin 9 is actually bit 1 of port B, not D, so see if this works:

#define IRSENSOR PINB
int irpin = 1;


alternatly, using a reference instead of define,

volatile uint8_t&amp; IRSENSOR = PINB;
int irpin = 1;