Last Updated: 05/07/2025

MCP23017 I2C Port Expander

Components >> MCP23017 I2C Port Expander

MCP23017

The MCP23017 is an I2C controlled port expander. It has you extra ports in two banks of 8. Each bank can be set as inputs or outputs.

The default I2C address for the board is 0x20 but the can be changed allowing a total of 8 different addresses allowing multiple boards to be accessed on the same I2C bus. This would give a maximum of 128 (8 x 16) extra input or out pins.

Why use one?

No matter what Arduino or ESP32 board you use, there are certain projects that require more pins than your controller has as standard. These boards allow extra pins to be added and accessed. This tutorial shows how I set up and used the MCP23017 using the CLMCU-2317 module.

CJMCU-2317 Tutorial

Click to download the MCP23017 Datasheet

CJMCU-2317

In this example I will be using the CJMCU-2317 module as this does not require any other components to use.

NOTE: These boards are a bit of a problem when used on a breadboard due to the two rows of pins being next to each other.
I soldered the two lines of headers in the opposite direction to the A2 - VCC side. If I was doing it again for breadboard use I would probably solder headers facing down for one set and a header or female socket facing upwards for the other.

This does have the issue that if you want to use these in a project the ones you use for breadboard work may not be useable for your finished project.

Changing the board address

Connecting pins A0 - A2 to VCC will change the board address, there are 7 possible combinations plus no connections giving a total of 8 addresses.


MCP23017 CJMCU-2317 Module

Circuit diagram

In the diagram below I have only put one led and one button as examples.

NOTE: Each bank can be an set as INPUT or OUTPUT but cannot be a mixture.

IMPORTANT: For inputs all pins MUST have a pull down resistor, even if you are not using them as the pins will float and give you false readings without them.
CJMCU-2317 Arduino Uno Circuit Diagram

Code:

Click to download code examples

Additional Resource Links

An alternative to the MCP23017 id the CD4021BE and 74HC595N shift registers. They are able to exceed the 128 pin limit.
Links to tutorials on the shift registers are below. These titurials also show how to bit shift to get values in and out of bytes with a methodology that can be adapted for the MCP23017.

Arduino C++ CD4021BE Shift register Arduino UNO, MEGA

Arduino C++ 74HC595N Shift register Arduino UNO, MEGA

Lesson 3 Controlliong timings with if() and millis()

Lesson 9 - Arrays and for() loop

Comments


This site has been designed to be child friendly, this means that comments cannot be added to videos or directly to the site.
To add a comment or ask a question please email the address in this image: and use MCP23017 I2C Port Expander as a reference.