

The I2C Port Expander is a versatile electronic component designed to increase the number of available input/output (I/O) pins on a microcontroller. It achieves this by utilizing the I2C (Inter-Integrated Circuit) communication protocol, which allows multiple devices to communicate over just two wires: SDA (data line) and SCL (clock line). This makes it an ideal solution for projects requiring additional I/O pins without increasing the complexity of wiring.








Below are the general technical specifications for a typical I2C Port Expander, such as the popular PCF8574 or MCP23017:
| Pin Number | Pin Name | Description |
|---|---|---|
| 1 | A0 | Address selection pin (LSB of I2C address) |
| 2 | A1 | Address selection pin |
| 3 | A2 | Address selection pin (MSB of I2C address) |
| 4 | GND | Ground connection |
| 5-12 | P0-P7 | General-purpose I/O pins |
| 13 | INT | Interrupt output (active low, triggered by input state change) |
| 14 | SDA | I2C data line |
| 15 | SCL | I2C clock line |
| 16 | VCC | Power supply (2.5V to 5.5V) |
| Pin Number | Pin Name | Description |
|---|---|---|
| 1-8 | GPA0-GPA7 | General-purpose I/O pins (Port A) |
| 9 | VDD | Power supply (2.5V to 5.5V) |
| 10 | INT A | Interrupt output for Port A (active low) |
| 11 | INT B | Interrupt output for Port B (active low) |
| 12 | SDA | I2C data line |
| 13 | SCL | I2C clock line |
| 14 | RESET | Active-low reset input |
| 15-22 | GPB0-GPB7 | General-purpose I/O pins (Port B) |
| 23 | A0 | Address selection pin (LSB of I2C address) |
| 24 | A1 | Address selection pin |
| 25 | A2 | Address selection pin (MSB of I2C address) |
| 26 | GND | Ground connection |
Below is an example of using the PCF8574 to control LEDs and read button states:
#include <Wire.h> // Include the Wire library for I2C communication
#define I2C_ADDRESS 0x20 // I2C address of the PCF8574 (configured via A0, A1, A2)
void setup() {
Wire.begin(); // Initialize I2C communication
Serial.begin(9600); // Start serial communication for debugging
// Set all pins as outputs (write 0x00 to the expander)
Wire.beginTransmission(I2C_ADDRESS);
Wire.write(0x00); // All pins low (outputs)
Wire.endTransmission();
}
void loop() {
// Example: Toggle an LED connected to P0
Wire.beginTransmission(I2C_ADDRESS);
Wire.write(0x01); // Set P0 high, others low
Wire.endTransmission();
delay(500); // Wait 500ms
Wire.beginTransmission(I2C_ADDRESS);
Wire.write(0x00); // Set all pins low
Wire.endTransmission();
delay(500); // Wait 500ms
}
I2C Device Not Detected:
Incorrect Output Behavior:
Interrupt Pin Not Working:
Multiple Devices on the Same Bus:
Q: Can I use multiple I2C Port Expanders on the same bus?
A: Yes, as long as each expander has a unique I2C address. Configure the address pins (A0, A1, A2) accordingly.
Q: Do I need external pull-up resistors for the I2C lines?
A: Yes, if your microcontroller or other devices on the bus do not already include them.
Q: Can the expander handle analog signals?
A: No, I2C Port Expanders are designed for digital I/O only. Use an ADC (Analog-to-Digital Converter) for analog signals.