Find I2C device addresses for sensors, displays, and expanders.
Open in compiler →/*
Roboda verified Arduino sample 0784
Feature: I2C Scan
Generated for online build, classroom practice, and hardware upload testing.
*/
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
for (byte address = 1; address < 127; address++) {
Wire.beginTransmission(address);
if (Wire.endTransmission() == 0) {
Serial.print("I2C device at 0x");
Serial.println(address, HEX);
}
}
delay(3000);
}
How it works
Discover I2C addresses on the board SDA/SCL bus.
- Wire SDA and SCL using the board-specific map.
- Share GND between all I2C devices.
- Run the scanner and open Serial Monitor.
- Use the printed address in later sensor/display sketches.
Connections
| Pin | Connect to | Note |
|---|---|---|
| SDA / SCL | I2C sensor, OLED, RTC, or expander | Use the board-specific SDA/SCL pins from the mapping table. |