0

I have a 5v relay which is not working on my esp-32 dev board. I understand that there logic levels are different but i checked the seller and they say it works with 3.3 logic level. When powered by the 3.3 pin on the board, the relay light turns on however it does not work. Sometimes the green light turns on but there is no sound or vibration of the latch opening/closing. Up till now you could dismiss all of these problems by saying that the board requires more power(5v). I thought so too. However what is bothering me is the fact that when the relays IN pin is connected too ground it turns on. Furthermore, i have also tried powering the board using a breadboard power supply(set to 5v) and triggering with esp-32 board but that too has failed? Could someone tell me If the problem is my code? relay? or mabye it is the right ammount of current/voltage?

( ik this is an electronic forum and am only asking about relays electrical side.this code is just to show it isn't a problem on the software side:) )

For testing purposes i am using this code:

void setup() {
  pinMode(23,OUTPUT);
}

void loop() {
  pinMode(23,HIGH);
  delay(250);
  pinMode(23,LOW);
  delay(250);

}
  • Current compliance is the problem. The relay needs too much. – jonk May 09 '20 at 23:58
  • How is the relay connected to IO pin? Directly, or via transistor etc? – Justme May 09 '20 at 23:59
  • @Justme The relay is connected directly to the 3V3 pin/ ground and GPIO23. – abdullah mohsin May 10 '20 at 00:01
  • @jonk if this is the case, How wold you go about fixing it? Do simple logic level converters increase current? – abdullah mohsin May 10 '20 at 00:02
  • 2
    Does this answer your question? https://electronics.stackexchange.com/questions/105850/transistor-to-run-relay – DKNguyen May 10 '20 at 00:04
  • @abdullahmohsin logic level converters change voltage to match logic threshold, usualy for high impedance inputs which also consume no current, so no. – DKNguyen May 10 '20 at 00:05
  • @Justme Also I've seen a couple of people use relays with transistors and loads do just fine without them. i have some transiters (S8050 transistor,PN2222 transistor) but as i have no idea what i am doing, i don't know if these can be used as amplifiers and how to wire them – abdullah mohsin May 10 '20 at 00:07
  • @abdullahmohsin If this is a mini relay, it's usually about 350 mW. So I'd figure about 100-120 mA in this case. That can be handled by many small signal BJTs, including the PN2222. So I'd probably use that. Your I/O pin *probably* can source enough base current to make that work. You'll need a resistor from I/O pin to the BJT base of about 120, 150, or 180 Ohms, emitter to ground, collector to one side of the relay. Other side of relay to +3.3 V. – jonk May 10 '20 at 00:20
  • @abdullahmohsin Also, you probably need a diode across the relay coil. This diode should be oriented so that it does ***not*** conduct when the relay is activated. – jonk May 10 '20 at 00:30
  • 1
    Where is the datasheet for the relay or relay module? From your description it sounds like you are using a module with a optocoupler or something on it, since you mention LEDs. – Spehro Pefhany May 10 '20 at 03:07

2 Answers2

0

Your issue is likely that the esp-32 cannot source enough current to activate the relay. Try using a transistor to drive the relay coil rather than having the esp drive it directly.

matdogg
  • 41
  • 4
0

You can't drive a relay directly from a GPIO pin. Use a transistor to drive the coil.

Justme
  • 127,425
  • 3
  • 97
  • 261
  • ok I will research up and try to use it with a transister. I dont know much about transister so bear with me if this a dumb question, Is a PN2222 transistor adequate for this job?? – abdullah mohsin May 10 '20 at 00:13
  • We can't know how much current your relay needs. You can check it yourself. Then you can check how much current the transistor can switch. Then you know if it is adequate or not. – Justme May 10 '20 at 00:17
  • i found this circuit online(https://imgur.com/WemTmin). Is this how you drive a relay? – abdullah mohsin May 10 '20 at 00:39