Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

How to Use I2C expander: Examples, Pinouts, and Specs

Image of I2C expander
Cirkit Designer LogoDesign with I2C expander in Cirkit Designer

Introduction

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.

Explore Projects Built with I2C expander

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
ESP32-Based I2C Communication Hub with Multiplexer and Expander
Image of Lights: A project utilizing I2C expander in a practical application
This circuit features an Olimex ESP32-EVB microcontroller unit (MCU) for processing and connectivity, interfaced with an MCP23017 I/O expander and an Adafruit TCA9548A I2C multiplexer to expand the number of I/O lines and allow multiple I2C devices to communicate with the MCU over the same bus. Pull-up resistors are connected to the I2C lines for proper bus operation, and both the MCP23017 and TCA9548A have their reset lines pulled high, likely for normal operation without external reset control.
Cirkit Designer LogoOpen Project in Cirkit Designer
I2C-Controlled Relay Switching with ESP32 and MCP23017 for Home Automation
Image of Vloerverwarming: A project utilizing I2C expander in a practical application
This circuit appears to be a control system utilizing two MCP23017 I/O expanders interfaced with an Olimex ESP32-EVB microcontroller via I2C communication, as indicated by the SDA and SCL connections with pull-up resistors. The MCP23017 expanders control an 8-channel relay module, allowing the microcontroller to switch various loads, potentially for home automation or industrial control. Additionally, there is an Adafruit ADS1115 16-bit ADC for analog signal measurement, and several heating actuators and a thermostat are connected, suggesting temperature control functionality.
Cirkit Designer LogoOpen Project in Cirkit Designer
MCP23017-Expanded I/O Interface with ADS1115 ADC and ESP32 Control
Image of door and window sensors: A project utilizing I2C expander in a practical application
This circuit features two MCP23017 I/O expanders interfaced with multiple switches, allowing for the expansion of input capabilities. The MCP23017s are connected via I2C to an Olimex ESP32-EVB microcontroller, which likely manages the input states from the switches. Additionally, an Adafruit ADS1115 16-bit ADC is included, suggesting that some analog inputs are being monitored, with the ADC also interfaced with the ESP32 via I2C.
Cirkit Designer LogoOpen Project in Cirkit Designer
ESP32 and MCP23017-Based Smart Relay Control System with DHT22 Sensors
Image of Indoor Lounge: A project utilizing I2C expander in a practical application
This circuit is a control system that uses an ESP32 microcontroller to manage multiple relays and read data from DHT22 temperature and humidity sensors. The DFRobot Gravity MCP23017 I2C module expands the GPIO capabilities of the ESP32, allowing it to control additional relays for switching high-power devices.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with I2C expander

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Lights: A project utilizing I2C expander in a practical application
ESP32-Based I2C Communication Hub with Multiplexer and Expander
This circuit features an Olimex ESP32-EVB microcontroller unit (MCU) for processing and connectivity, interfaced with an MCP23017 I/O expander and an Adafruit TCA9548A I2C multiplexer to expand the number of I/O lines and allow multiple I2C devices to communicate with the MCU over the same bus. Pull-up resistors are connected to the I2C lines for proper bus operation, and both the MCP23017 and TCA9548A have their reset lines pulled high, likely for normal operation without external reset control.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Vloerverwarming: A project utilizing I2C expander in a practical application
I2C-Controlled Relay Switching with ESP32 and MCP23017 for Home Automation
This circuit appears to be a control system utilizing two MCP23017 I/O expanders interfaced with an Olimex ESP32-EVB microcontroller via I2C communication, as indicated by the SDA and SCL connections with pull-up resistors. The MCP23017 expanders control an 8-channel relay module, allowing the microcontroller to switch various loads, potentially for home automation or industrial control. Additionally, there is an Adafruit ADS1115 16-bit ADC for analog signal measurement, and several heating actuators and a thermostat are connected, suggesting temperature control functionality.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of door and window sensors: A project utilizing I2C expander in a practical application
MCP23017-Expanded I/O Interface with ADS1115 ADC and ESP32 Control
This circuit features two MCP23017 I/O expanders interfaced with multiple switches, allowing for the expansion of input capabilities. The MCP23017s are connected via I2C to an Olimex ESP32-EVB microcontroller, which likely manages the input states from the switches. Additionally, an Adafruit ADS1115 16-bit ADC is included, suggesting that some analog inputs are being monitored, with the ADC also interfaced with the ESP32 via I2C.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of Indoor Lounge: A project utilizing I2C expander in a practical application
ESP32 and MCP23017-Based Smart Relay Control System with DHT22 Sensors
This circuit is a control system that uses an ESP32 microcontroller to manage multiple relays and read data from DHT22 temperature and humidity sensors. The DFRobot Gravity MCP23017 I2C module expands the GPIO capabilities of the ESP32, allowing it to control additional relays for switching high-power devices.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications and Use Cases

  • Expanding GPIO pins for microcontrollers like Arduino, Raspberry Pi, or ESP32.
  • Driving LEDs, relays, or other digital output devices.
  • Reading digital inputs such as switches, buttons, or sensors.
  • Building control panels or keypads.
  • Interfacing with multiple peripherals in resource-constrained systems.

