Using the MCP23017 with Arduino involves wiring up the expander to your Arduino-compatible microcontroller, installing the Adafruit MCP23017 library and running the provided example code.


Wire as shown for a 5V board like an Uno. If you are using a 3V board, like an Adafruit Feather, wire the board's 3V pin to the MCP23017 VIN.

Here is an Adafruit Metro, a button and an LED wired up to the MCP23017 using a solderless breadboard:


  • Board 5V to expander VIN (red wire)
  • Board GND to expander GND (black wire)
  • Board SCL to expander SCL (yellow wire)
  • Board SDA to expander SDA (blue wire)


  • LED + to 470Ω resistor
  • LED - to Board GND (black wire)
  • 470Ω resistor to expander A0 (pink wire)


  • Button leg to expander A1 (green wire)
  • Opposite button leg to Board GND (black wire)

Library Installation

You can install the MCP23017 library for Arduino using the Library Manager in the Arduino IDE.

Click the Manage Libraries ... menu item, search for MCP23017, and select the Adafruit MCP23017 Arduino Library library:

If asked about dependencies, click "Install all".

If the "Dependencies" window does not come up, then you already have the dependencies installed. 

If the dependencies are already installed, you must make sure you update them through the Arduino Library Manager before loading the example!

Load Example

Open up File -> Examples -> Adafruit MCP23017 Arduino Library -> mcp23xxx_combo. Before uploading the code, comment out the mcp instance using the Adafruit_MCP23X08 class, and uncomment the mcp instance using the Adafruit_MCP23X17 class.

// uncomment appropriate line
// Adafruit_MCP23X08 mcp;
Adafruit_MCP23X17 mcp;
// Controls an LED via an attached button.

// ok to include only the one needed
// both included here to make things simple for example
#include <Adafruit_MCP23X08.h>
#include <Adafruit_MCP23X17.h>

#define LED_PIN 0     // MCP23XXX pin LED is attached to
#define BUTTON_PIN 1  // MCP23XXX pin button is attached to

// only used for SPI
#define CS_PIN 6

// uncomment appropriate line
Adafruit_MCP23X08 mcp;
//Adafruit_MCP23X17 mcp;

void setup() {
  //while (!Serial);
  Serial.println("MCP23xxx Combo Test!");

  // uncomment appropriate mcp.begin
  if (!mcp.begin_I2C()) {
  //if (!mcp.begin_SPI(CS_PIN)) {
    while (1);

  // configure LED pin for output
  mcp.pinMode(LED_PIN, OUTPUT);

  // configure button pin for input with pull up


void loop() {
  mcp.digitalWrite(LED_PIN, !mcp.digitalRead(BUTTON_PIN));

Upload the sketch to your board and open up the Serial Monitor (Tools -> Serial Monitor) at 9600 baud. You should see the text "Looping..." in the Serial Monitor.

When you press the button, the LED will light up.

That's all there is to using the MCP23017 STEMMA breakout with Arduino!

This guide was first published on Mar 23, 2022. It was last updated on Jul 22, 2024.

This page (Arduino) was last updated on Jul 22, 2024.

Text editor powered by tinymce.