You may have found yourself in a situation where you would like to expand the number of inputs and outputs available to your arduino board, since you are carrying out a project that needs more devices than expected. In these cases you could only do one thing, and that is to think about buying a board of a higher model with more of these connections. But now with The PCF8574 can expand the I/O of Arduino in an easy and cheap way.
Here we will show you what the PCF8574 is in case you didn't know it, in addition to showing how it can be connected to your Arduino board explained step by step and how it works...
What is the PCF8574?
El PCF8574 is a digital input and output (I/O) expander for the I2C1 bus. This device, manufactured by Philips, allows you to connect a processor such as Arduino to control more devices using fewer pins2. The PCF8574 incorporates 8 quasi-directional pins based on CMOS outputs in open drain configuration.
Furthermore, the PCF8574 is a low-power device that supports VCC operations from 2.5V to 6V. It features an 8-bit quasi-bidirectional I/O port, latched outputs, open drain interrupt output, and high current driving capability for LEDs. On the other hand, its stand-by consumption is very low, less than 10 µA.
It is very useful for Expand the capabilities of your Arduino board beyond its limits, which can be a great help for creators who need something more than what Arduino offers. The maximum current that each pin can supply will depend on the configuration:
- When it acts as an output, it is 25mA when it acts as a sink, that is, when the electrical current flows to the PCF8574. This is the default configuration.
- When it acts as a source it is 300µA, that is, when the current flows from the PCF8574. Likewise, you must know that all outputs have Latches, that is, they maintain the state by themselves in a register. We only have to act when we want to modify the state of one of the outputs.
Communication is done via I2C bus, so it is easy to obtain data from the devices connected to it. Likewise, it should be noted that it has 3 address pins, which gives 8 possible connections to the same I2C bus. This means that it is possible to control 64 devices using only 2 pins.
Address settings
Some models of this PCF8574 module usually include configuration pins and jumpers like the ones you see in the image above. On the other hand, other models include a switch that makes things easier with the three microswitches... Be that as it may, they are used to configure addresses of I/O pins:
A0 | A1 | A2 | Address |
0 | 0 | 0 | 0x20 |
0 | 0 | 1 | 0x21 |
0 | 1 | 0 | 0x22 |
0 | 1 | 1 | 0x23 |
1 | 0 | 0 | 0x24 |
1 | 0 | 1 | 0x25 |
1 | 1 | 0 | 0x26 |
1 | 1 | 1 | 0x27 |
Price and where to buy
It can be found for just a few euros. It is a device quite cheap for how practical it can be for some Arduino models that have a lower number of I/Os. So if you are looking for a PCF8574, you can find it in specialized stores or also on large online platforms such as Amazon, Aliexpress or eBay. For example, here we recommend one:
Connecting the PCF8574 to Arduinno
At connect the PCF8574 expander to your Arduino board, The connection diagram is quite simple. You will only have to connect:
- The SCL pin marked on the PCF8574 board to the SCL pin of Arduino. This pin can change depending on the model, but is usually on the A5 on the more popular models like the UNO.
- The SDA pin of the expander has to connect with the SDA pin of the Arduino. The same thing I mentioned above, it can change depending on the model, but generally it is the A4. If in doubt, check the pinout of your model.
- The GND pin of the PCF8574 will of course be connected to the one marked GND on the Arduino, that is, it is the ground connection.
- The Vcc pin of the expander is connected to 5V of the Arduino, in this way, with GND and Vcc we have already powered the expander board so that it can start working.
Operation
Once the PCF8574 is connected to the Arduino board, now it's time to know how does it work. To do this, you have to keep in mind that you will be able to have 8 extra pins, in exchange for having used two Arduino pins, in addition to the power ones. On the other hand, you have to take something into account, and that is that on each of those 8 pins of the PCF8574 you have a MOSFET transistor along with a very low resistance pull-up resistor. This assumes a current intensity of 100 microA when the transistor is active.
And this leaves us with the following panorama:
- Configuration as output- When the pin is used as an output, it acts as a current sink, as I have discussed above, i.e. current flows in.
- LOW: When at low voltage, it does not conduct current, load = Vdd.
- HIGH: when at high voltage, up to 25mA current can pass, the load will be connected to GND.
- Configuration as input: it must always be set to HIGH, and in this case it will act as a source, that is, the current flows out.
- Closed: When the external load is not given, the voltage on the pin goes to GND.
- Open: When an external load occurs, the pin voltage becomes Vdd.
Arduino IDE Code
If what you want is some examples of how to create code to use this PCF8574 on Arduino, it is as simple as using these code examples that you can modify according to your needs:
- Configuration as output:
#include <Wire.h> const int pcfAddress = 0x38; void setup() { Wire.begin(); Serial.begin(9600); } void loop() { for (short channel = 0; channel < 8; channel++) { // Escribir dato en canal 'channel' Wire.beginTransmission(pcfAddress); Wire.write(~(1 << channel)); Wire.endTransmission(); // Leer dato de canal delay(500); } }
- Configuration as input:
#include <Wire.h> const int pcfAddress = 0x38; void setup() { Wire.begin(); Serial.begin(9600); } void loop() { short channel = 1; byte value = 0; // Leer dato de canal 'channel' Wire.requestFrom(pcfAddress, 1 << channel); if (Wire.available()) { value = Wire.read(); } Wire.endTransmission(); // Mostrar el valor por puerto serie Serial.println(value); }
Remember that you can also use the library created especially for the PCF8574 which also includes practical examples…