Ad Code

Responsive Advertisement

Ticker

6/recent/ticker-posts

Interfacing PIC Microcontroller with Relay

Interfacing PIC Microcontroller with Relay

Fig: Relay

In this tutorial, i will be discussing how we can interface a PIC microcontroller with a Relay. You can also check out my previous post on Interfacing PIC16F877A with LCD.
Relays are the switches used in closing and opening  circuits electronically as well as electromechanically. A Relay can be used to control high-voltage and high-current appliances  from lower voltage levels.
Some Relays are Alternating Current (AC) controlled while others are Direct Current (DC) Controlled.

There are different kinds of Relays some includes:
  • Single Pole Single Throw      (SPST)
  • Single Pole Double Throw    (SPDT)
  • Double Pole Single Throw    (DPST)
  • Double Pole Double Throw   (DPDT)


Fig: Schematic of SPDT Relay

The above image shows the schematic of  SPDT Relay, it is a very common kind of relay. SPDT relays have five(5) terminals. L1 and L2 are the coil terminals, other terminals are the common (COM) , normally-closed (NC) and normally-opened (NO). whenever a considerable amount of current is passed through the coils of the Relay at rated voltage, the coil gets energized and the lever inside it changes state. By default, the lever connects the COM and NC terminals but when the coil gets energized, the lever changes state and connects COM and NO as shown in Fig a. and Fig b. below.

Fig a. 

Fig b.

A low power supply on the coil can be used to control a high power load. When  switch SW in Fig a. is open, the lever connects COM and NC making the Lamp OFF, but When switch SW in Fig b. is closed, the lever changes state hence the Lamp comes ON as a result of the Closed circuit formed .

SCHEMATIC:



Fig: schematic

In the above Circuit diagram, The 12v lamp is to be turned On and OFF at an interval of one second. The first bit of  PORTD  (RD0) takes care of that . The current rating of the Relay is higher than the sourcing current of a PIC MCU hence a transistor is needed to power the Relay . The diode on the relay coil is referred to as a freewheeling diode which is used to protect the PIC MCU from Back EMF.


CODE

/*

  Name     : Interface  PIC16F877A with Relay

  Author   : DANIEL OLUWOLE

           : (C) 2020 DANITRONICS.

           : danitronics7@gmail.com, danieloluwole51@yahoo.com

           : Mobile: +234 8188508765.
    Aim : This program demonstrates how signals sent from the PIC MCU                  can affect the load connected on the relay.  
              Here, the 12v lamp will turn ON and OFF every second.
device   : PIC16F877A.
*/
void main() {
     TRISD.B0 = 0;  // SET RD0 AS OUTPUT

      while(1)
      {
        PORTD.B0 = 1;     // turn ON relay
        delay_ms(1000);    // 1000ms delay  = 1 sec
        PORTD.B0 = 0;     // turn OFF relay
        delay_ms(1000) ;   // 1000ms delay  = 1 sec
        
      
}    }



NEXT POST:
.

 

Post a Comment

0 Comments

Ad Code

Responsive Advertisement