How to Find I2C Address Using Arduino

I2C Scanner Code

How to get and read an I2C Address from an I2C Device Using an Arduino – In this tutorial, I will share how to get or find an I2C address from an I2C device, in which we don’t know the address of the device.

In the Sparkfun I2C tutorial, how the I2C system works, you can read it here.

Prepare I2C Device

There is a simple program that can read the I2C address from the device automatically. The program is called I2C Scanner.

So that this program can read the I2C address from an I2C device, the first step is to connect the Arduino to the device.

For example,  I use the RTC Module with I2C communicaion. In the current state, I don’t know the address of the module, so I can’t read anything on the RTC.

Now connect the Arduino and the I2C device using the following configuration wiring:


I2C Scanner Code

After that, use the I2C Scanner program code, before upload that code, this code using Version 6.

Version 1

This program (or code that looks like it) can be found in many places. For example on the forum. Original author unknown.

Version 2, June 2012, Using Arduino 1.0.1

Adapted to be as simple as possible by user Krodal

Version 3, 26 Feb 2013, by louarnold

Version 4, March 3, 2013, Using Arduino 1.0.3

By user Krodal. Changes by louarnold are removed. Scan address changed from 0 … 127 to 1 … 119, according to an i2c scanner by Nick Gammon (

Version 5, 28 March 2013

As of version 4, but the scan address is now to 127. The sensor seems to use address 120.

Version 6, 27 November 2015

Added waiting for Leonardo’s serial communication. This sketch tests a standard 7-bit address. Devices with a higher bit address may not appear correctly.

Now, upload the following code to Arduino Uno. 

#include <Wire.h>
void setup()
  while (!Serial);            
  Serial.println("\nI2C Scanner");
void loop()
  byte error, address;
  int nDevices;
  nDevices = 0;
  for(address = 1; address < 127; address++ )
    error = Wire.endTransmission();
    if (error == 0)
      Serial.print("I2C Address is 0x");
      if (address<16)
      Serial.println("  !");
    else if (error==4)
      Serial.print("Unknown address at 0x");
      if (address<16)
  if (nDevices == 0)
    Serial.println("Not found I2C Address \n");
  delay(5000);           // wait 5 seconds for next scan

Then open the serial monitor and you will see the I2C address in a Hexadecimal number.

In the experiments that I did with this RTC module, I got the result with the address is 0x68.

How to Get I2C Address Using Arduino I2C Scanner Code

If you find this article is useful, please share it with your friends using the share button below.

Similar Posts