PCF8574 I²C 8-LED Bargraph
Eight LEDs from two wires — an I²C GPIO expander in 30 minutes.
Difficulty: Breadboard. Estimated build time: about 35 minutes. Estimated parts cost: about US$2.50. 6-line bill of materials. Compare supplier offers when available. The PCF8574 is a slow but useful I²C-to-parallel chip: two wires in (SDA + SCL), eight quasi-bidirectional GPIOs out.
Set the I²C address
PCF8574 has three address pins — A0, A1, A2 (chip pins 1, 2, 3). Tie all three to GND for I²C address 0x20. Tie any combination to VCC if you want addresses 0x21 through 0x27 (eight chips on one bus, 64 GPIOs total).
Wire SDA, SCL, power, decoupling
VDD (pin 16) goes to your 5 V rail; VSS (pin 8) to GND. Drop a 100 nF ceramic between VDD and VSS as close to the chip as you can manage. SDA (pin 15) and SCL (pin 14) connect to the Arduino's A4 and A5. The PCF8574 datasheet asks for external pull-ups (4.7 kΩ to VCC) on SDA and SCL — most Arduino boards have weak internal pull-ups that work for short wires, but add the externals if your bus runs longer than 10 cm.
Wire the 8 LEDs
P0–P7 are chip pins 4, 5, 6, 7, 9, 10, 11, 12 (in that order — note the gap across VSS). For each output: P_pin → LED cathode → LED anode → 470 Ω resistor → VCC. Because the chip drives LOW to turn the LED on (sinking current), digitalWrite(LOW) lights the LED and digitalWrite(HIGH) turns it off — opposite of a typical Arduino direct-drive.
Install the PCF8574 library and test
Adafruit publishes a clean PCF8574 Arduino library. Install it through the IDE library manager. The hello-world is one line: pcf.begin(0x20). After that, pcf.digitalWrite(0, LOW) lights LED 0. Wrap that in a loop that walks 0–7 and you have a Knight Rider scanner over two wires.
Push the chip — bargraph mode
Read the value of A0 (a potentiometer on the Arduino) and map it to a 0–8 'level'. Light the bottom N LEDs and turn off the top 8−N — you now have a working VU-meter style bargraph driven by an I²C expander. Latency is ~1 ms per write, so refresh rate is well above flicker fusion. The same chip with eight buttons (and pull-ups disabled in software so we use the chip's internal pull-ups) gives you an 8-button keypad over two wires — same wiring, different code.