Controlling the DC motor direction using two relays and ULN driver with 89S52 microcontroller


Driving the DC motor is very simple by using 8051 microcontroller and relay driving mechanism. But to control the direction of the DC motor (i.e., clockwise direction and Anti-clockwise direction) is a little bit complex for beginners. Here in this tutorial, I will show a simple way to control the DC motor direction. The circuit is very easy to design and to understand but cost will increase, when it is compared to transistor logic circuitry.

In figure 1.1 shows the entire circuit diagram to control the direction of the DC motor using two relays and ULN driver with basic 8051 microcontroller (89S52/89C52). Here, the inductor coil of two relays are connected to 5V/12V (depend up on the relay specification) supply and other end of the coils are connected to ground via ULN2803/ULN2003. When the input pin of the ULN driver is high then the corresponding output pins are connected to ground (9th pin of the ULN driver) via Darlington pair transistor which provides 500mA current sinking capability.



The NO (normally open) and NC (normally closed) terminals should be connected to another power supply to drive the DC motor. The supply positive is connected to NO and negative/ground is connected to NC. One wire of the DC motor is connected to the swing terminal of first relay and other wire is connected to swing terminal of second relay. Initially the two swing terminals are connected to NC of the relays (grounded) so DC motor will not rotate because two terminals are at same potential (ground). Similarly, if two swing terminals are connected to 5V/12V supply in this case also motor will not rotate.

If you want to rotate the DC motor any one of the swing terminals should be connected to supply (5V/12V) and other should be connected to ground. Consider a case where the first relay swing terminal is connected to supply and other is grounded then current will flow from RL1 to RL2 via DC motor so the shaft of DC motor is rotate in clockwise direction.

If the second relay swing terminal is connected to supply and other is connected to ground then the current will flow from RL2 to RL1 via DC motor so the shaft of DC motor is rotate in anti-clockwise direction.

The relay swing terminals are controlled with ULN driver. Where ULN driver input pins are controlled by using 89S52/89C52 microcontroller port P1 pins.

From the above discussion we have seen four cases

Case 1:  if P1.0 = 0 and P1.1 = 0; no operation.
Case 2:  if P1.0 = 1 and P1.1 = 1; no operation.
Case 3:  if P1.0 = 0 and P1.1 = 1; clockwise.
Case 4:  if P1.0 = 1 and P1.1 = 0; anti-clockwise.



Embedded code:


#include<reg52.h>                                                                                                                            
/*Motor terminals are connected to relays which are controlled by using microcontroller port0 pins*/
sbit MOTOR_PIN1 = P2^0;
sbit MOTOR_PIN2 = P2^1;

/*function prototype*/
void delay(unsigned int);

void main(void)
{
           
                         while(1)
                         {
                                    MOTOR_PIN1 = 1;
                                    MOTOR_PIN2 = 0;  // forward direction
                                    delay(50);
                                    MOTOR_PIN1 = 0;
                                    MOTOR_PIN2 = 1;  // reverse direction
                                    delay(50);

                         }


}


void delay(unsigned int value)
{
 unsigned int i=0,j=0;
            for(i=0;i<value;i++)
                        for(j=0;j<1725;j++);

}


      NOTE:


1.    Provide separate power supply to DC motor and circuit.
2.   Ensure that relay coil supply should be 5V or greater that 5V.
3.  Pull up resistance should be between 1K and 10K (see datasheet). Pull-up is not required for port2 but practically pull up shows between results for all ports.
4.   Fly wheel or fly back diode is used to protect the controller circuit from high voltages produced when relay coil current is OFF.

Download code




    Video:


2 comments :

  1. thank u sir giving tech. knowledge.

    ReplyDelete
  2. may i asking you,how to change transistor in my RC car with relay to make speed more variable in my RC car,thank you sir before.

    ReplyDelete

Thanks for visiting NPEDUCATIONS. We will contact you soon

2 comments :

Dinesh Hire said...

thank u sir giving tech. knowledge.

iyung anam said...

may i asking you,how to change transistor in my RC car with relay to make speed more variable in my RC car,thank you sir before.

Post a Comment

Thanks for visiting NPEDUCATIONS. We will contact you soon

If you really like this tutorial, Don't forget to give the comment or please subscribe to the RSS feed by submitting your E-mail or like our Facebook page.
Related Posts Plugin for WordPress, Blogger...

 
Powered by Blogger