PCF8575 + relay board

Hi guys!
I have a 4 channel relay board connected to PCF8575
The PCF8575 is connected to Arduino Uno as follows:
SDA>A4
SCL>A5
VCC>Arduino 5V
GND>Arduino ground

also I have 10k resistors between SDA/SCL and Vcc

Relay board is connected as follows:
Vcc>Arduino 5V
Ground>Arduino ground
Channel 1-4 > PCF8575 ports 1-4

The code:

void setup()
{
Wire.begin();

// setting all pins to output/off
 Wire.beginTransmission(0x20);
 Wire.write(B00000000);
 Wire.write(B00000000);
 Wire.endTransmission();
}


void loop()
{

Wire.beginTransmission(0x20);
 Wire.write(B00000000);
 Wire.write(B00000000);
 Wire.endTransmission();

 delay(5000);

 Wire.beginTransmission(0x20);
 Wire.write(B11111111);
 Wire.write(B11111111);
 Wire.endTransmission();

 delay(5000);

}

All Wire methods return 0 (success).
Using a voltmeter, I can read 0V and 4.95V on any port of PCF8575, but the relays are not working…

Am I missing something?
Any help is really appreciated!
Thank you!

arno0548:
Am I missing something?

Yes, all the essential stuff. You have failed to cite what you mean by a "relay board". Web link to the circuit schematic or at minimum, to the page from where you obtained it.

As the PCF8575 is (IIRC) an open-collector driver, you need to understand the specifics of the connection.

Also, you need to read the instructions and go back and mark up the code in your posting.

Sorry for that,
I thought a relay board is a common term around here, my mistake...
So, the board has 4 relays, it is rated as arduino compatible, and it can be controlled using 5V

arno0548:
So, the board has 4 relays, it is rated as arduino compatible, and it can be controlled using 5V

So, apart from "four relays", we know nothing! :grinning:

Details?

Here is the board description:
http://www.robotshop.com/en/4-channel-5v-relay-module.html
I have connected the board to Arduino as follows:
Vcc> 5 V Arduino
Ground> Arduino Ground
Channel 1 > Pin 2
.. and I was able to control the relay by setting the pin HIGH/LOW

I thought a relay board is a common term around here, my mistake...

It is a common term, your mistake is that you think they are all the same, there are many many different ones.

You don't say what you have wired pins 2 & 3 PCF8575, they should be connected to ground if you want to use that address.

To use the pins as inputs you must first write a logic one to the bit and then have your input pull this down. Then you will read a zero if it is pulled down or one if it is not.

and I was able to control the relay by setting the pin HIGH/LOW

So do you have a problem now?

I was able to control the relay board when connected directly to Arduino.

Pins 1,2,3 from PCF8575 are connected to ground, therefore we have the address 0x20.
The problem is when I connect the four channels from the relay board to 1-4 PCF8575 ports, despite the fact that I can read 0/5V to PCF8575 ports, the relays are not working…
Let me rephrase the question…
Is it possible to drive the relayboard described above with PCF8575?

PCF8575_1.jpg

despite the fact that I can read 0/5V to PCF8575 ports, the relays are not working...

That sounds to me like you have not got a common ground between the relay board power supply and the PCF8575. That would explain why you see the voltage change but do not see the relay switch.

arno0548:
Here is the board description

Ah, so finally you confess!

Well now, looking at the schematic, we now find that unlike many of the relay boards on eBay, this one does not include opto-isolators (which may be "neither here nor there") but requires a positive signal referenced to ground, to activate.

Here's the problem.

The PCF8575, like its 8-bit sibling the PCF8574, has a "quasi-bidirectional input/output (I/O) port" which is another name for an essentially open-collector output with 100 µA pull-ups and a brief (corresponding to the ACK on the I2C interface) pulse of 1 mA as HIGH is written.

Now according to that schematic, the input circuit of the relay board has various (3) loads including a 10k resistor. Let's see - 10k, 100 µA - that's 1 V that the PCF8575 will drive to the relay board (after a very brief pulse of somewhat more), barely enough to start to turn on the transistor via its 1k resistor.

Do you now see the problem?

It's all clear now...
I took the measurements again, this time from ground to channel 1 and it barely reads 1V when the channel is "up".
This also demystifies the "quasi-bidirectional input/output" specification...

Well, I guess I have to figure it out another way to drive those relays...
Could you point me in the right direction?
Thank you very much sir!

When I referred to "unlike many of the relay boards on eBay", the hint is that most of them (well, more or less) use opto-isolators though not always in a fashion that actually provides isolation and they generally operate from active-low inputs.

You essentially have three options:

  • Buy a relay board with active-low inputs.
  • Use PNP transistors, emitter to 5V, base to the PCF8575 outputs via a 10k resistor and collector to control your relay board (no other components needed) or 74HC14 inverters, to invert the logic.
  • Use opto-couplers - which are generally a good idea as you can separate your logic power supplies from the relay power supply which often causes trouble. A 470 ohm resistor will control the current feeding the opto-coupler which is fed from the logic 5V, while the output of the opto-coupler feeds the relay board input separately from its power supply.

Using an PNP transistor looks easy..
I'll definitely look for an opto-coupler to fit in the scheme.. and will double check next time before buying a relay board.
Sir, you have all my gratitude!
Thank you!

I have connected an PNP transistor (TIP42) as described above and it works like a charm!