Arduino Nano - Potentiometer fade LED
This tutorial instructs you how to use Arduino Nano to adjust the brightness of the LED based on the output of the potentiometer.
Hardware Preparation
Or you can buy the following kits:
| 1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Buy Note: Use the LED Module for easier wiring. It includes an integrated resistor.
Overview of LED and Potentiometer
If you are unfamiliar with LED and potentiometer (including pinout, operation, and programming), the following tutorials can help:
Wiring Diagram

This image is created using Fritzing. Click to enlarge image
Loose wires are a common cause of strange bugs. You can plug the Arduino Nano into a Screw Terminal Expansion Board for Arduino Nano and connect the wires to its screw terminals. This is how it looks with the screw terminal board:

This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Nano and other components.
How To Program
- Gets the value from analog pin A0, which is a range of 0 to 1023.
- Adjusts the brightness to a value between 0 and 255.
- Sets the LED connected to pin 3 to the brightness.
Arduino Nano Code
Detailed Instructions
- Copy the code above and open it with the Arduino IDE.
- Click the Upload button on the Arduino IDE to compile and upload the code to the Arduino Nano.
- Open the Serial Monitor.
- Turn the potentiometer.
- Check out the LED.
- Check out the result on the Serial Monitor.