What is the best most safe way to drive this Relay?

renegadeandy
Posts: 19
Joined: Tue Mar 06, 2018 2:08 pm

What is the best most safe way to drive this Relay?

Postby renegadeandy » Tue Mar 06, 2018 2:18 pm

Hi all,

I have this relay module : https://www.amazon.co.uk/gp/product/B06 ... UTF8&psc=1

I want to drive the 8 control pins (driving low at 3.3v) from the ESP32. I believe that each pin needs > 10mA according to this datasheet:http://datasheetcafe.databank.netdna-cd ... asheet.pdf

How can I drive this safely using normal cheap components?

renegadeandy
Posts: 19
Joined: Tue Mar 06, 2018 2:08 pm

Re: What is the best most safe way to drive this Relay?

Postby renegadeandy » Wed Mar 07, 2018 7:56 pm

<bump>

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: What is the best most safe way to drive this Relay?

Postby Archibald » Wed Mar 07, 2018 8:47 pm

According to information from Amazon and directly from Elegoo, each channel requires 15 to 20mA drive current. It is not clear whether that is for input low or high, but probably low. The data you link to regarding the relay is irrelevant because there is evidently an 817C optocoupler for each input.

I suggest you consider using a 74HCT244 octal buffer / line driver as example here. You would want to tie the two output enable pins low (pins 1 and 19). The integrated circuit is capable of driving 25mA loads however the maximum supply or ground current is only 70mA. This means you can only drive three, perhaps four, optocouplers at the same time. That may be OK for your requirements but you would need to be careful to ensure the current is not excessive when your ESP32 is first powered-up, after reset or at any other time. If you wish to drive more than 3 or 4 optocouplers at the same time, you could consider using two 74HCT244s. Alternatively, I would resort to 8 discrete bipolar transistors (with base resistors).

I understand there is a visible LED to indicate the state of each input. If you remove those LEDs you may well be able to drive the board directly from your ESP32 but you would need to check the new input current needed.

renegadeandy
Posts: 19
Joined: Tue Mar 06, 2018 2:08 pm

Re: What is the best most safe way to drive this Relay?

Postby renegadeandy » Thu Mar 08, 2018 2:50 pm

Hi Archibald,

Am I right in thinking that this octal buffer would be supplied 5v from an external 5v supply rail? It is then sent a signal from the ESP32 which says 'shoot this current at this pin' and then it outputs as appropriate?

Can you maybe draw up a little schematic of how the pieces might work together? Really appreciate your help.

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: What is the best most safe way to drive this Relay?

Postby Archibald » Thu Mar 08, 2018 6:13 pm

Yes, the octal buffer needs a 5V supply. I would expect you to use the same supply that you use for your relay board. I would be very apprehensive about using USB power. If you are using an ESP32 development board that requires a 5V supply, I would recommend using the same supply. When using separate supplies there can be issues with parasitic powering when one supply is on and the other is off (see below). In this regard, don't overlook supply from a USB.

The buffer simply goes between the outputs of your ESP32 and the inputs of your relay board. The datasheet shows the pin connections of the HCT244. Pin 10 needs to be connected to ground (0 volts) and pin 20 to Vcc (5 volts). Also pins 1 and 19 need to be connected to ground to enable the outputs. An output from your ESP32 would go to buffer input pin 2 ("1A1") and the corresponding buffer output from pin 18 ("1Y1") would go to an input of your relay board. However, I would recommend placing resistors in series with the outputs from your ESP32 to protect your ESP32, especially if parasitic powering could occur. The input current of each buffer is less than 1µA, so quite high values of resistor could be used but I would suggest something in the range 1kΩ to 10kΩ. (This aspect if often overlooked by electronic engineers.)

The datasheet says the absolute maximum output current (Io) can be up to "±35mA" (may be different for other manufacturers of this integrated circuit). That means the output can "source" or "sink" up to 35mA. So when the output is high it can source 35mA and when the output is low it can sink 35mA. That's good news because I don't know what the relay board requires: it should work regardless. However the 70mA limit on the total current is very disappointing, especially by modern standards (this is an old design of integrated circuit).

