Projects / I2C scanner and address map lab

I2C scanner and address map lab

Beginner1 hGuided buildReviewed

Build it step by step

0 of 8 done
  1. UNO11.6 mASSD1306

    Wire one module

    For example the OLED on A4, A5, 5V and GND.

  2. UNO

    Upload the sketch

    Serial monitor starts scanning every 3 seconds.

  3. UNO11.6 mASSD1306

    Check the result

    The OLED shows at 0x3C.

  4. UNOBH1750364 lux

    Add the light sensor

    BH1750 appears at 0x23.

  5. UNODS323116:06

    Add the clock

    DS3231 appears at 0x68 and its EEPROM at 0x57.

  6. UNO

    Unplug SDA from one module

    It disappears from the list.

  7. UNOBH1750366 lux

    Tie ADDR high on the BH1750

    It moves from 0x23 to 0x5C.

  8. UNO

    Make a note

    Write down the addresses of your own modules.

In short

How do you build an I2C scanner and address map lab?

A short sketch finds every I2C device on a bus and names the common ones, so you can debug wiring and address clashes. You need Arduino Uno R3, BH1750 light sensor, DS3231 RTC module, SSD1306 OLED Display, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm). It takes 8 steps and about 60 minutes.

Level
Beginner
Time
About 60 min
Parts
6

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
Uno A4 (SDA)SDA on every moduleShared data line
Uno A5 (SCL)SCL on every moduleShared clock line
Uno 5VVCC on every moduleCheck each module voltage
Uno GNDGND on every moduleCommon ground
ModulesBH1750, DS3231 clock and OLEDThree different addresses on one bus

Code

I2C is a two-wire bus where each device answers to its own 7-bit address. The scanner tries every address from 8 to 119 and sends an empty message. A device that exists replies with an acknowledge, so endTransmission returns 0. The list of known addresses is only a guide, because different chips share addresses: 0x68 is used by the DS3231 clock, the MPU6050 and the DS1307, so two of them cannot sit on one bus without changing an address pin. Common faults the scanner reveals are SDA and SCL swapped, a device without power, a missing pull-up resistor (most breakout boards have them), two devices on the same address, and a bus that is held low by a faulty device, which shows as every address responding or an error. The Uno uses A4 for SDA and A5 for SCL. A 3.3 V-only module needs a level shifter on a 5 V Uno, or must be powered at 3.3 V with care that its pull-ups go to 3.3 V as well.

Runs on a virtual Arduino Uno in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).

#include <Wire.h>

struct Known { uint8_t addr; const char* name; };
const Known KNOWN[] = {
  {0x23, "BH1750 light sensor (ADDR low)"},
  {0x3C, "SSD1306 OLED"},
  {0x3D, "SSD1306 OLED (alternate)"},
  {0x27, "LCD backpack PCF8574"},
  {0x3F, "LCD backpack PCF8574A"},
  {0x57, "AT24C32 EEPROM on DS3231 board"},
  {0x68, "DS3231 clock, MPU6050 or DS1307"},
  {0x76, "BME280 or BMP280"},
  {0x77, "BME280, BMP280 or BMP180"},
  {0x5C, "BH1750 (ADDR high)"},
  {0x40, "INA219 or PCA9685"},
  {0x48, "ADS1115 or PCF8591"}
};

const char* nameFor(uint8_t a) {
  for (uint8_t i = 0; i < sizeof(KNOWN) / sizeof(KNOWN[0]); i++)
    if (KNOWN[i].addr == a) return KNOWN[i].name;
  return "unknown device";
}

void setup() {
  Wire.begin();
  Serial.begin(9600);
  while (!Serial) {}
}

void loop() {
  Serial.println("Scanning I2C bus...");
  uint8_t found = 0;
  for (uint8_t a = 8; a < 120; a++) {          // valid 7-bit addresses are 0x08 to 0x77
    Wire.beginTransmission(a);
    uint8_t err = Wire.endTransmission();
    if (err == 0) {
      Serial.print("  0x");
      if (a < 16) Serial.print('0');
      Serial.print(a, HEX);
      Serial.print("  ");
      Serial.println(nameFor(a));
      found++;
    } else if (err == 4) {
      Serial.print("  error at 0x"); Serial.println(a, HEX);
    }
  }
  if (found == 0) Serial.println("  No devices found. Check wiring, power and pull-ups.");
  else { Serial.print("  Found "); Serial.print(found); Serial.println(" device(s)."); }
  Serial.println();
  delay(3000);
}

What the serial monitor should show

Open the serial monitor at the baud rate in the code. This is what our simulator prints for a virtual Arduino Uno with its sensors at their default values. Your numbers will follow your real readings, but the format should match.

Scanning I2C bus...
0x3C  SSD1306 OLED
Found 1 device(s).
Scanning I2C bus...
0x3C  SSD1306 OLED
Found 1 device(s).

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Nothing connectedNo devices found
OLED connected0x3C found
Three modules connectedThree or four addresses listed
SDA unpluggedNo devices found
ADDR pin changedAddress changes

If it does not work

No devices found

Check SDA and SCL are not swapped and the module has power.

Every address responds

A device is holding the bus low, remove modules one by one.

Address not in my list

Look at the module datasheet, the list is only a guide.

Intermittent results

Shorten wires, check for loose breadboard contacts.

3.3 V module misbehaves

Check its voltage and use a level shifter on a 5 V board.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the I2C scanner and address map lab?

Arduino Uno R3, BH1750 light sensor, DS3231 RTC module, SSD1306 OLED Display, Breadboard 830 Tie Points and Jumper wires male to male (40 pcs, 20 cm).

How long does the I2C scanner and address map lab take to build?

About 60 minutes for a beginner maker, in 8 steps.

How do I know the I2C scanner and address map lab works?

Nothing connected: No devices found. OLED connected: 0x3C found. Three modules connected: Three or four addresses listed.

No devices found: what should I check?

Check SDA and SCL are not swapped and the module has power.

Every address responds: what should I check?

A device is holding the bus low, remove modules one by one.

Address not in my list: what should I check?

Look at the module datasheet, the list is only a guide.

Intermittent results: what should I check?

Shorten wires, check for loose breadboard contacts.