How to Use PCF8574 GPIO Extender With Arduino or ESP32

by RonFrtek in Circuits > Arduino

782 Views, 2 Favorites, 0 Comments

How to Use PCF8574 GPIO Extender With Arduino or ESP32

How to Use PCF8574 GPIO Extender With Arduino or ESP32

If you require more pins for your project to connect more buttons, sensors or LEDs, GPIO expanders can help. Essentially, these expanders offer additional GPIOs when your board doesn't provide enough pins.

In this tutorial we will learn how to use PCF8574 I2C GPIO Expander with Arduino UNO or ESP32

Watch the Video!

Also check out this amazing Visuino tutorials on how to use PCF8574 I2C GPIO Expander:

Arduino and Visuino: Use PCF8574/PCF8574A I2C GPIO to Add More Digital Channels to Arduino : 12 Steps - Instructables

Arduino Nano: I2C Matrix Keypad With PCF8574/PCF8574A GPIO and Visuino : 11 Steps - Instructables

What You Will Need

PCF8574.jpeg
WROOM-32D.jpg
redled.jpg
arduino-button.png
jumper-wires.jpg
VisuinoAdvrtisemenESPNowESP32C3-1.jpg
breadboard.png
arduino.jpg
download (5).jpg
  • Arduino UNO or ESP32 (Or any other Board)
  • PCF8574 I2C GPIO Expander
  • To do the test experiment:
  • 2x 1k ohm resistor
  • LED
  • Jumper wires
  • Breadboard
  • Visuino program: Download Visuino


Brought by PCBWay

2022-08-26_13-41-18.jpg
FHUQHJ6LF9Y8DUL.png

Thank you PCBWay for supporting this tutorial and helping users learn more about electronics.

NEW! Now you can get Aluminum PCB & FLEX PCB in their Special Offer!

What I like about the PCBWay is that you can get 10 boards for approximately $5 which is really cost effective for professional made boards, not to mention how much time you save!

Go check them out here. They also offer a lot of other stuff in case you might need it like assembly3D printingCNC machining and a lot more.

The Circuit Using Arduino UNO

pcf8754.png

Connecting LED:

  • Connect PCF8574 pin [0] to 1K ohm resistor on the breadboard
  • Connect other side of the resistor to the LED pin [positive +]
  • Connect LED pin [negative -] to the breadboard negative pin [Black line]

Connecting Button:

  • Connect PCF8574 pin [1] to button on the breadboard and to the Resistor
  • Connect other side of the resistor to the breadboard pin [GND]
  • Connect Other pin of the button to the breadboard positive pin [5V]
  • Connect Arduino pin [5V] to breadboard positive pin [Red line]
  • Connect Arduino pin [GND] to breadboard negative pin [Black line]

Connecting PCF8574 :

  • Connect PCF8574 pin [VCC] to breadboard positive pin [Red line]
  • Connect PCF8574 pin [GND] to breadboard positive pin [Black line]
  • Connect PCF8574 pin [SCL] to Arduino pin [SCL]
  • Connect PCF8574 pin [SDA] to Arduino pin [SDA]


The Circuit Using Arduino ESP32

pcf8754-esp32.png

Connecting LED:

  • Connect PCF8574 pin [0] to 1K ohm resistor on the breadboard
  • Connect other side of the resistor to the LED pin [positive +]
  • Connect LED pin [negative -] to the breadboard negative pin [Black line]

Connecting Button:

  • Connect PCF8574 pin [1] to button on the breadboard and to the Resistor
  • Connect other side of the resistor to the breadboard pin [GND]
  • Connect Other pin of the button to the breadboard positive pin [5V]
  • Connect ESP32 pin [5V] to breadboard positive pin [Red line]
  • Connect ESP32 pin [GND] to breadboard negative pin [Black line]

