Arduino Nano - Potentiometer LED
In a previous tutorial, We have learned how to adjust the brightness of LED based on the potentiometer's output value.
This tutorial instructs you how to use Arduino Nano and potentiometer to control LED. In detail:
- If the analog value of the potentiometer is greater than a threshold, Arduino Nano turns the LED on
- If the analog value of the potentiometer is lower than a threshold, Arduino Nano turns the LED off
- If the output voltage of the potentiometer is greater than a threshold, Arduino Nano turns the LED on
- If the output voltage of the potentiometer is lower than a threshold, Arduino Nano turns the LED off
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables.
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
Arduino Nano Code - Analog Threshold
Detailed Instructions
- Connect your Arduino Nano to your computer using a USB cable.
- Launch the Arduino IDE, choose the correct board and port.
- Open the code in the Arduino IDE.
- Click the Upload button in the Arduino IDE to compile and upload the code to the Arduino Nano.
- Turn the potentiometer
- Check out the alteration of the LED's condition
Code Explanation
Check out the line-by-line explanation contained in the comments of the source code!
Arduino Nano Code - Voltage Threshold
A potentiometer's analog value is transformed into a voltage value. This voltage value is then compared to a voltage threshold, which will cause the LED to be activated.