Most pins of a microcontroller are multi purpose. But they also each have digital input and output hardware, just like any other digital pin. For example: The analog pins can be used by the ADC (Analog to Digital Converter) to measure an analog voltage. In case you want to go deeper into the rabbit hole:Īctually the microcontroller has different hardware for different functions incorporated. As reference the numbers are also printed on the Arduino board itself. The Arduino way of counting the digital and analog pins just hides away complexity for the beginner. So internally we use a different counting system based on the pin function.
Arduino nano pinout digital in code#
But the internal code doesn't know, where the physical pins are located and the actual location can also depend on the packaging. TL DR: For building the circuit we must refer to pin positions (like where is Vcc, where is ground) to connect the chip/microcontroller correctly. For the code its just the third digital output hardware and so on.
![arduino nano pinout digital in arduino nano pinout digital in](https://www.etechnophiles.com/wp-content/uploads/2021/05/Arduino-Every-Pinout-in-detail.png)
Where that pin is physically located on the board isn't interesting for the code, nore does the code know the actual location. So D2 means the third digital pin inside the Arduino framework. Those are the numbers, that are normally written only the Arduino board. So for the convenience of beginners (which are targeted by the Arduino framework) the digital and analog pins are just numbered. On an Arduino you have mainly digital and analog pins, which can be controlled. So this counting only makes sense in the context of placing this specific package of the chip into a circuit (like where is Vcc, where ground and where do I need to connect to that specific digital pin), but makes no sense to use for the code inside the controller.įor referring to pins from inside the controller (aka in the code) we use the function of the pins. Each package has a different pin order and form factor. Also the microcontroller on the inside of its package doesn't know in which package it got stuck by the manufacturer. Those pins cannot be referenced by the code (wouldn't make much sense). This also includes special pins like Vcc, GND and Reset. The first way is only for referring to specific pin positions from the outside, for example when you are building the actual circuit. Referring to the pins by their function.
![arduino nano pinout digital in arduino nano pinout digital in](https://electropeak.com/learn/wp-content/uploads/2020/03/Arduino-Buying-Guide-Arduino-NANO-pinout.jpg)
Counting the physical pins in the order as they appear on the chosen package of the chip.Every chip datasheet (and also the Arduino boards) uses 2 different ways to refer to the pins: