

The PCF8574 is an I2C-based I/O expander that allows microcontrollers to interface with additional digital input/output (I/O) pins using the I2C communication protocol. This component is particularly useful when the number of GPIO pins on a microcontroller is insufficient for a given application. By connecting the PCF8574 to the I2C bus, up to 8 additional I/O pins can be added, which can be configured as either inputs or outputs.








The PCF8574 has 16 pins, with the following configuration:
| Pin Number | Pin Name | Description |
|---|---|---|
| 1 | A0 | Address selection bit 0 (used to set the I2C address) |
| 2 | A1 | Address selection bit 1 (used to set the I2C address) |
| 3 | A2 | Address selection bit 2 (used to set the I2C address) |
| 4 | P0 | General-purpose I/O pin 0 |
| 5 | P1 | General-purpose I/O pin 1 |
| 6 | P2 | General-purpose I/O pin 2 |
| 7 | P3 | General-purpose I/O pin 3 |
| 8 | GND | Ground (0V reference) |
| 9 | P4 | General-purpose I/O pin 4 |
| 10 | P5 | General-purpose I/O pin 5 |
| 11 | P6 | General-purpose I/O pin 6 |
| 12 | P7 | General-purpose I/O pin 7 |
| 13 | INT | Interrupt output (active low, triggered by input pin state changes) |
| 14 | SCL | I2C clock line (connect to microcontroller's SCL pin) |
| 15 | SDA | I2C data line (connect to microcontroller's SDA pin) |
| 16 | VCC | Power supply (2.5V to 6V) |
Connect Power and Ground:
VCC pin to the power supply (e.g., 5V for Arduino).GND pin to the ground of the circuit.Set the I2C Address:
A0, A1, and A2 pins to configure the I2C address. These pins can be connected to GND (logic 0) or VCC (logic 1) to set the address. The base address is 0x20, and the address can range from 0x20 to 0x27.Connect the I2C Lines:
SCL pin to the microcontroller's I2C clock line.SDA pin to the microcontroller's I2C data line.SCL and SDA lines if not already present.Connect I/O Devices:
P0 to P7 pins to connect digital input or output devices. Configure these pins in your microcontroller code as needed.Write Code:
INT pin can be used to detect changes in input states. This is useful for applications requiring event-driven input handling.#include <Wire.h> // Include the Wire library for I2C communication
#define PCF8574_ADDRESS 0x20 // Base I2C address of the PCF8574
void setup() {
Wire.begin(); // Initialize I2C communication
Serial.begin(9600); // Initialize serial communication for debugging
// Set all pins (P0 to P7) as outputs and turn them off
Wire.beginTransmission(PCF8574_ADDRESS);
Wire.write(0xFF); // Write 0xFF to set all pins high (off for active-low devices)
Wire.endTransmission();
}
void loop() {
// Example: Toggle P0 every second
static bool state = false;
state = !state;
Wire.beginTransmission(PCF8574_ADDRESS);
Wire.write(state ? 0xFE : 0xFF); // Toggle P0 (0xFE = 11111110, 0xFF = 11111111)
Wire.endTransmission();
delay(1000); // Wait for 1 second
}
I2C Communication Fails:
SCL and SDA lines.Device Not Responding:
A0, A1, and A2 pin connections and calculate the correct address.Output Pins Not Driving High Current Devices:
Interrupt Pin Not Working:
INT pin is connected to a microcontroller interrupt-capable pin and properly configured in the code.Can I use multiple PCF8574 devices on the same I2C bus?
Yes, up to 8 devices can be used by configuring unique addresses using the A0, A1, and A2 pins.
What happens if I exceed the current limits? Exceeding the current limits can damage the PCF8574 or cause unreliable operation. Always stay within the specified ratings.
Can the PCF8574 handle analog signals? No, the PCF8574 is designed for digital I/O only. Use an ADC (Analog-to-Digital Converter) for analog signals.
Is the PCF8574 compatible with 3.3V systems? Yes, the PCF8574 operates from 2.5V to 6V, making it compatible with both 3.3V and 5V systems.