As this is an "HCT" integrated circuit, it is said to be "TTL compatible": the datasheet says the minimum input level that the IC regards as high is 2.0V. A high output from your ESP32 on 3.3V supply will easily be over 2.0V so that's OK. Don't get an "HC" version of this IC because its input voltage for high could be over 3.3V.

If you require a circuit diagram for discrete transistors, I will need to know whether the inputs of the relay board need to be connected to ground or to 5V to operate the relays (BTW: I've not worked out what the jumper on the board does).

If you are considering manufacture hundreds or thousands of these, we ought to consider other options more carefully :) .

renegadeandy
Posts: 19
Joined: Tue Mar 06, 2018 2:08 pm

Re: What is the best most safe way to drive this Relay?

Postby renegadeandy » Thu Mar 08, 2018 9:13 pm

Hi Archibald,

Thank you *ever* so much for your continued support, I really appreciate it.

I built the circuit as you suggested, and it behaves exactly the same as if I had connected the ESP GPIO directly to the control pin, which I think is what we are expecting.

I have some questions :lol:

1/What is the advantage of using the buffer against connecting the ESP32 directly to the signal pin?

2/I added 10kOhm resistors (GPIO -> Resistor -> Input), what exactly are they doing? Stopping current flowing back towards the ESP?

3/ When the ESP32 is booting / resetting, the relay when control pins are connected via the HCT244 opens and closes VERY VERY fast, it kind of sounds like a machine gun, once the ESP32 starts to execute, the relay returns to normal and it behaves 'stably'. What is causing this?

4/Ultimately I was hoping the addition of this buffer would solve a problem I have with a specific ESP32 library. The library plays audio over I2S, and I have this all wired up and working nicely. The problem is, when audio is playing, and I am sending LOW to enable the relay to close, the relay starts to 'buzz' and the relay control LED 'fades', as soon as the audio finishes the relay returns to 'normal' silent operation with a strongly glowing LED. The addition of the buffer has not solved that. It behaves almost exactly the same. If you have a moment, perusing my 'issue' with the maintainer of the library here will shed some background on this question : https://github.com/earlephilhower/ESP82 ... /issues/65 The package maintainer kindly pointed me to ask about what is causing this on these forums, I am thankful for your support.

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: What is the best most safe way to drive this Relay?

Postby Archibald » Fri Mar 09, 2018 2:59 am

I have been under the impression from forum posts that the maximum GPIO output current from an ESP32 is 12mA whereas your relay board requires 15 to 20mA. That's partly why I have been suggesting the need to have a buffer capable of supplying up to 20mA. However, I have just checked the datasheet of the ESP32 and I find on page 32 the maximum output current is specified as 40mA. But in the IO_MUX table on page 49 the maximum "drive strength" seems to be 20mA (but I've not yet found out what d'2d means). Apparently the figure of 12mA applies to the ESP8266. The buffers also convert 3.3 volt logic to 5 volt logic for the relay board. However from your StackExchange thread, as expected, the relay board requires a 'low' to operate each relay. I believe the relay board can be driven "safely" directly from the ESP32 but we ought to consider what happens when an output from the ESP32 is high at about 3.3V. Assuming the circuit in the StackExchange thread is correct, current can flow from 5V supply through 470Ω, the optocoupler LED and the DS1 diode (LED?). This will tend to pull the output of the ESP32 above 3.3V. This may not cause any problems but it could be considered good practice to include the buffers to avoid this issue. Note if driving the relay board directly from the ESP32 outputs, it is important to power the ESP32 development board from the same 5V power supply to avoid the situation of power from the relay board feeding into the outputs of an unpowered ESP32 (via the optocoupler etc). For a very similar reason, I suggested putting a resistor in series with each buffer input to limit the current if the ESP32 output is high and the buffer is not powered (for example if the development board is powered via USB).

