Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Microcontroller behaves wrongly when I trigger the relay

Not open for further replies.


Newbie level 2
Jul 14, 2009
Reaction score
Trophy points
Activity points
Hi All,

I am triggering 3 relays one after other using microcontroller 89v51rd2. My application is like this
1. When I give input(5V) to microcontroller input1 then output1 becomes ON
2. Now I will get input (5V) to microcontroller input2 then output2 becomes ON
3. Now I will get input (5V) to microcontroller input3 then output3 becomes ON

all the microcontroller outputs are connected to T547(npn) transistor base through 4.7k ohm register and
+12V is connected to collector through relay and emitter is connected to ground.

Here In normal condition(without 230V connected to the relay) this is working fine. But when I connect a 230V(AC) load to the relay my microcontroller behaves wrongly. I mean when I give input(5V) to the microcontroller input1, immediately output1 and output2 triggers simultaneously irrespective of the input2.

So I have connected RC circuit to the 2.2K/1W resistor and capacitor across relay's AC network to avoid surge current. Still microcontroller triggers 2 relays simultaneously. Could you please suggest some solutions.

Thanks in advance.

Firstly, you also need diodes across the relay coils, cathode end up to supply.

The symptoms you describe are fairly common and caused by noise induced into the microprocessor somehow. The most likely source is the supply lines and if applicable the reset line. I am not familiar with the 89v51rd2 so forgive my lack of direct experience, I use the PIC family but the same problem and reasons apply.

Make sure you have good decoupling across the processor supply pins, and as close to the IC as possible. Use at least 10uF with a ceramic 100nF across it. The closer they are to the chip, the less likely supply noise will cause problems.

If you have a reset line, make sure it is also well filtered.

Although not impossible, it is improbable that the lines driving your transistors have spikes on them. Generally, output pins are not responsible for this kind of issue.

Ensure you have no floating or high impedance input pins which could act as antennas to the interference burst.

Finally, if filtering fails all you can do is go for physical isolation of the micro from the relays. The magnetic field from the relay coils and switched load is inducing voltage into the micro somehow and keeping them apart may be the only solution.



I've had your problem a while ago in one of my circuits. The main reason can be one of the followings:

1) you do not have a 'FlyWheel diode' across relays coils to suppress the back EMF which can cause the uC go crazy (Mainly,corrupting your PC register is enough), it even can breakdown your transistor junction permanently. Put a normal diode (Like 1N4001) across your relay coil in reverse bias mode. i.e., diode cathode to coil +12v and anode to transistor collector.

2) The snubber circuit must be placed as close as possible to your load, not on the relay contacts itself. This means EMF suppression will occur very near to the source (Your load) instead of suppressing it after it passes the wires connecting load to your PCB. Usually i use a non-polarized 0.22uF/400V capacitor in series with 100R/1W resistor.

Best regards.

Thank You Brain and Bus master.

I forgot to mention that I have connected a diode parallel to the relay with reverse bias towards +12V.
I agree with you this is because of some noise. I have connected 100nF and 10 µF capacitor to the supply and ground of the IC. Still I am Facing same issue. May be because I am using same source to micro controller and relays. I will try with separate voltage sources for micro controller and relay.

Bus Master,
I have connected 'fly wheel diode' and snubber circuit. In snubber circuit I have connected 2.2k/1W resister I think If i reduce resistor value, the register will heat.
This is very strange behavior. I am sure this is because of some noise. This looks very strange behavior.

Hello hsprao,

What about your input conditioning circuit? I mean: do you have resistors from input pins to gnd? You`ll need relatively low impedance to ground as a to avoid collecting noise. You can also try a low pass filter adding an aditional resistor and a capacitor to gnd.
Please also check PCB (if you have one) trace or cable routing, to be sure that the relay current closes right to the power supply.

Just my two cents,


Schematic will help a lot !, please post it

Not open for further replies.

Part and Inventory Search

Welcome to