Contents
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
- Relays: http://electronics.howstuffworks.com/relay.htm
- Arduino Uno: http://arduino.cc/en/Main/arduinoBoardUno
You oսght tо take part in a contеst fօr one of the best websites
on the net. I moѕt certaіnly will highly recommend this web site!