Bench NotesUno handbook

I²C Basics and a Bus Scanner

Wire an I²C module to A4/A5 and find its address with a scanner sketch before writing any driver code.

IntermediateI2C deviceSerial

Overview

I²C connects many devices over two shared wires: SDA (data) and SCL (clock). Each device has a 7-bit address; the Uno talks to one at a time by address. Displays, real-time clocks, port expanders and many sensors use it. On the Uno, SDA is A4 and SCL is A5 (also brought out to the two pins beside AREF on R3 boards).

You will need

  • Arduino Uno R3
  • Any 5 V-tolerant I²C module (e.g. a PCF8574 LCD backpack or DS3231 clock)
  • 4 jumper wires

Wiring

Uno pinConnects toNotes
5VModule VCCCheck the module's voltage
GNDModule GND
A4 (SDA)Module SDA
A5 (SCL)Module SCL
Wiring for I²C Basics and a Bus ScannerArduino Uno 5V to I²C module VCC; Arduino Uno GND to I²C module GND; Arduino Uno A4 (SDA) to I²C module SDA; Arduino Uno A5 (SCL) to I²C module SCL.Connections (each line is one wire)Arduino UnoI²C module5VVCCGNDGNDA4 (SDA)SDAA5 (SCL)SCL
Original wiring diagram. Each line is one jumper wire; boxes on a line are series resistors.

Pull-up resistors and voltage

I²C lines need pull-up resistors (typically 4.7 kΩ to the supply). Most breakout modules include them. With several modules on one bus their pull-ups combine; that is usually fine for two or three. A 3.3 V-only module must not be pulled up to 5 V: use a level shifter or a module with one built in.

Conflicts

Because I²C uses A4 and A5, they are not available for other uses while the bus is active. The workshop projects that drive A4 HIGH to power a potentiometer cannot share the board with an I²C device unless the pot is moved to other pins.

The sketch

i2c_scanner.ino
#include <Wire.h>

void setup() {
  Wire.begin();
  Serial.begin(9600);
  Serial.println("Scanning I2C bus...");
}

void loop() {
  int found = 0;
  for (byte address = 1; address < 127; address++) {
    Wire.beginTransmission(address);
    byte error = Wire.endTransmission();
    if (error == 0) {
      Serial.print("Device found at 0x");
      if (address < 16) {
        Serial.print("0");
      }
      Serial.println(address, HEX);
      found++;
    }
  }
  if (found == 0) {
    Serial.println("No devices found. Check wiring and power.");
  }
  Serial.println("Scan done.");
  Serial.println();
  delay(5000);
}

How the code works

endTransmission() returns 0 when a device acknowledges its address. Common addresses: 0x27 or 0x3F for PCF8574 LCD backpacks, 0x68 for DS3231 and MPU-6050, 0x3C for SSD1306 OLEDs. Use the address the scanner finds in that device's library.

What you should observe

  • Every five seconds the Monitor lists each connected device's address in hexadecimal.
  • "No devices found": swapped SDA/SCL is the usual cause, followed by missing power or ground.