A Relay is a electronic operated switch, relay’s uses an electromagnet mechanical to operate the switch and provide electrical isolation between two circuits. Is this lab project we don’t need to isolate one circuit from other, will going to use ARDUINO UNO to control the 5v Relay. will going to make a simple circuit to demonstrate & identify the NO(Normally Open) and NC(Normally Closed) to the terminal of the relay.
Electronic Parts Required
- 1x 14Core Arduino Uno Compatible / Arduino Uno R3
- 2x 220 Ohm Resistor
- 1x 1-4 Channel Relay Module
- 2x LED
- Jumber Wires
Connections:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
/* Plug the 5V on Arduino to VCC on Relay Module Plug the GND on Arduino to GND on Relay Module Plug the GND on Arduino to the Common Terminal (middle terminal) on Relay Module. */ #define CH1 8 // Plug the Digital Pin 8 on Arduino to CH1 on Relay Module #define CH3 7 // Plug the Digital Pin 7 on Arduino to CH3 on Relay Module #define LEDgreen 4 // Plug the Digital Pin 4 on Arduino to Green LED (+ 220 ohm resistor) and then to "NO" terminal on relay module #define LEDyellow 12 // Plug the Digital Pin 12 on Arduino to Yellow LED (+ 220 ohm resistor) and then to "NC" terminal on relay module void setup(){ //Setup all the Arduino Pins pinMode(CH1, OUTPUT); pinMode(CH3, OUTPUT); pinMode(LEDgreen, OUTPUT); pinMode(LEDyellow, OUTPUT); //Provide power to both LEDs digitalWrite(LEDgreen, HIGH); digitalWrite(LEDyellow, HIGH); //Turn OFF any power to the Relay channels digitalWrite(CH1,LOW); digitalWrite(CH3,LOW); delay(2000); // Delay - Wait 2 seconds before starting sequence } void loop(){ digitalWrite(CH1, HIGH); //LED Green LED on, Yellow LED off delay(1000); digitalWrite(CH1, LOW); //LED Yellow LED on, Green LED off delay(1000); digitalWrite(CH3, HIGH); //LED Relay 3 switches to NO delay(1000); digitalWrite(CH3,LOW); //LED Relay 3 switches to NC delay(1000); } |
The red LED light on the Relay turns On while the power is up via the VCC pin. When power is up to one of the channel, the green light will on, then the other relay will switch from NC to NO. When power is down from the channel pin the relay will shutoff to NC from NO. This code we see that power is declared to both LED in the setup() function. When power is down going into channel 1 pin, the yellow LED will be On and the green LED will be off, because there is a break in the circuit for the green LED, When power is up going into Channel 1 the relay will switch from NC to NO closing the circuit for the green LED and open the circuit for the yellow LED. the LED Green will on and the yellow LED will off.
Download the source code here > 14core_relay_led_code
Pingback:Using Password Access Control on Matrix Keypad and Relay | 14Core.com