pcf8574 can not actuate a relay (only it's LED)

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
rudloffl
Normal user
Posts: 43
Joined: 04 Jul 2019, 07:17

pcf8574 can not actuate a relay (only it's LED)

#1 Post by rudloffl » 25 Aug 2019, 07:03

Hello all,

My question is not directly related to espeasy, but I'm sure someone knows the solution to my problem.
I want to actuate my relay via a PCF8574, the relay is a "single" version (one relay on the board, with 3 pins: a VCC, a GND and a S). The relay is connected to the 5V and the S is connected to a PCF8574 pin directly.
The PCF8574 is connected to I2c via a level-shifter (2 PIRs need 5 volts).

When I try to change the relay state, I can see it's LED change, but not the relay itself.
If I connect the relay to the esp8266 directly (D4 + 5v), it works fine.
I also tried to used the level-shifter backward (to go back to 3.3V logic), does not work (only the LED, not the relay).

Also connected to the PCF: 1 door sensor, 2 PIRs and the relay described.

Any idea how I can et to work via the PCF8574 ?

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: pcf8574 can not actuate a relay (only it's LED)

#2 Post by Shardan » 25 Aug 2019, 09:36

A short question first:
Has the relay board an active-low or an active-high type input?

You may test this (and the relay board at all) by putting a jumper cable on the input and touch ground and +5V.
Which one, ground or +5V, triggers the relay active?
Regards
Shardan

rudloffl
Normal user
Posts: 43
Joined: 04 Jul 2019, 07:17

Re: pcf8574 can not actuate a relay (only it's LED)

#3 Post by rudloffl » 25 Aug 2019, 17:57

The relay will be activated with the +5V (or3.3V). Should I wire it like add a resistor somewhere ?

rudloffl
Normal user
Posts: 43
Joined: 04 Jul 2019, 07:17

Re: pcf8574 can not actuate a relay (only it's LED)

#4 Post by rudloffl » 25 Aug 2019, 18:16

Do I need to a dd a 10K resistor like in this example ?
http://www.circuitbasics.com/setting-up ... e-arduino/

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: pcf8574 can not actuate a relay (only it's LED)

#5 Post by ThomasB » 25 Aug 2019, 19:09

Yes, you will need a pull-up resistor on PCF8574's IO Pin. Because it appears your PCF8574 is powered by 5V you can follow the circuit diagram you posted.

The pullup resistor value may vary depending on the relay module design. Start with 10K ohms, but be prepared to reduce it to achieve success; If necessary try 4.7K, then 2.2K, then 1K.

Installations that use a 3.3V powered PCF8574 would need to do it differently. That's because the input circuitry on some 5V relays needs additional attention to protect the drive signal from the 3.3V chip.

- Thomas

Shardan
Normal user
Posts: 1156
Joined: 03 Sep 2016, 23:27
Location: Bielefeld / Germany

Re: pcf8574 can not actuate a relay (only it's LED)

#6 Post by Shardan » 25 Aug 2019, 19:12

The example uses a resistor for the thermistor, not for relay if i see that right.

The problem is simple:
The PCF8574 outputs use a "constant current" source to pull up to Vcc (5V in your case).
The current is limited to 100µA internally, so that's the maximum you can get out of the PCF.

The relay uses most likely a transistor - the transistor needs
some driving current to open fully, If it does not open fully the LED will light up faintly and the relay
won't work as it does not get enough current.

A simple solution might be an additional resistor from Vcc (+5V) to the relay input.
Try starting with 10 KOhm, if that's not enough, lower the resistor to 4,7 KOhm or 2,2KOhm.
PCF_W_Relayboard.jpg
PCF_W_Relayboard.jpg (269.6 KiB) Viewed 14458 times
This way the "high" current to the relay board will be rised.
If the output from the PCF8574 goes low it takes the current, thats just a transistor inside the PCF
which can take some mA.

Another way is using a MCP23017 instead of the PCF8574. It offers 16 IO pins, usage is more or less the same.
The MCP23017 offers full current source and drain, says it can deliver up to some mA if "high" and
take some mA if "low".

Third way - create your own relay board using a small FET instead of the transistor, a 2N7000 or 2N7002 will do.
Regards
Shardan

rudloffl
Normal user
Posts: 43
Joined: 04 Jul 2019, 07:17

Re: pcf8574 can not actuate a relay (only it's LED)

#7 Post by rudloffl » 25 Aug 2019, 21:30

I got it to work with a 10K and 330ohm. Thank you all

rudloffl
Normal user
Posts: 43
Joined: 04 Jul 2019, 07:17

Re: pcf8574 can not actuate a relay (only it's LED)

#8 Post by rudloffl » 01 Sep 2019, 21:12

I actually have an other problem...

When I power up the complete system, the relay is changing state --> it is a big problem when you want to use it as a controller for the garage door. (I risk to open the garage each time there is an outage, a reboot has no effect)

Is there a work around to make sure that the relay will stay in his initial state when I power up the system?

I tried other schematics (and fried the PCF8574 with my different test, yes I'm a rookie) --> unsuccessful. My plan now is to change the relay to a version where I can select via a jumper if it behaves has a pull up or down (https://www.amazon.com/gp/product/B07M8 ... UTF8&psc=1)

Am I on the right track or should I consider a different solution ?

Thank

User avatar
ThomasB
Normal user
Posts: 1064
Joined: 17 Jun 2018, 20:41
Location: USA

Re: pcf8574 can not actuate a relay (only it's LED)

#9 Post by ThomasB » 02 Sep 2019, 19:50

My plan now is to change the relay to a version where I can select via a jumper if it behaves has a pull up or down
That should solve the problem.
I tried other schematics (and fried the PCF8574 with my different test, yes I'm a rookie) --> unsuccessful.
Building circuits is the best to way to learn; You can adapt your existing relay board by adding another resistor and a transistor.
The transistor can be any general purpose NPN, such as BC547, PN2222, etc. Or a small MOSFET like the 2N7000. Resistor value is not critical, but 10K ohms is typical.

- Thomas
Attachments
esp_relay.jpg
esp_relay.jpg (213.55 KiB) Viewed 14133 times

Post Reply

Who is online

Users browsing this forum: No registered users and 33 guests