Connecting PCF8574 :

  • Connect PCF8574 pin [VCC] to breadboard positive pin [Red line]
  • Connect PCF8574 pin [GND] to breadboard positive pin [Black line]
  • Connect PCF8574 pin [SCL] to ESP32 GPIO pin [22]
  • Connect PCF8574 pin [SDA] to ESP32 GPIO pin [21]


Start Visuino, and Select the Arduino UNO or ESP32 Board Type

select-board-uno.jpg
Visuino-Select-Board-UNO.jpg
ESP32-BOARD.jpg

Start Visuino as shown in the first picture Click on the "Tools" button on the Arduino component (Picture 1) in Visuino When the dialog appears, select "Arduino UNO" as shown on Picture 2 or "ESP32 Development Board" as shown on Picture 3

Experiment No.1 - in Visuino Add & Set Components

2023-05-15_19-13-14.png
2023-05-15_19-14-48.png
2023-05-15_19-15-55.png
2bb7f764b8432cd5357aacaee66e334c8a5ddecd.jpeg
2023-05-15_19-46-13.png
uno-gpio.png
esp32-gpio.png
  • Add "PCF8574" component
  • Add "Pulse Generator" component


  • Select "GPIO1" component and in the properties window set the I2C "Address", my module I2C Address was 32, you can check the pins on the module and compare it to the table as shown on Picture 4 or check the Step 7.


  • Connect "PulseGenerator1" pin [Out] to "GPIO1" pin Channel 0 [In]
  • Connect "GPIO1" pin I2C [Out] to the Board pin I2C [In]


  • Upload the Project to the Board, see the "Generate, Compile, and Upload the Arduino Code" Step on how to upload the project


How to Find the I2C Address of the Module With Visuino

2023-05-15_19-25-44.png
2023-05-15_19-29-10.png
2023-05-15_19-30-11.png
2023-05-15_19-30-45.png
2023-05-15_19-39-50.png
2023-05-15_19-39-20.png

Make sure that the module is connected to the board correctly (pins VCC,GND,SCL,SDA)

  • In Visuino select the board and in the properties window expand "I2C Channels" > "I2C" > "Elements" and click on the 3 dots button
  • In the "Elements" window Drag "I2C Scan" to the Left side
  • Close the "Elements" window
  • Add "Start" component


  • Connect "Start1" component to the board pin [Scan]
  • Connect board pin [Address] to the board Serial pin 0 [In]
  • Upload the Project to the Board, see the "Generate, Compile, and Upload the Arduino Code" Step on how to upload the project
  • Select the "Serial" tab and click "Connect" button and you should see the I2C Address of your module

Experiment No.2 - in Visuino Add & Set Components

2023-05-15_19-48-35.png
2023-05-15_19-49-04.png
2023-05-15_19-50-56.png
uno-gpio2.png
esp32-gpio2.png


  • Add "Debounce Button" component
  • Add "Toggle Flip Flop" component


  • Connect "GPIO1" pin Channel 2 [Out] to "Button1" pin [In]
  • Connect "Button1" pin [Out] to "TFlipFlop1" pin [Clock]
  • Connect "TFlipFlop1" pin [Out] to "GPIO1" pin Channel 1 [In]
  • Connect "GPIO1" pin I2C [Out] to the Board pin I2C [In]


  • Upload the Project to the Board, see the "Generate, Compile, and Upload the Arduino Code" Step on how to upload the project


Generate, Compile, and Upload the Arduino Code

FBR42I2KXBU01YW.jpg

In Visuino, at the bottom click on the "Build" Tab, make sure the correct port is selected, then click on the "Compile/Build and Upload" button.

Note: If you are using a ESP32 dev board then hold the "BOOT" when uploading the project

Play

If you power the Board in Experiment No.1 the LED will Blink and in the Experiment No.2 the LED will turn On or Off if you press the button.

Congratulations! You have completed your project with Visuino. Also attached is the Visuino project, that I created for this Instructable, you can download it here and open it in Visuino: https://www.visuino.eu