I2C scanner and address map lab
Build it step by step
0 of 8 doneWire one module
For example the OLED on A4, A5, 5V and GND.
Upload the sketch
Serial monitor starts scanning every 3 seconds.
Check the result
The OLED shows at 0x3C.
Add the light sensor
BH1750 appears at 0x23.
Add the clock
DS3231 appears at 0x68 and its EEPROM at 0x57.
Unplug SDA from one module
It disappears from the list.
Tie ADDR high on the BH1750
It moves from 0x23 to 0x5C.
Make a note
Write down the addresses of your own modules.
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
| From | To | Why |
|---|---|---|
| Uno A4 (SDA) | SDA on every module | Shared data line |
| Uno A5 (SCL) | SCL on every module | Shared clock line |
| Uno 5V | VCC on every module | Check each module voltage |
| Uno GND | GND on every module | Common ground |
| Modules | BH1750, DS3231 clock and OLED | Three 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.
| Check | Expected |
|---|---|
| Nothing connected | No devices found |
| OLED connected | 0x3C found |
| Three modules connected | Three or four addresses listed |
| SDA unplugged | No devices found |
| ADDR pin changed | Address 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 →
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.
