Arduino PCF8574 I2C I/O Expander: Wiring, Code and Simulator

To build this Arduino PCF8574 I2C I/O Expander project you need an Arduino Uno and an I/O expander PCF8574, a 330 Ω resistor and a red LED. Eight extra pins over I2C: P0 blinks an LED through a resistor from 5 V. Make the 7 connections in the wiring table, upload the Arduino C++ code, and add LEDs on P1–P7 and write a pattern with io.write8().

Open this circuit in the free Arduino Uno simulator

Parts list

QtyPartWhat it does
1Arduino Unothe microcontroller board
1I/O Expander PCF8574Eight extra pins over I²C (0x20–0x27): Wire.write(byte) sets P0–P7 (0 = LOW, 1 = released high); Wire.requestFrom reads them back.
1330 Ω resistorLimits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down.
1red LEDLights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor.

Wiring

#FromTo
1Arduino Uno 5VI/O Expander PCF8574 VCC
2Arduino Uno GNDI/O Expander PCF8574 GND
3Arduino Uno A4I/O Expander PCF8574 SDA
4Arduino Uno A5I/O Expander PCF8574 SCL
5Arduino Uno 5V330 Ω resistor leg 1
6330 Ω resistor leg 2red LED anode (A, long leg)
7red LED cathode (C, short leg)I/O Expander PCF8574 P0

Step by step

  1. Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
  2. Add the parts. Add an I/O expander PCF8574, a 330 Ω resistor and a red LED from the parts palette.
  3. Wire 1. Connect Arduino Uno 5V to I/O Expander PCF8574 VCC.
  4. Wire 2. Connect Arduino Uno GND to I/O Expander PCF8574 GND.
  5. Wire 3. Connect Arduino Uno A4 to I/O Expander PCF8574 SDA.
  6. Wire 4. Connect Arduino Uno A5 to I/O Expander PCF8574 SCL.
  7. Wire 5. Connect Arduino Uno 5V to 330 Ω resistor leg 1.
  8. Wire 6. Connect 330 Ω resistor leg 2 to red LED anode (A, long leg).
  9. Wire 7. Connect red LED cathode (C, short leg) to I/O Expander PCF8574 P0.
  10. Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
  11. Run it. Press Run. Add LEDs on P1–P7 and write a pattern with io.write8().

Arduino C++ code

// PCF8574 (Rob Tillaart): eight extra I/O pins over I2C. P0 drives an LED.
#include <PCF8574.h>

PCF8574 io(0x20);

void setup() {
  Serial.begin(9600);
  Wire.begin();
  if (!io.begin()) {
    Serial.println("PCF8574 not found.");
    while (true) {}
  }
  Serial.println("PCF8574 ready.");
}

void loop() {
  io.write(0, LOW);   // LED from 5 V through the resistor into P0: LOW turns it on
  delay(500);
  io.write(0, HIGH);
  delay(500);
}

What to try

Add LEDs on P1–P7 and write a pattern with io.write8().

Frequently asked questions

How do I wire the PCF8574 I2C I/O Expander project on an Arduino Uno?

Make 7 connections: Arduino Uno 5V to I/O Expander PCF8574 VCC; Arduino Uno GND to I/O Expander PCF8574 GND; Arduino Uno A4 to I/O Expander PCF8574 SDA; Arduino Uno A5 to I/O Expander PCF8574 SCL; Arduino Uno 5V to 330 Ω resistor leg 1; 330 Ω resistor leg 2 to red LED anode (A, long leg); red LED cathode (C, short leg) to I/O Expander PCF8574 P0.

What parts do I need for this Arduino project?

An Arduino Uno and an I/O expander PCF8574, a 330 Ω resistor and a red LED.

Can I simulate this Arduino project online for free?

Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.

What does the code do?

Eight extra pins over I2C: P0 blinks an LED through a resistor from 5 V.

More Arduino Uno projects