I2C Bus Master Tool: Find Your Devices Fast! 🚀
Welcome! If you’re struggling to find the address of your sensor, you’re not alone. The $\text{I}^2\text{C}$ (or Two-Wire Interface,) communication protocol is powerful, but address conflicts are a common headache.
Use this simple, reliable I2C scanner sketch for your Arduino Uno. It will instantly check all possible addresses and report exactly where your connected devices are, getting you back to building!
What is a serial scanner on I2C
An I2C scanner is a specialized Arduino sketch that systematically checks all possible addresses 0x08 to ox77. For each address, it sends a brief request to see if a device acknowledges the call. If a device responds, the scanner reports its address, confirming a successful connection and helping you debug your hardware setup instantly.
The Code: Arduino $\text{I}^2\text{C}$ Scanner Sketch
Copy and paste this minimal code directly into your Arduino IDE.
C++
// --------------------------------------
// I2C Scanner
// --------------------------------------
//
// This sketch will scan the I2C bus for all devices
// and print their addresses to the Serial Monitor.
//
// --------------------------------------
#include <Wire.h>
void setup() {
Wire.begin(); // Initialize the I2C communication
Serial.begin(9600); // Start serial communication
while (!Serial); // Wait for serial port to connect.
Serial.println("\nI2C Scanner");
}
void loop() {
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
// I2C addresses are 7-bit values, typically from 0x08 to 0x77.
for (address = 1; address < 127; address++) {
// We create a function to scan the bus for an address
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0) {
Serial.print("I2C device found at address 0x");
if (address < 16)
Serial.print("0");
Serial.print(address, HEX); // Print address in Hexadecimal format
Serial.println(" !");
nDevices++;
} else if (error == 4) {
Serial.print("Unknown error at address 0x");
if (address < 16)
Serial.print("0");
Serial.println(address, HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // Wait 5 seconds before scanning again
}
⚙️ Setup and Instructions
Follow these four simple steps to get your devices scanned:
1. Hardware Connection
Connect your $\text{I}^2\text{C}$ devices to your Arduino Uno using the designated pins:
- SDA (Serial Data Line): Connect to Analog Pin A4
- SCL (Serial Clock Line): Connect to Analog Pin A5
- VCC: Connect to $5\text{V}$
- GND: Connect to GND
2. Software Setup
- Open the Arduino IDE.
- Go to Sketch $\rightarrow$ Include Library $\rightarrow$ Wire. (It should be included by default, but this verifies it.)
- Copy the code above and paste it into a new sketch.
3. Run the Scanner
- Select your correct Board (Arduino Uno) and Port in the IDE.
- Click the Upload button.
- Once uploaded, open the Serial Monitor (Tools $\rightarrow$ Serial Monitor or Ctrl+Shift+M / Cmd+Shift+M).
- Ensure the baud rate in the Serial Monitor is set to $9600$ to match the
Serial.begin(9600)line in the code.
4. Check the Output
The Serial Monitor will display the results, showing the Hex address of every device found:
I2C Scanner
Scanning...
I2C device found at address 0x3C ! <-- This is likely an OLED screen
I2C device found at address 0x76 ! <-- This is likely a BME280 sensor
done
Scanning...
No I2C devices found
done
Troubleshooting Tips
| Problem | Potential Solution |
| “No I2C devices found” | Check your wiring carefully, especially $\text{A4}$ ($\text{SDA}$) and $\text{A5}$ ($\text{SCL}$). Ensure all devices are properly powered ($\text{VCC}$ to $5\text{V}$, $\text{GND}$ to $\text{GND}$). |
| Unknown Error (error 4) | This is a generic error; try a different set of pull-up resistors or simplify your bus by connecting only one device at a time. |
| Scanner only runs once | The delay(5000); pauses for $5\text{ seconds}$ before scanning again. If you only want one scan, remove the delay and move the scanning code from the loop() function to the setup() function. |