Fork me on GitHub

Project Notes

#397 I²C Scanner

Scanning for I²C devices with an Arduino.



This is a simple sketch, inspired by i2c_scanner that simply scans for the presence of addresses in the full 7-bit address space.

This can be very helpful when trying to use I²C modules where the default address is not documented.

About I²C

I²C (Inter-Integrated Circuit) is a communications bus specification invented in 1982 by Philips Semiconductor. Patents on I²C have now lapsed and trademark protection only remains for the logo.

I²C is now generally supported by many manufacturers, but it is also known as TWI (Two-Wire Interface) or TWSI (Two-Wire Serial Interface) Note: in some cases, the term “two-wire interface” may hint at incomplete implementation of the I²C specification.

I²C provides bi-directional communication for many devices in a master-slave configuration over two wires.

I²C addresses are used to select between devices on a single bus. There are 7-bit and 10-bit address modes:

  • 7-bit addresses are most commonly used in microcontroller peripherals
  • 10-bit addresses are not yet widely used, and support is limited
  • the sketch here only looks for 7-bit addresses


The I2CScanner sketch runs an address scan every 5 seconds and prints the address of any found devices over the serial port.


It uses the standard Wire Library to attempt to begin a (null) transmission to each device address. The Wire.endTransmission() return code indicates the status of the transmission:

  • 0:success
  • 1:data too long to fit in transmit buffer
  • 2:received NACK on transmit of address
  • 3:received NACK on transmit of data
  • 4:other error

Any device that returns 0 is reported as a valid address.


Pull-up resistors may need to be provided if they are not already present on the I²C two-wire bus.




Credits and References

Project Source on GitHub Project Gallery Return to the LEAP Catalog

This page is a web-friendly rendering of my project notes shared in the LEAP GitHub repository.

LEAP is just my personal collection of projects. Two main themes have emerged in recent years, sometimes combined:

  • electronics - usually involving an Arduino or other microprocessor in one way or another. Some are full-blown projects, while many are trivial breadboard experiments, intended to learn and explore something interesting
  • scale modelling - I caught the bug after deciding to build a Harrier during covid to demonstrate an electronic jet engine simulation. Let the fun begin..
To be honest, I haven't quite figured out if these two interests belong in the same GitHub repo or not. But for now - they are all here!

Projects are often inspired by things found wild on the net, or ideas from the many great electronics and scale modelling podcasts and YouTube channels. Feel free to borrow liberally, and if you spot any issues do let me know (or send a PR!). See the individual projects for credits where due.