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

STEP 1
What You Will Need
  • 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

 

What You Will Need

What You Will Need photo 2

What You Will Need photo 3

What You Will Need photo 4

What You Will Need photo 5

What You Will Need photo 6

What You Will Need photo 7

What You Will Need photo 8

What You Will Need photo 9

STEP 2
Brought by PCBWay

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.

Brought by PCBWay

Brought by PCBWay photo 2

STEP 3
The Circuit Using Arduino UNO

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 UNO

STEP 4
The Circuit Using Arduino ESP32

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]

 

The Circuit Using Arduino ESP32

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

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

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

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

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

STEP 6
Experiment No.1 - in Visuino Add & Set Components
  • 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

 

Experiment No.1 - in Visuino Add & Set Components

Experiment No.1 - in Visuino Add & Set Components photo 2

Experiment No.1 - in Visuino Add & Set Components photo 3

Experiment No.1 - in Visuino Add & Set Components photo 4

Experiment No.1 - in Visuino Add & Set Components photo 5

Experiment No.1 - in Visuino Add & Set Components photo 6

Experiment No.1 - in Visuino Add & Set Components photo 7

STEP 7
How to Find the I2C Address of the Module With Visuino

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

How to Find the I2C Address of the Module With Visuino

How to Find the I2C Address of the Module With Visuino photo 2

How to Find the I2C Address of the Module With Visuino photo 3

How to Find the I2C Address of the Module With Visuino photo 4

How to Find the I2C Address of the Module With Visuino photo 5

How to Find the I2C Address of the Module With Visuino photo 6

STEP 8
Experiment No.2 - in Visuino Add & Set Components

 

  • 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

 

Experiment No.2 - in Visuino Add & Set Components

Experiment No.2 - in Visuino Add & Set Components photo 2

Experiment No.2 - in Visuino Add & Set Components photo 3

Experiment No.2 - in Visuino Add & Set Components photo 4

Experiment No.2 - in Visuino Add & Set Components photo 5

STEP 9
Generate, Compile, and Upload the Arduino Code

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

Generate, Compile, and Upload the Arduino Code

STEP 10
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

icon PCF8754-Exp1-ESP32.zip 9KB Download(0)
icon PCF8754-Exp1-UNO.zip 6KB Download(0)
icon PCF8754-Exp2-ESP32.zip 10KB Download(0)
icon PCF8754-Exp2-UNO.zip 7KB Download(0)
License
All Rights
Reserved
licensBg
0