Switching of Coil Relay Modules

 

 Switching of Coil Relay Modules

Just Arduino Things | TW TechieTube

Try to switch on and off a Coil Relay using Arduino UNO in various methods.



Principle:

The function of the relay coil is to create a magnetic field that actuates the switch mechanism of the relay. The coil is energized by an electric signal from a power source. When the coil is energized, it attracts the contact and completes the circuit within the relay, turning on or off the load being controlled. The relay coil is an electromagnet that can be operated by a small electric current to control a larger electric current.

Components Required:

  • Arduino UNO                                                (1)                        
  • 1 Channel 5vDC Relay Module                    (1)
  • Breadboard                                                    (As per Requirement)
  • Jumper Cables                                               (As per Requirement)
  • Arduino Bus Cable                                        (1)

Construction:

A Simple project to switch coil relays using the Relay Module


Now connect the Relay pins with the order given,

Vcc  - Arduino 5v/3.3v Pin
Gnd  - Arduino Gnd Pin
IN    - Any Digital Pins except D1/D2 on UNO.

As explained in the Video, the Code is written as Follows.

Code:

//CODE: Auto-Loop code for the relay to switch in a 1-second interval

int EMSwitch = 13;

void setup() {

  pinMode(13, OUTPUT);

  Serial.begin(9600);

}

void loop() {

    digitalWrite(EMSwitch, HIGH);

    delay(1000);

    Serial.println("EMSwitch is ON");

    digitalWrite(EMSwitch, LOW);

    delay(1000);

    Serial.println("EMSwitch is OFF");

  }

//CODE: Timer-based switching on the relay by user input

int EMSwitch = 13;

void setup() {

  pinMode(13, OUTPUT);

  Serial.begin(9600);

}

void loop() {

    Serial.println("Enter number of seconds");

    delay(10000);

    const int n = Serial.parseInt();

    if(n>0){

      Serial.println("EMSwitch will be ON for the specified seconds");

      digitalWrite(EMSwitch, HIGH);

      delay(n*1000);

      digitalWrite(EMSwitch, LOW);

      Serial.println("EMSwitch was ON for the specified seconds");

      }

    else {

      digitalWrite(EMSwitch, LOW);

       }

}

//CODE: Counter-based switching on the relay by user input

int EMSwitch = 13;

void setup() {

 Serial.begin(9600);

 pinMode(13, OUTPUT);

 digitalWrite(EMSwitch, LOW);

}


void loop() {

  Serial.println("Enter the number of times to switch on and off the relay:");

  delay(10000);

  int n = Serial.parseInt();

  int x;

  for(x=0; x<n; x++)

  { digitalWrite(EMSwitch, HIGH);

    delay(1000);

    digitalWrite(EMSwitch, LOW);

    delay(1000);

    Serial.println("cycle has occured");

}}

Do make the Project, Take a Snap and Tag us @techwiz_india


Comments

Popular posts from this blog

Buzzer Alarm using Touch Sensor

Obstacle Detection using IR Sensor

Human Detection using PIR Sensor