Pin not declared.

Hi,

Here the problem is, pin is not declared. Basically, now I am using Arduino Nano, and the pins are not 12, 11, 10 but D12, D11, D10. I don’t know why those pins are not declared. Below is the picture of Arduino Nano.

#include <Servo.h>

Servo Side, Up, Down, Forward, WL, WR;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
Side.attach(D12);
Up.attach(D11);
Down.attach(D10);
Forward.attach(D9);
WL.attach(D8);
WR.attach(D7);
}

Error Message:

Build options changed, rebuilding all
Receiver_Final.ino: In function 'void setup()':
Receiver_Final:17: error: 'D12' was not declared in this scope
Receiver_Final:18: error: 'D11' was not declared in this scope
Receiver_Final:19: error: 'D10' was not declared in this scope
Receiver_Final:20: error: 'D9' was not declared in this scope
Receiver_Final:21: error: 'D8' was not declared in this scope
Receiver_Final:22: error: 'D7' was not declared in this scope
'D12' was not declared in this scope

The boards uses 'D' to let you know its digital, and 'A' for analog.

Just use the number, like 11 not D11.

If you want to give them names, use defines or constants.

1 Like

You have to declare them yourself:

const byte D7 = 7;

But it is much smarter to name them for what they are actually connected to:

const byte PurpleLED = 7;

That is a big part of the reason they are not declared D0...Dx in the first place.