Port Registers: Where is PIND defined?

My hardware:

Intel Edison
IR (Infrared) Receiver Sensor - TSOP38238 (AdaFruit product id: 157)

My software:

Arduino IDE 1.6.9

I've been working through the AdaFruit tutorial:

I downloaded the their sample code from:

When I compile rawirdecode the first compiler error is:

rawirdecode:20: error: 'PIND' was not declared in this scope
#define IRpin_PIN PIND

The folks at AdaFruit directed me to:


which says:

"Each port is controlled by three registers, which are also defined variables in the arduino language. "

Looking at:


I see HIGH and LOW, for example, but I don't see port register variables.

Question: Where is PIND defined? Do I need to include another file?


which board are you playing with (which arduino)?

because in the link you give

Arduino - PortManipulation it is stated:

PORTD maps to Arduino digital pins 0 to 7

DDRD - The Port D Data Direction Register - read/write
PORTD - The Port D Data Register - read/write
PIND - The Port D Input Pins Register - read only

nothing special to do

It’s the name of a register, it comes from the part-specific files that come with the compiler. If you are compiling for a chip that has a PIND, it is already handled and will be defined when you use it, nothing needs to be included.

You’re getting that error because you’re trying to compile a sketch which directly uses the PIND register for a microcontroller that does not have a PIND register (that is, it either is not an AVR, or is an AVR that doesn’t have a port D - PIND is the input register for port D).

If you’re compiling it for an AVR, you can select a pin on another port to use, and adapt the code to use the PIN/PORT/DDR registers for that port instead.

If you’re compiling it for something that isn’t an AVR, you will need to rewrite that code to work with that architecture.

actually re-reading what you said, a #define cannot cause an issue.

did you copy/paste from the PDF? if so verify that no line of code got stuck into the comments

I tried and at first the parser was failing and then once I had cleaned things up, the parser was fine with the code.

give it a try

/* Raw IR decoder sketch!
  This sketch/program uses the Arduno and a PNA4602 to
  decode IR received. This can be used to make a IR receiver
  (by looking for a particular code)
  or transmitter (by pulsing an IR LED at ~38KHz for the
  durations detected
  Code is public domain, check out www.ladyada.net and adafruit.com for more tutorials!
// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
//uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN PIND
#define IRpin 2

// for MEGA use these!
//#define IRpin_PIN PINE
//#define IRpin 4

// the maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000

// what our timing resolution should be, larger is better // as its more 'precise' - but too large and you wont get // accurate timing
#define RESOLUTION 20

// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2]; // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing

void setup(void) {
  Serial.println("Ready to decode IR!");

void loop(void) {
  uint16_t highpulse, lowpulse; // temporary storage timing
  highpulse = lowpulse = 0; // start out with no pulse length
  // while (digitalRead(IRpin)) { // this is too slow!
  while (IRpin_PIN & (1 << IRpin)) {
    // pin is still HIGH
    // count off another few microseconds highpulse++;
    // If the pulse is too long, we 'timed out' - either nothing
    // was received or the code is finished, so print what
    // we've grabbed so far, and then reset
    if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
      currentpulse = 0;

  // we didn't time out so lets stash the reading
  pulses[currentpulse][0] = highpulse;
  // same as above
  while (! (IRpin_PIN & _BV(IRpin))) {
    // pin is still LOW
    if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
      currentpulse = 0;
  pulses[currentpulse][1] = lowpulse;
  // we read one high-low pulse successfully, continue!

void printpulses(void) {
  Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
  Serial.println("\n\r\n\rReceived: \n\rOFF \tON");

  for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses[i][0] * RESOLUTION, DEC); Serial.print(" usec, ");
    Serial.print(pulses[i][1] * RESOLUTION, DEC); Serial.println(" usec");
  // print it in a 'array' format
  Serial.println("int IRsignal[] = {");
  Serial.println("// ON, OFF (in 10's of microseconds)"); for (uint8_t i = 0; i < currentpulse - 1; i++) {
    Serial.print("\t"); // tab
    Serial.print(pulses[i][1] * RESOLUTION / 10, DEC); Serial.print(", ");
    Serial.print(pulses[i + 1][0] * RESOLUTION / 10, DEC); Serial.println(",");
  Serial.print("\t"); // tab
  Serial.print(pulses[currentpulse - 1][1] * RESOLUTION / 10, DEC); Serial.print(", 0};");

The board is an Intel Edison based board (see opening post). OP, you might be better of at Home - Intel Communities

Oh, somehow I missed that it's an Edison.

But if that's the case, it's a totally different architecture - direct port manipulation will use different registers. It may or may not be a simple change - it could be as simple as a different register, or it could be more complicated.

Try the Edison forum for more information - it's not an official arduino board, so you may not get much information out of these forums - most of us here work primarily with the AVRs, and to a lesser extent the SAM ARMs.

Based on all of your input, I will now guess that the Arduino "compatible" board, that the Intel Edison is plugged into, is not EXACTLY the same as an Arduino R3 Uno.

I didn't copy/paste the code from the PDF. I used their github link and downloaded it from there. The github version is almost the same as that in the PDF. The difference is the PDF version has some commented out lines about MEGA.

My investigation path began at AdaFruit where I bought the infrared sensor. They pointed me to Atduino:

My next stop WILL be the Intel Edison forum.

I thank all of you for your feedback.