LED switcher using a DPDT Relay and a potentiometer

🕒 < 1 m read

In this project, 2 LEDs will be switched on and off using the DPDT relay. (or flip-flopping the LEDs) This is another simple project to further explore the features of Arduino.

Overview

The potentiometer will help to set the duration (or delay) of when the relay is going to switch from the default circuit to the other circuit (or vice versa). This causes one LED to be turned on & the other LED to be turned off. This project uses the Arduino Uno board.

Demo

( If you are wandering what the clicking sound is, it is actually created by the relay switching circuits. )

Parts required

  • Arduino Uno x 1
  • Jumper Wires
  • DPDT Relay x 1
  • 330Ω resistors x2
  • 1K Resistor
  • Potentiometer x 1
  • Transistor
  • Diode x 1

 

Code

int led = 2;
int sensorPin = 0; // select the input pin for the potentiometer
int d = 500;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
   Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
   int sensorValue = analogRead(sensorPin);// read the value from the potentiometer:
   sensorValue = map(sensorValue, 0, 1023, 100, 1000);
      sensorValue = constrain(sensorValue, 100, 1000); // Constrain the potentiometer values
     d = sensorValue;
       Serial.println(sensorValue);
       
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(d);               // wait for d second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(d);               // wait for d second
}

 

Reference

Share your love

One comment

Leave a Reply

Your email address will not be published. Required fields are marked *