LED Blinking is a very common and almost first program for every embedded learner or beginner. In which we blink an LED with having some delay. So today we are here with the same project but here we will use an AC bulb instead of normal LED and will blink an AC bulb.
Whenever we need to connect any AC Appliance in our embedded circuits, we use a Relay. So in this arduino relay control tutorial we will simply learn How to interface a Relay with Arduino. Here we are not using any Relay Driver IC like ULN2003 and will only use an NPN transistor to control relay.
Components Required:
- Arduino
- 5v or 6v relay
- AC appliance or Bulb
- BC547 transistor
- 1k resistor
- Breadboard or PCB
- Connecting jumper wire
- Power supply
- 1n4007 diode
- Screw terminal or terminal block
Relay:
Relay is an electromagnetic switch, which is controlled by small current, and used to switch ON and OFF relatively much larger current. Means by applying small current we can switch ON the relay which allows much larger current to flow. A relay is a good example of controlling the AC (alternate current) devices, using a much smaller DC current. Commonly used Relay is Single Pole Double Throw (SPDT) Relay.
When there is no voltage applied to the coil, COM (common) is connected to NC (normally closed contact). When there is some voltage applied to the coil, the electromagnetic field produced, which attracts the Armature (lever connected to spring), and COM and NO (normally open contact) gets connected, which allow a larger current to flow. Relays are available in many ratings, here we used 6V operating voltage relay, which allows 7A-250VAC current to flow.
The relay is always configured by using a small Driver circuit which consists a Transistor, Diode and a resistor. Transistor is used to amplify the current so that full current (from the DC source – 9v battery) can flow through a coil to fully energies it. The resistor is used to provide biasing to the transistor. And Diode is used to prevent reverse current flow, when the transistor is switched OFF. Every Inductor coil produces equal and opposite EMF when switched OFF suddenly, this may cause permanent damage to components, so Diode must be used to prevent reverse current. A Relay module is easily available in the market with all its Driver circuit on the board or you can create it on perf board or PCB like below. Here we have used 6V Relay module.
Here to turn on the Relay with Arduino we just need to make that Arduino Pin High (A0 in our case) where Relay module is connected. Below given is Relay Driver Circuit to build your own Relay module.
Circuit Diagram and Working:
In this Arduino Relay Control Circuit we have used Arduino to control the relay via a BC547 transistor. We have connected transistor base to Arduino pin A0 through a 1k resistor. An AC bulb is used for demonstration. The 12v adaptor is used for powering the circuit.
Working is simple, we need to make the RELAY Pin (PIN A0) high to make the Relay module ON and make the RELAY pin low to turn off the Relay Module. The AC light will also turn on and off according to Relay.
We just programmed the Arduino to make the Relay Pin (A0) High and Low with a delay of 1 second:
void loop() { digitalWrite(relay, HIGH); delay(interval); digitalWrite(relay, LOW); delay(interval); }
Demonstration Video and complete code for Arduino Relay Control is given below.
#define interval 1000
pinMode(relay, OUTPUT);
}
{
digitalWrite(relay, HIGH);
delay(interval);
digitalWrite(relay, LOW);
delay(interval);
}
Video:
Source : Arduino Relay Control Tutorial