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:


What is DC Motor? Interfacing DC motor with 8051 microcontroller using Relay and ULN2003


What is a DC Motor?

A DC motor runs with the help of Direct Current. It produces torque by using both electricity and magnetic fields. The common term used to refer both fields is Electromagnetism. When a current carrying conductor is placed in the external magnetic field, then it will experience a force proportional to the current in the conductor and strength of the external magnetic field.
                        F = B*L*I
Where F is force in dynes.
            B is flux density in lines per square centimetres.
            L is length of the conductor
            I  is current in the conductor.

The same principle is used in the DC motor. The DC motor has rotor, stator, field magnet, brushes, shaft, commutator. The DC motor requires more current to produce initial torque than in running state.

Interfacing DC motor with 8051 microcontroller using Relay and ULN2003

Interfacing the DC motor directly to 8051 microcontroller is not possible. Because the DC motor uses large current (200-300mA in small DC motors) to run. When this current flow into the 8051 microcontroller, the IC will get burn out. Therefore we need a driving circuit. In this tutorial, we are using DC motor driving circuit using relay and ULN2003/ULN2803.

Figure 1.1 Interfacing DC motor to 8051 Microcontroller using relay and ULN

A very simple driver circuit for the DC motor is by using Relay driver circuit is shown in figure 1.1. One wire of the DC motor is connected to the swing terminal of the relay and other wire is grounded as shown in figure. Initially the relay swing terminal is at normally closed connection. Connect the DC motor supply positive at NO. Whenever the relay coil is exited the swing terminal is attracted towards the coil and connected to the NO terminal of the relay. Now the current flows through the DC motor winding and starts rotating.

Whenever the current flowing through the coil is off the swing terminal is again comes back to its original position. The flywheel diode protects the ULN driver circuit from large negative potential developed across the coil when the current in it is off.

In the above circuit, upon reset the microcontroller the relay is switched ON and drives the motor. This happens only during the reset button is pressed, because upon reset all the microcontroller port pins acts as input pins. By default input pins are at logic HIGH, therefore this logic High at the port pin causes the Relay to be ON via ULN driver.

To avoid this situation, build a simple circuit using BC547 transistor. This circuit acts as a not gate (transistor as a switch). To make the transistor as a switch, it should operate in between two regions (cut-off and saturation) don’t try to operate in active region which will show undesired results. For this purpose a Base resistance of 330Ohms is connected to transistor (BC547) base to make the transistor completely ON (saturation region) and again 330 Ohms resistor is connected at collector. A Led show the ON or OFF operations of the transistor. The circuit diagram is shown in figure 1.2

Figure 1.2 DC motor interface to 8051 MCU with a Not gate to avoid reseting condition



Important Note:

1.       The speed of the DC motor is proportional to the current flowing in it.
2.       The Direction of the DC motor shaft rotation is depending upon the currents flowing in its winding.
3.       Provide separate power supply to DC motor. If we connect the circuit power supply to DC motor, the motor takes large current to produce initial torque in it. This sudden large current may damage circuit components. If your circuit has an LED and LCD, you will find dimness of both during motor start.
4.       Some DC motor comes with a capacitor connected along the two terminals. This capacitor by pass any AC noises in the power supply.


What is a Relay? How to interface relay with 8051 microcontroller using ULN2003/ULN2803? What is use of Fly wheel diode?


What is a Relay?

A relay is an electromechanical switch, which perform ON and OFF operations without any human interaction. General representation of double contact relay is shown in fig 1.1

Generally, the relay consists a inductor coil, a spring (not shown in the figure), Swing terminal, and two high power contacts named as normally closed (NC) and normally opened (NO). Relay uses an Electromagnet to move swing terminal between two contacts (NO and NC). When there is no power applied to the inductor coil (Relay is OFF), the spring holds the swing terminal is attached to NC contact.
Figure 1.1 Representation of Relay

Whenever required power is applied to the inductor coil, the current flowing through the coil generates a magnetic field which is helpful to move the swing terminal and attached it to the normally open (NO) contact. Again when power is OFF, the spring restores the swing terminal position to NC.

