Arduino Nano - Potentiometer Relay
This tutorial instructs you how to use Arduino Nano and potentiometer to control relay. In detail:
- Arduino Nano determines if the potentiometer's analog value is above or below a threshold and act accordingly by turning the relay on or off
- Arduino Nano determines if the potentiometer's output voltage is above or below a threshold and act accordingly by turning the relay on or off
By connecting a relay to a light bulb, LED strip, motor, or actuator, we can use the Arduino Nano and potentiometer to regulate the light bulb, LED strip, motor, or actuator.
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 Relay and Potentiometer
If you are unfamiliar with relay and potentiometer (including pinout, operation, programming, etc.), 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, select the appropriate board and port.
- Copy the code above and open it in the Arduino IDE.
- Click the Upload button on the Arduino IDE to compile and upload the code to the Arduino Nano.
- Turn the potentiometer
- Check out the alteration of the relay's condition
Code Explanation
Check out the line-by-line explanation contained in the comments of the source code!
Arduino Nano Code - Voltage Threshold
The analog value of a potentiometer is changed to a voltage value. This voltage is then compared to a voltage threshold. If the voltage is greater than or equal to the threshold, the relay is triggered.