0
\$\begingroup\$

I am having trouble turning ON a relay from the ESP8266 output pin. I have wired the relay as shown in the picture below. The only change is that the transistor is BC556. Other specs of components are: Relay 5V , running this on 5V power supply. Here are some more facts: - I have wired the exact same circuit on the bread board and it works perfect. - I am using GPIO2 as the output PIN and apart from driving this relay , it also has a pull up resistor of 10K connected to GPIO2. - The relay works fine sometimes but many times it either does not work or is very slow in reacting. For eg. when my output tuns LOW, it soemtimes takes several seconds to turn ON the relay. - I measured the voltage across the transistor Vce = 1.1 V which means the voltage across the relay pins is 3.9V. I thought this is the reason why the relay is not able to trigger but then I have exact measurements on my breadboard circuit and it works fine. I even tried switching the relays but I get the same result. - From BC556 datasheets it says saturation Vce is .09 - .25V but I get 1.1 voltage drop Is this normal? I tried BC 557 with the same result. I even varied the base resistor to decrease it till 100 ohms but the Vce improve by 0.1 V only. Any suggestion on what should I do to troubleshoot this further would be helpful. Thanks

enter image description here

\$\endgroup\$
4
\$\begingroup\$

One thing that limits what you can do is that the ESP chip is 3.3V and your supply is 5V so you cannot use just a PNP transistor to do what you want. Here is one way to accomplish the task without changing the logic (low = on).

schematic

simulate this circuit – Schematic created using CircuitLab

Your circuit has two problems - the voltage across the relay coil will only go between about 4.3V and 1.1V- neither fully on nor fully off. That is because it is an emitter follower and has a 0.6~0.7V offset and it cannot amplify the 3.3V coming from the ESP chip.

The 1.1V is particularly dangerous since it is a grey zone of relay operation and some relays may stay pulled in (depending on temperature, whether they have been tapped, etc.) and some may drop out. The 4.3 means you are not getting full voltage on the coil so it might not pull in at very high temperatures. With the circuit above, the relay voltage will go from about 4.9V to 0V, as it should.

\$\endgroup\$
  • 1
    \$\begingroup\$ Thank you so much for the diagram to make it clear. I implemented this as it works fine! And yes, my relay wasn't bad, with this circuit it reacts like a charm. \$\endgroup\$ – Vijay Sharma Feb 2 '17 at 16:21
3
\$\begingroup\$

The problem is that you are likely not fully turning the transistor on and off. You mention in the comments that the relay is taking 13 mA when off. This is obviously because of your setup.

One, the ESP is 3.3V logic. Even with a 5V pull up, you create a voltage divider between 5V and 3.3V, so the transistor is still conducting. You may also have fried the ESP, just saying.

Two, the 1 kohm resistor may not be enough to saturate the transistor. It's 5 mA maybe, or less.

Three, with a PNP transistor, wiring the relay on the emitter, like a low side driver is not recommended. The emitter will never be a diode drop lower than its collector.

Solution, replace the PNP with a NPN. Remove the pull up, and change your code to invert the logic (1 = on).

Second solution, switch the PNP and relay around, and use a NPN as a PNP driver, because of the 3.3V logic of the ESP.

\$\endgroup\$
  • 1
    \$\begingroup\$ Thanks for your comments. I did ultimately find out that my relay was faulty, the replacement works fine. But I accept your comments and will make these changes. You're right the relay should not conduct when OFF. Thanks :) \$\endgroup\$ – Vijay Sharma Jan 29 '17 at 17:57
2
\$\begingroup\$

In such a circuit supplying a low switching voltage usually turns on the transistor. And supplying a high usually turns off the transistor.

However, consider the case of supplying the PNP transistor's base with a 3.3V high signal. It might be expected the transistor is turned off. But if we look closely at the question we see that the relay is run at 5V. Not at the same voltage as the micro processor is running at.

If 5V is supplied to the relay and 3.3V to the transistor's base, there could be as much as 5 - 3.3 or 1.7V difference between the emitter and base. Enough to activate the transistor even when it might be expected the transistor is turned off.