Advantage of relay:

A relay takes small power to turn ON, but it can control high power devices to switch ON and OFF. Consider an example; a relay is used t control the ceiling FAN at our home. The ceiling FAN may runs at 230V AC and draws a current maximum of 4A. Therefore the power required is 4X230 = 920 watts. Off course we can control AC, lights, etc., depend up on the relay ratings. Relays can be used to control DC motors in ROBOTICs.

Types of Relays:

a.       SPST (Single Pole Single Throw)

b.       SPDT (Single Pole Double Throw)

c.       DPST (Double Pole Single Throw)

d.       DPDT (Double Pole Double Throw)
Interfacing 



Interfacing relay to 8051 microcontroller


There are many ways to interface a relay to 8051 microcontroller. But simple and easy way for beginners is by using ULN2003/ULN2803. In this tutorial, a 5volts operated relay is taken for the demonstration. But the circuits shown can be useful to 12Volts operated relays also.


What happens when a relay is directly interfaced to 8051 micro controller?

Generally, a relay takes 70mA (some relays may works with 50mA) current to excite the inductor coil. But the current sinking capability (IoL) of each port pin of 89S52/89C52/89C51 has 20mA. So whenever 70mA current flow into the port pin may cause damage to that particular port pin. So to avoid this problem we need a large current sinker.

What is the need of ULN2803/ULN2003?


As we discuss above we need a large current sinker circuit between the relay and 8051 microcontroller. A transistor which has current sinking capability greater that 70mA is enough to act as a relay driver between the microcontrollers and relay. But the biasing circuit required for the transistor is a bit clumsy. In some cases like robotic car, the number of relays required will increase. Therefore the number of transistors and its biasing components will increase, PCB size increases, debugging is a bit headache.




Figure 1.2 interfacing Relay with 8051 microcontroller using ULN2003



So the simple way to drive the relay with 8051 microcontroller is by using ULN2003/ULN2803. A ULN driver has 500mA current sinking capability for each output pin. When input pin of ULN driver is at logic high then the corresponding output pin is connected to ground via 500mA fuse. Internally each fuse is designed by using Darlington transistor pair. So interfacing the 8051 microcontroller to relay via ULN driver will not damage the microcontroller port pin. The interfacing circuit is shown in figure1.2.

What is the need of fly wheel diode?


When power is applied to the relay inductor coil the current flowing through it causes magnetic field energy stored in it. This magnetic field is stored through the center of the coil and also outside of the coil.
                                                            B = LI2/2.
When the current flowing through inductor is off (i.e, the current changes from max to zero) causes changes in the stored magnetic field which in turn produce electric field that opposes the change in the current.
                                                            V = Ldi/dt.
If the current change is fast, the derivative value will be very high. The voltage produced due to the electric field across the coil to opposite to the actual current direction (i.e., negative potential) and may reach hundreds of volts if the change in current is very fast. This large voltage may damage the electronic parts.



                              Figure 1.3 Inductor coil connected across the collector terminal

As shown in figure 1.3 the inductor coil is connected at the collector terminal of the transistor. When logic high is applied, the transistor is in ON state, so the current flows along the inductor and transistor. When a logic LOW is applied, the transistor enters into OFF state (OPEN circuit), which in turn stop the current flow. Inductor doesn’t allow sudden changes in the current therefore large negative voltage is produce across inductor coil and causes electrons to cross the air gap as shown in figure. Therefore an electric spark/arc is produced across the open terminals of the transistor and it may damage the transistor as shown in figure 1.4


                  Figure 1.4 Spark Generated when inductor coil current is suddenly off

To avoid such problem, place a diode across the inductor coil as shown in below figure. When a power of the coil is OFF, the electric field (produced from the stored magnetic field) finds a path to flow electrons. Therefore the stored energy dissipates in the diode. When the relay coil power is ON, then the diode is not in conducting state. Whenever the power is OFF, the voltage appears across coil forward bias the diode and the current find a path to flow as shown in figure 1.5.



                  Figure 1.5 Flywheel diode across the inductor coil protects the transistor