I have now read the discussion on github. I think there is undue concern there regarding isolation of the relay contacts. The datasheet for the relay indicates a dielectric strength between coil and contacts of 1500VAC (this could be compromised a bit by the design of the printed circuit board). If you are switching dangerous voltages with your relays, you still need to be fully aware that there will be high voltages on the printed circuit board. Your relay board includes opto-isolators (also known as optocouplers) but, in view of the isolation provided by the relays, their purpose is questionable.

Assuming you have a voltmeter, check whether the output that is driving the relay (GPIO22 I think) remains close to 0 volts while the audio is playing: I suspect not! Also check the 5V supply remains at 5V.
Last edited by Archibald on Fri Mar 09, 2018 5:22 pm, edited 1 time in total.

renegadeandy
Posts: 19
Joined: Tue Mar 06, 2018 2:08 pm

Re: What is the best most safe way to drive this Relay?

Postby renegadeandy » Fri Mar 09, 2018 3:25 pm

Hi Archibald,

Can you please help with these?

3/ When the ESP32 is booting / resetting, the relay when control pins are connected via the HCT244 opens and closes VERY VERY fast, it kind of sounds like a machine gun, once the ESP32 starts to execute, the relay returns to normal and it behaves 'stably'. What is causing this?

4/Ultimately I was hoping the addition of this buffer would solve a problem I have with a specific ESP32 library. The library plays audio over I2S, and I have this all wired up and working nicely. The problem is, when audio is playing, and I am sending LOW to enable the relay to close, the relay starts to 'buzz' and the relay control LED 'fades', as soon as the audio finishes the relay returns to 'normal' silent operation with a strongly glowing LED. The addition of the buffer has not solved that. It behaves almost exactly the same. If you have a moment, perusing my 'issue' with the maintainer of the library here will shed some background on this question : https://github.com/earlephilhower/ESP82 ... /issues/65 The package maintainer kindly pointed me to ask about what is causing this on these forums, I am thankful for your support.

My main question now is, why is the Relay making the noise, and the led dimming when Audio is playing, and more importantly, how do I stop it?

Archibald
Posts: 110
Joined: Mon Mar 05, 2018 12:44 am

Re: What is the best most safe way to drive this Relay?

Postby Archibald » Fri Mar 09, 2018 6:48 pm

I understand the visible LED is in series with the LED within the optocoupler and a 470Ω resistor. The three items are connected between the +5V supply of the relay board and the input connection to the relay board. So if the visible LED is dimming, either the 5V supply is reducing or the input from the ESP32 (with or without buffer) is not staying at a logic 'low' level. Especially as the LED is dimming even with the buffer in place (including if there's an extra resistor in series with its input), I do not think there is any problem with the electrical interfacing of the ESP32 to the relay board. Considering your description of a machine gun or buzzing sound from the relay, I think its most likely that the ESP32 output that you are using to drive the relay (GPIO22 ?) is also being driven by some other code or internal functionality of the ESP32.

That's why in my last post I asked if you could use a voltmeter to measure the ESP32 output that is driving the relay while the audio is playing. Better still: use an oscilloscope or logic analyser! Also check the 5V supply to the relay board remains at 5V.

renegadeandy
Posts: 19
Joined: Tue Mar 06, 2018 2:08 pm

Re: What is the best most safe way to drive this Relay?

Postby renegadeandy » Fri Mar 09, 2018 10:42 pm

When connecting the ESP32 pin directly to the relay signal pin, during the music the ESP pin flicks between 1.4v and 1.8v

After the music stops, it settles at 49mV.

The 5v for the relay sits at 4.68v whilst the music plays, and returns to 4.71v when the music stops.

I am not sure what conclusions to draw from this!

Please note there are 2 issues here.

1/When I use the CMOS buffer, and the ESP32 is booting I get the relay opening and closing seriously fast...which is the machine gun noise, and i am not sure why this happens. When I send LOW to the relay, it is happy again and settles closed.

2/The issue with the LED fading and the buzzing from the relay when it is closed during music being played.

Who is online

Users browsing this forum: chegewara and 170 guests