In this guide we will going to find and detect i2c address on our i2c device. You can scan and find the i2c address used by your devices by find the exact address used by the i2c device for more detail how i2c works please see this link, before we will going to begin you need to have the Arduino IDE and the source code sketch, the code below will scan and find the address which has been used by your i2c device. in this example we will going to used the i2c lcd 16×2 LCD display.  upload the source code to your Arduino board and then change the baud rate 115200, and push the reset button then see the result.

Scanned Output

Arduino Sketch (i2C Address Scanner)

i2C Scanner Sketch Code 2


Scanning i2C Device Address on Arduino
Tagged on:     


5 thoughts on “Scanning i2C Device Address on Arduino

  • at

    I2C scanner,,,,Huh? How did the output make decimal 39 = hex 0x3F

    • at


      void setup()

      while (!Serial); // Leonardo: wait for serial monitor
      Serial.println(“\nI2C Scanner”);

      void loop()
      byte error, address;
      int nDevices;


      nDevices = 0;
      for(address = 1; address < 127; address++ ) { // The i2c_scanner uses the return value of // the Write.endTransmisstion to see if // a device did acknowledge to the 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); Serial.println(" !"); nDevices++; } else if (error==4) { Serial.print("Unknow 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 for next scan }

  • at

    This code has an error, i2c address is 7 bit, not a byte.
    So you have to multiply by 2 the printed hex and decimal values

    Serial.print (2*i, DEC);
    Serial.print (” (0x”);
    Serial.print (2*i, HEX);

    • at

      Nop, my mistake, your code is correct, the problem was with my interpretation of the PCF8574 datasheet I was reading.
      Although I would change this part, because i have seen devices using address 127:

      for (byte i = 0; i < 128; i++)


Leave a Reply

Your email address will not be published. Required fields are marked *