Where do we see the electric spark in daily life?

You can see the electric spark by triggering the gas lighter or rubbing the positive terminal of the battery with its negative terminal by using a wire.
You can see big electric arc in movie theaters at film projector room.
You can see when a fan/light switch is on/off.








GSM Based Real-Time Automation of Irrigation System using 8051 Microcontroller


At the present era, the farmers have been using irrigation technique in India through the manual control in which the farmers irrigate the land at the regular intervals. This process sometimes consumes more water or sometimes farmer may forget to switch ON the irrigation system due to which the crops get dried. Water deficiency can be detrimental to plants before visible wilting occurs. Slowed growth rate, lighter weight fruit follows slight water deficiency.

This problem can be rectified by using automatic irrigation system using 8051 microcontroller. This automatic system can be operated remotely by the farmer, if he desires to water the crop field. The automatic irrigation system itself switches ON to watering the crop field at regular intervals of time without the involvement of the farmer. The farmer knows the ON/OFF status of the irrigation system by receiving SMS, which is automatically sent by the irrigation system. The farmer can send two formats of SMS as mode 1 and mode2. In mode1 format the farmer can change the water irrigation time intervals. In mode2 format he can directly switch ON the irrigation system whenever the needs it. A water level indicator system will signal the microcontroller system that required water content is supplied to the field or not. By checking that status signal the microcontroller system automatically switch off the irrigation system. The entire Microcontroller system runs under battery power, hence it monitors the power failures. According to the power failure the water irrigation system will be automated.

In this project, DC motor along with microcontroller circuitry shows the automatic irrigation system. The GSM modem is used to receive the message from the farmer and also used to send the status of irrigation system via SMS. A water level indicator circuit is used to know, that the required water is supplied to the field or not. A real time clock is used to get time and according to that microcontroller system compares it switch ON the irrigation system at regular intervals.


Block Diagram for GSM Based Real-Time Automation of Irrigation System using 8051 Microcontroller



GSM and Microcontroller based automatic railway gate control system with feedback provision


Now-a-days many accidents are taken place at train crossing gate. This is because of railway gate man carelessness or it may be the problem of station master, who fails to pass information to the gate man about the train arrivals. Consider, there are three train crossing gate points between two stations. The station master should pass the information about the train arrival to all train crossing gate points one after another. If he fails to send information to gate man leads to train accidents at train crossing points.


To avoid such accidents, this project provides better solution for railway gate control. In this project, at each train crossing point a SMS based gate control system is implemented. In which, a GSM modem is used to receive user command as SMS. The station master himself monitors all the train crossing gates points between two stations in the control panel. If the station master finds the arrival of train to the stations, then he will send command to close the gate as SMS to the first crossing point. Whenever the gate is closed at the receiver end, a sensor detects it and sends an acknowledgement to station master as a feedback about the gate close. After acknowledgement is received, the station master provides the green signal to the train. If the train crosses the first crossing point, then the station master sends next message to another crossing point and this process continues until the train reaches the next station. If acknowledgement is not received by the station master, the message is sent again to particular crossing point. Until a valid Acknowledgement is received, the station master will not give green signal to the train. Each resending messages are identified with sequence of numbers, by using those numbers the station master is waiting for corresponding acknowledgement.


A GSM modem is used to receive commands as SMS from stationmaster. The microcontroller based circuit process the SMS validation and drives the DC motor to close or open the gate. The DC motor is controlled by using PWM technique. An IR or magnetic sensor is used to detect the gate close or not and sends the status to the microcontroller circuit. Then the controller circuit formats the acknowledgement as SMS and sends it to station master.

Block Diagram for GSM and Microcontroller based automatic railway gate control system with feedback provision
GSM and Microcontroller based automatic railway gate control system with feedback provision



Tags: GSM modem, automatic railway gate control, IR transmitter, IR receiver, magnetic sensor, DC motor, DC motor driver, PWM control DC motor, pulse width modulation, station master control board, 8051 microcontroller, SMS, train crossing gate point.

