Go back

Pico I2C Scanner: Find Devices on the Bus

Introduction

I2C (Inter-Integrated Circuit) is a popular communication protocol that lets microcontrollers talk to sensors, displays, and other peripherals using just two wires: SDA (data) and SCL (clock). But when you’re prototyping, you often don’t know the exact address of a new I2C device. That’s where an I2C scanner comes in handy. It probes every possible address on the bus and reports which ones respond.

In this tutorial, we’ll build an I2C scanner for the Raspberry Pi Pico using the Velxio in-browser simulator. You’ll learn how to wire up a simple circuit with two indicator LEDs, write the scanning code in Arduino C++, and interpret the results. No hardware needed—just your browser!

Circuit diagram of pico-i2c-scanner on the Velxio simulator canvas

Circuit Walkthrough

Our circuit is minimal but instructive. We’ll use two LEDs to give visual feedback during scanning:

Both LEDs share a common ground connection to the Pico’s GND.1 pin. The I2C bus itself uses the default pins: SDA = GP4 and SCL = GP5. No external pull-up resistors are needed because the Pico’s internal pull-ups are enabled by the Wire library.

To build this circuit in Velxio:

  1. Open the component picker from the canvas toolbar. Velxio component picker modal browsing parts by category
  2. Add a Raspberry Pi Pico board.
  3. Add two LEDs (blue and green) from the Output category.
  4. Wire them as described: GP12 → blue LED anode, GP10 → green LED anode, both cathodes → GND.
  5. Use the canvas toolbar to zoom and arrange components neatly. Velxio canvas toolbar above the simulation viewport

Code Walkthrough

Now let’s dive into the code. Open the code editor in Velxio and paste the following sketch:

// Raspberry Pi Pico — I2C Scanner
// Scans I2C bus (Wire / I2C0: SDA=GP4, SCL=GP5) for devices

#include <Wire.h>

void setup() {
  Serial.begin(115200);
  delay(500);
  Wire.begin(); // SDA=GP4, SCL=GP5 by default on Pico
  Serial.println("=== Pico I2C Scanner ===");
  Serial.println("Default I2C0: SDA=GP4, SCL=GP5");
  Serial.println();
}

void loop() {
  Serial.println("Scanning I2C bus...");
  int found = 0;

  for (byte addr = 1; addr < 127; addr++) {
    Wire.beginTransmission(addr);
    byte error = Wire.endTransmission();

    if (error == 0) {
      found++;
      Serial.print("  Device found at 0x");
      if (addr < 16) Serial.print("0");
      Serial.print(addr, HEX);

      // Identify known addresses
      switch (addr) {
        case 0x48: Serial.print(" (Temperature sensor)"); break;
        case 0x50: Serial.print(" (EEPROM)"); break;
        case 0x68: Serial.print(" (DS1307 RTC)"); break;
        case 0x27: Serial.print(" (LCD backpack)"); break;
        case 0x3C: Serial.print(" (SSD1306 OLED)"); break;
        default: break;
      }
      Serial.println();
    }
  }

  Serial.print("Scan complete. Found ");
  Serial.print(found);
  Serial.println(" device(s).");
  Serial.println();
  delay(5000);
}

How It Works

To compile and run, click the compile button in the editor toolbar. Velxio editor toolbar with compile and run controls

Key Concepts

Common Pitfalls & Debugging Tips

Suggested Extensions

Try It Yourself!

Ready to scan the I2C bus? Open the live example in Velxio and start experimenting:

Launch the Pico I2C Scanner on Velxio

No downloads, no soldering—just pure simulation. Modify the code, add new components, and see the results instantly. Happy scanning!


Share this post on:
David Montero

Written by

David Montero

Creator of Velxio, the open-source circuit and Arduino simulator.

GitHub velxio.dev

Related posts


Previous Post
Read a Virtual DS1307 RTC with Raspberry Pi Pico I2C
Next Post
Pico Serial LED Control: Build Your First Command Interface