The Arduino Nano is a 45 × 18 mm board built around the ATmega328P (or ATmega4809 on the Every variant). Its 22 digital and analog I/O pins cover most sensor-logging and actuator-control scenarios without the bulk of the Uno. This guide walks through pin numbering, how pull-up resistors work in software, PWM outputs and a complete example that reads a push-button on D2 and dims an LED on D9.
Pin map on the Nano
The Nano exposes 14 digital pins (D0–D13) and eight analog input pins (A0–A7). D0 and D1 are shared with the hardware UART, so avoid them for GPIO work unless you have a second serial port available. D13 is connected to the onboard LED, which makes it handy for basic blink tests.
Pins marked with a tilde (~) on the silkscreen — D3, D5, D6, D9, D10, D11 — support 8-bit PWM via analogWrite(). The PWM frequency defaults to roughly 490 Hz on most pins and 980 Hz on D5 and D6.
- D2, D3 — support hardware interrupts (
INT0andINT1), useful for reading rotary encoders or counting pulses. - D10, D11, D12, D13 — the SPI bus (SS, MOSI, MISO, SCK), shared with the SD card and many display modules.
- A4, A5 — the I²C bus (SDA, SCL); also usable as analog inputs when I²C is not in use.
Internal pull-up resistors
Every ATmega328P GPIO pin has a software-selectable pull-up resistor of approximately 20–50 kΩ. Activating it removes the need for an external 10 kΩ resistor when wiring a momentary push-button. The logic is inverted: the pin reads HIGH when the button is open and LOW when pressed (connecting the pin to ground).
Enable the internal pull-up with:
pinMode(2, INPUT_PULLUP);
At Optimus Digital, a bag of 100 × 10 kΩ 0805 resistors costs around 3.50 RON. Skipping the external resistor is a practical saving on a breadboard build where pin count is tight.
Reading a push-button on D2 with interrupt
Polling digitalRead() in loop() works for slow signals, but attaching an interrupt to D2 (INT0) lets the MCU respond in microseconds and frees the main loop for other tasks.
volatile bool pressed = false;
void onButton() {
pressed = true;
}
void setup() {
pinMode(2, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), onButton, FALLING);
pinMode(9, OUTPUT);
}
void loop() {
if (pressed) {
pressed = false;
analogWrite(9, 128);
delay(500);
analogWrite(9, 0);
}
}
The FALLING edge fires when the pin transitions from HIGH to LOW — that is, when the button is pressed. Using volatile bool tells the compiler not to cache the variable in a register, ensuring the interrupt handler and the main loop see the same value.
PWM and LED dimming on D9
analogWrite(pin, value) sets the duty cycle of the PWM signal, where value ranges from 0 (always off) to 255 (always on). A 470 Ω series resistor in front of the LED limits the current to around 5 mA at 5 V, well within the Nano's 40 mA per-pin maximum. A bag of 100 × 470 Ω 0805 resistors is 3.80 RON at Elecpro.
For a smooth fade effect:
for (int brightness = 0; brightness <= 255; brightness += 5) {
analogWrite(9, brightness);
delay(30);
}
Analog inputs and voltage dividers
The analog pins use the ATmega328P's 10-bit ADC, which maps 0–5 V onto values 0–1023. The reference voltage is VCC by default (5 V on the standard Nano, 3.3 V on the Nano Every running at 3.3 V). To read a 10 kΩ NTC thermistor on A0 against a fixed 10 kΩ resistor:
float rawADC = analogRead(A0);
float voltage = rawADC * (5.0 / 1023.0);
float resistance = 10000.0 * (5.0 / voltage - 1.0);
The NTC thermistor is available at Robofun (reference NTC-B3950-10K) for 2.90 RON per piece. Combined with the fixed resistor and two wires, the total cost of this temperature front-end is under 7 RON.
Common wiring mistakes on the Nano
- Floating inputs. A pin configured as
INPUTwithout a pull-up or pull-down will pick up random noise. Always tie unused input pins to VCC or GND through a resistor, or enable the internal pull-up. - Exceeding the 40 mA per-pin limit. Driving a motor or a high-brightness LED directly from a GPIO pin will damage the ATmega. Use a MOSFET or a motor-driver IC instead.
- 5 V signals into a 3.3 V board. The Nano Every and Nano 33 families operate at 3.3 V. Connecting a 5 V sensor directly will exceed the absolute maximum rating (3.6 V on most pins). A two-resistor voltage divider or a level-shifter module (about 4 RON at Optimus Digital) is the correct fix.
- Missing decoupling capacitors. On breadboard builds, add a 100 nF ceramic capacitor between VCC and GND close to the Nano's power pins. It suppresses the high-frequency noise generated when the MCU switches outputs rapidly.
Further reading
The official Arduino Nano hardware documentation lists the full pinout diagram and electrical characteristics. The ATmega328P datasheet, available from Microchip, covers the ADC, timers and interrupt system in detail.
Related on this resource: connecting an ESP8266 to a Nano over software serial and using a Raspberry Pi as the central MQTT broker for a multi-node sensor network.