Biometric fingerprint based vehicle anti theft system with GSM SMS alerts | vehicle security system


Generally, theft of many vehicles is taken place mainly in big cities. Now-a-days not only motor bikes, the big vehicles like cars, Lorries and trucks are also theft by the criminals. This is due to the lack of the security provision for the vehicles. The manual mechanical key based lock is the main drawback in the present vehicle systems. If somebody stolen the vehicle key can easily start the engine of the vehicle.
To protect our vehicles from theft, the present mechanical key based security system should be replaced with biometric fingerprint based ignition lock system. The entire circuit of this project provides an anti-theft device for vehicles. The technology used in this device is based on biometrics and embedded systems.
In this project, the biometric fingerprint based key system is accessed only by the authorized person or owner of the vehicle otherwise the vehicle won’t be start. If any authorized person tries to start the vehicle an alarm will be activated or a SMS is sent to the police and owner of the vehicle.
Technology involved in this project, is biometric fingerprint based authentication system. The fingerprint scanner module SM630 is used to scan the fingerprint of the authorized persons. The authorization of a person is verified by the 8051 program which is written in embedded C and burns it into the 89S52 microcontroller flash memory. A GSM modem (dual band GSM (900/1800) messaging system) is interfacing to 89S52 microcontroller to provide the SMS alerts when the unauthorized persons try to access the vehicle ignition lock.



Block diagram for Bio-metric fingerprint based vehicle anti theft system with GSM SMS alerts | vehicle security system
Block diagram for Bio-metric fingerprint based vehicle anti theft system with GSM SMS alerts | vehicle security system




Tags:

89S52 microcontroller, GSM modem, 8051 program, Embedded systems, Biometric Systems, access control, car security, auto security, fingerprint based ignition lock, biometrics, fingerprint scanner SM630, fingerprint reader, keil c, embedded c, vehicle security system

Wireless Based Monochrome LED Display Screen using 8051 microcontroller


Now-a-days so many companies are going for digital based advertisements. Not only companies the shopping malls, Railway stations, Bus stands, Cricket and Football stadiums every where the advertisement is going to be digital. All these are going for rich media or animated advertisements rather than simple text based advertisements. And the advertisers wants that people can the advertisement over from a longer distance. The internet, news paper and television media based advertisements are confined to indoor, shorter distance and cover fewer audience. To make the advertisement to over larger number of people, the advertisers chosen the transportation system (like highways, buses, railway stations) and sport stadiums, etc.,
To provide the solution for the above discussed problem, LED based digital screen is the best way to show the text, animation or rich media advertisement over a longer distance than the basic CRT and LCD technologies. The image or video shown in the CRT and LCD TV’s are not visible to human eye, but by using high power LED technology it is possible to see the image or video even in the mid-day light also. Not only just for advertisement, the LED displays are more wanting where the information dissemination is needed over a long distance.
In this project, a simple monochrome LED display screen is designed by using 8051 microcontroller. The advantage of this project is that it implemented with less hardware to decrease the cost of the LED display screen. This simple monochrome LED display screen will show the monochrome picture and will play the animations.
The 5mm LED’s are used to construct the LED screen of 24x16 pixels in resolution. An 89S52 microcontroller is used to refresh the screen with 24 frames per sec to avoid the flicker. The 8051 programming is involved in refreshing the screen. The 8051 program developed by using Embedded C in microvision keil IDE. Power supply interfacing to microcontroller is seperate than used  for the LED display. The microcontroller is also perform the job to collect the animation data from PC and stored it in EEPROM memory (24C32). A Zigbee module (Xbee-pro) is used for wireless data transfer between PC and the LED screen. The shift register (74LS164) is used in the LED display construction along with large current sinker (ULN2803).

Block Diagram for Wireless Based Monochrome LED Display Screen using 8051 microcontroller

Block Diagram Wireless Based Monochrome LED Display Screen using 8051 microcontroller


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.
Related Posts Plugin for WordPress, Blogger...
Twitter Delicious Facebook Digg Stumbleupon Favorites More

 
Powered by Blogger