// i2c_scanner
#include <Wire.h>

void setup() 
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println("I2C scanner start");

  Wire.begin();
}

void loop() 
{
  int devicesQty = 0;
  Serial.println("Scanning...");

  for (byte address = 1; address < 127; address++) 
  {
    // transmitting address to I2C bus
    Wire.beginTransmission(address);
    byte error = Wire.endTransmission();

    // Wire.endTransmission() will return 0 only if an ACK is received
    // from the subscriber with the current address

    if (error == 0) 
    {
      Serial.print("Device found at address 0x");
      if (address < 16)
        Serial.print("0");
      Serial.println(address, HEX);
      devicesQty++;
    } 
    delayMicroseconds(1);
  }

  if (devicesQty == 0)
    Serial.println("No device found");
  else
  {
    Serial.print(devicesQty);
    Serial.println(" devices found");
  }

  Serial.println();
  delay(5000);
}
