Built-in project · Arduino Nano

Nano dial

A potentiometer on the Nano's A7, the analog-only pin an Uno does not have, fades an LED on pin 9. The whole build, an Arduino Nano and 3 more parts, runs here in your browser on the firmware below; open it in the editor to change the wiring or the code and run it again.

BeginnerRuns in your browser. Free, and no account needed.

Nano dial · Arduino Nanolive0.000 s 0.00x
Click to open it in the editor
The circuit itself, running here on the simulator. Press what can be pressed; click anything else to open it in the editor.

The code

The firmware exactly as the editor opens it. Change a line there and press Run: it compiles in the browser.

sketch.ino · Arduino Nano
// Dial: a potentiometer on A7, the pin an Uno does not have, fading an LED.
//
// A7 is ADC channel 7. On the Nano's TQFP package it is bonded out as an
// analogue input with no port pin behind it, so it can be read with
// analogRead and nothing else: pinMode, digitalWrite and digitalRead ignore
// it, and there is no internal pull-up to switch on. That is the one thing
// this board has that an Uno does not, so it is worth a sketch of its own.
//
// Wire the potentiometer's two ends to 5V and GND and its wiper to A7. The
// LED goes on pin 9 through a 220 ohm resistor to GND; pin 9 is OC1A, so
// analogWrite gives it hardware PWM at 490 Hz rather than a software loop.

const int DIAL_PIN = A7;
const int LAMP_PIN = 9;

unsigned long lastReport = 0;

void setup() {
  Serial.begin(115200);
  pinMode(LAMP_PIN, OUTPUT);
  Serial.println("turn the dial on A7");
}

void loop() {
  // 0..1023 from the ten-bit conversion, 0..255 for the eight-bit PWM.
  int raw = analogRead(DIAL_PIN);
  analogWrite(LAMP_PIN, raw >> 2);

  unsigned long now = millis();
  if (now - lastReport >= 250) {
    lastReport = now;
    Serial.print("A7 ");
    Serial.print(raw);
    Serial.print("  duty ");
    Serial.println(raw >> 2);
  }
}

Parts list

5 parts, plus the jumper wires. Every one is in the editor's parts bin.

How it is wired

6 connections, pin by pin, read from the circuit itself. Each line is one set of pins joined together, by a jumper wire or a breadboard strip.

  • Ground: Arduino Nano pin GND; LED, yellow pin C
  • Arduino Nano pin 9; Resistor, 220 Ω pin 1
  • Ground: Arduino Nano pin GND; Potentiometer pin 1
  • Arduino Nano pin 5V; Potentiometer pin 3
  • Arduino Nano pin A7; Potentiometer pin 2
  • Resistor, 220 Ω pin 2; LED, yellow pin A

Change it and keep it

Open it in the editor, change the circuit or the code, and keep your version in a free account.