Technical Specifications

  • Manufacturer Part ID: PCF8574
  • Communication Protocol: I2C (Inter-Integrated Circuit)
  • Operating Voltage: 2.5V to 6V
  • Maximum Sink Current (per pin): 25mA
  • Maximum Source Current (per pin): -300µA
  • I2C Address Range: 0x20 to 0x27 (configurable via address pins A0, A1, A2)
  • Number of I/O Pins: 8 (P0 to P7)
  • Operating Temperature Range: -40°C to +85°C
  • Package Type: DIP, SOIC, or TSSOP (varies by manufacturer)

Pin Configuration and Descriptions

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)

Usage Instructions

How to Use the PCF8574 in a Circuit

  1. Connect Power and Ground:

    • Connect the VCC pin to the power supply (e.g., 5V for Arduino).
    • Connect the GND pin to the ground of the circuit.
  2. Set the I2C Address:

    • Use the 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.
  3. Connect the I2C Lines:

    • Connect the SCL pin to the microcontroller's I2C clock line.
    • Connect the SDA pin to the microcontroller's I2C data line.
    • Use pull-up resistors (typically 4.7kΩ) on the SCL and SDA lines if not already present.
  4. Connect I/O Devices:

    • Use the P0 to P7 pins to connect digital input or output devices. Configure these pins in your microcontroller code as needed.
  5. Write Code:

    • Use an I2C library (e.g., Wire.h for Arduino) to communicate with the PCF8574. Send or receive data to control the I/O pins.

Important Considerations and Best Practices

  • Interrupt Pin: The INT pin can be used to detect changes in input states. This is useful for applications requiring event-driven input handling.
  • Current Limitations: The PCF8574 can sink up to 25mA per pin but can only source a small current (-300µA). Use external transistors or drivers for high-current applications.
  • I2C Pull-Up Resistors: Ensure proper pull-up resistors are present on the I2C lines to maintain signal integrity.
  • Address Conflicts: Avoid address conflicts when using multiple I2C devices on the same bus.

Example Code for Arduino UNO

#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
}

Troubleshooting and FAQs

Common Issues and Solutions

  1. I2C Communication Fails:

    • Cause: Incorrect wiring or missing pull-up resistors.
    • Solution: Verify connections and ensure 4.7kΩ pull-up resistors are present on the SCL and SDA lines.
  2. Device Not Responding:

    • Cause: Incorrect I2C address configuration.
    • Solution: Check the A0, A1, and A2 pin connections and calculate the correct address.
  3. Output Pins Not Driving High Current Devices:

    • Cause: PCF8574 has limited current sourcing capability.
    • Solution: Use external transistors or drivers for high-current loads.
  4. Interrupt Pin Not Working:

    • Cause: Interrupts not enabled or misconfigured.
    • Solution: Ensure the INT pin is connected to a microcontroller interrupt-capable pin and properly configured in the code.

FAQs

  • 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.