It might be that the relay is never turned off. So that it appears never to switch. Perhaps even thought of as defective.

\$\endgroup\$
2
\$\begingroup\$

To be clear, here is your circuit being discussed:

You need a NPN transistor there, not a PNP. The base should be wired as shown, the emitter to ground, and the collector to the relay.

Otherwise, you have to make sure the transistor can support the relay current. Let's say the digital signal is 3.3 V when high. Figure the B-E drop will be 700 mV, so that leaves 2.6 V across the base resistor. With the 1 kΩ resistor as shown, that will result in 2.6 mA of base current. Verify that the digital output can source that. Most can, but you should check anyway. Of course it can't be a open drain output if used this way since those can't source any current.

Let's say you use a transistor with a minimum guaranteed gain of 50. That means it can support up to 130 mA collector current. The relay must be rated for that or less.

\$\endgroup\$
  • \$\begingroup\$ Whoever downvoted this, please explain what you think is wrong, misleading, or badly written. Everything is correct as far as I can tell. \$\endgroup\$ – Olin Lathrop Jan 29 '17 at 18:21
  • \$\begingroup\$ I didn't downvote you, but... your schematic is just a copy of the OP's. You should edit the schematic to match your description (ie. NPN transistor with Emitter to ground). \$\endgroup\$ – Bruce Abbott Jan 29 '17 at 19:01
  • \$\begingroup\$ @Bruce: I copied the OP's schematic so that I could talk about it. I've learned the hard way that sometimes the question is changed, then your answer no longer makes sense. However, I'll add clarification that this is a copy of the OP's schematic. \$\endgroup\$ – Olin Lathrop Jan 29 '17 at 19:04
  • \$\begingroup\$ Of course I didn't downvote either, but he did (later) specify he wanted the reverse logic. Could just be someone's sloppy fingers too, stuff happens. Or chip+shoulder <shrug>. \$\endgroup\$ – Spehro Pefhany Jan 29 '17 at 19:12
  • \$\begingroup\$ But the question hasn't been changed and you still have the OP's bad design in your answer. Why not add a schematic showing how it should be done? \$\endgroup\$ – Bruce Abbott Jan 29 '17 at 19:39
1
\$\begingroup\$

Normally, an NPN transistor is used, with the emitter grounded and collector to the relay. That way, the transistor will be saturated when on, so the voltage across it will be about 0.2 volts.

That will invert the logic, so a High from the ESP8266 will turn on the relay.

\$\endgroup\$
  • \$\begingroup\$ Thanks but I have a low trigger on which the relay should be turned ON. \$\endgroup\$ – Vijay Sharma Jan 29 '17 at 17:25
  • \$\begingroup\$ @VijaySharma Then use two NPN transistors. \$\endgroup\$ – Craig McQueen Jan 29 '17 at 22:41
0
\$\begingroup\$

What is the relay?

Quite often small low voltage relays have a polarised coil (It saves power by having a permanent magnet biasing the field), and will not switch if you connect the coil the wrong way around. This is usually in the datasheets, but is often not so obvious as you would like (Guess who was had by this one....). Look at the pinout diagram on the datasheet for a '+' by one terminal, they mean it, both Omron and TE are buggers for this.

Do respect the 'must operate' and 'must release' ratings from the datasheet, these are temperature sensitive and you can set yourself up for a lot of reliability pain if you ignore these.

\$\endgroup\$
  • \$\begingroup\$ Oh! I didnt know that. Though I dont see any polarity markings on my relay. I tried both ways and it works fine. Maybe its the case with some of them and they carry a marking showing this off - nice info. \$\endgroup\$ – Vijay Sharma Jan 29 '17 at 17:51
  • \$\begingroup\$ Where this is the case it is often not on the part itself, you need to look at the datasheet. It is a lovely trap, and very annoying when you have just had a $1,000 prototype turn up and not work because you cannot get the main power interlock relay to pull in. \$\endgroup\$ – Dan Mills Jan 29 '17 at 17:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.