Arduino - Potentiometer Triggers Relay
by DIYables in Circuits > Arduino
11 Views, 0 Favorites, 0 Comments
Arduino - Potentiometer Triggers Relay
This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://arduinogetstarted.com/tutorials/arduino-potentiometer-triggers-relay
This build uses a potentiometer to turn a relay on and off. Turn the knob past a set point and the relay switches, letting you control a light bulb, LED strip, motor, or actuator wired through the relay. It is a simple way to use an analog input as an on/off trigger for higher-power loads.
Supplies
Everything below is what the build uses. The links go to the parts we make and test.
- Official Arduino Uno
- DIYables STEM V3, Fully Compatible with Arduino Uno R3
- USB 2.0 cable type A/B (for USB-A PC)
- USB 2.0 cable type C/B (for USB-C PC)
- Potentiometer
- 10k Ohm Trimmer Potentiometer
- Potentiometer Kit
- Potentiometer Module with Knob
- Relay
- Breadboard
- Jumper Wires
- Solenoid Lock
- DC Power Jack
- Screw Terminal Block Shield for Arduino Uno
- Sensors/Servo Expansion Shield for Arduino Uno
- Breadboard Shield for Arduino Uno
- Enclosure for Arduino Uno
- Prototyping Base Plate & Breadboard Kit for Arduino UNO
- DIYables STEM V3 Starter Kit (Arduino included)
- DIYables Sensor Kit (18 sensors/displays)
Wiring
Connect the potentiometer's output to the Arduino's A0 pin. Connect the relay's control pin to Arduino pin 3. Power and ground the potentiometer and relay as required by their modules. Once wired, upload the sketch and rotate the potentiometer to see the relay click on and off.
How It Works
The Arduino continuously reads the analog value from the potentiometer on pin A0. That value ranges based on the knob's position. When the reading rises above a set threshold, the Arduino drives the relay pin HIGH, switching the relay on. When the reading drops back below the threshold, the relay pin goes LOW and the relay turns off.
Code
The sketch defines the potentiometer pin (A0), the relay pin (3), and an analog threshold value of 500. In setup, the relay pin is set as an output. In the main loop, the code reads the potentiometer's analog value and compares it to the threshold: above it, digitalWrite sets the relay pin HIGH; otherwise it sets it LOW. A separate version of the code converts the analog reading to a voltage value first and compares that voltage against a voltage threshold instead of a raw analog number.
arduino-potentiometer-triggers-relay.ino - the sketch from the tutorial, unchanged.
Full Tutorial
The complete tutorial, wiring diagram and code explanation: https://arduinogetstarted.com/tutorials/arduino-potentiometer-triggers-relay