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
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | I/O Expander PCF8574 | Eight extra pins over I²C (0x20–0x27): Wire.write(byte) sets P0–P7 (0 = LOW, 1 = released high); Wire.requestFrom reads them back. |
| 1 | 330 Ω resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
| 1 | red LED | Lights when A (anode, the bent leg) is high and C (cathode) is low. Use a resistor. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno 5V | I/O Expander PCF8574 VCC |
| 2 | Arduino Uno GND | I/O Expander PCF8574 GND |
| 3 | Arduino Uno A4 | I/O Expander PCF8574 SDA |
| 4 | Arduino Uno A5 | I/O Expander PCF8574 SCL |
| 5 | Arduino Uno 5V | 330 Ω resistor leg 1 |
| 6 | 330 Ω resistor leg 2 | red LED anode (A, long leg) |
| 7 | red LED cathode (C, short leg) | I/O Expander PCF8574 P0 |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add an I/O expander PCF8574, a 330 Ω resistor and a red LED from the parts palette.
- Wire 1. Connect Arduino Uno 5V to I/O Expander PCF8574 VCC.
- Wire 2. Connect Arduino Uno GND to I/O Expander PCF8574 GND.
- Wire 3. Connect Arduino Uno A4 to I/O Expander PCF8574 SDA.
- Wire 4. Connect Arduino Uno A5 to I/O Expander PCF8574 SCL.
- Wire 5. Connect Arduino Uno 5V to 330 Ω resistor leg 1.
- Wire 6. Connect 330 Ω resistor leg 2 to red LED anode (A, long leg).
- Wire 7. Connect red LED cathode (C, short leg) to I/O Expander PCF8574 P0.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- 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
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino Capacitance Meter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator