Table of contents
  1. The structure of I2C
  2. Deciding the pull-up resistor value
  3. Matching voltages
  4. Addresses and conflicts
  5. Wiring tips
  6. The order to check when it does not work
  7. Summary

I2C is a communication method that connects several sensors and displays with two wires (SDA and SCL). The wiring is simple, so it is used very often in perfboard projects, for things like temperature sensors, OLED screens, and clock modules. But "I connected it clearly, yet the device does not show up" is the most common problem, and it is mostly caused by one of the pull-up resistors, the address, the wiring, or the power. This article covers the structure of an I2C bus, how to decide pull-up resistor values, device address problems, and the order to check when it does not work.

The structure of I2C

  • SDA: the data line
  • SCL: the clock line
  • Master: the device that starts communication and makes the clock (the microcontroller)
  • Slave: devices such as sensors and displays. Each device has a unique 7-bit address.

SDA and SCL are open drain. A device can only pull the line Low, and High is made by a pull-up resistor lifting it toward the supply. So without pull-up resistors, the line cannot rise and communication does not work.

ModeSpeedNotes
Standard mode100 kHzMost stable, the beginner default
Fast mode400 kHzSupported by many sensors and OLEDs

Deciding the pull-up resistor value

If the value is too large, the line rises slowly and the signal dulls; if too small, the current becomes large when a device pulls the line Low, which causes problems.

  • Typical value: 4.7 kΩ on a 3.3 V or 5 V bus (100 kHz), and 2.2 kΩ to 3.3 kΩ for fast mode or long lines
  • Minimum: decided by the current a device can sink (usually 3 mA). R_min ≈ (supply − 0.4 V) ÷ 3 mA, so about 1 kΩ at 3.3 V and about 1.5 kΩ at 5 V.
  • Maximum: decided by the line capacitance (C) and the required rise time. R_max ≈ rise time ÷ (0.85 × C). The standard mode rise-time limit is 1000 ns, so with C = 100 pF you can go up to about 11.8 kΩ.

Put one pull-up resistor each on SDA and SCL (two in total). For how to read resistor values, see Reading Resistors.

Matching voltages

The High of I2C is the supply voltage the pull-ups are connected to. Do not mix 3.3 V and 5 V devices on one bus.

  • Make all devices work at the same voltage, or
  • if they differ, use a bidirectional level shifter (Connecting 3.3V and 5V Signals).
  • Make sure a 5 V pull-up does not end up on a 3.3 V microcontroller pin.

Addresses and conflicts

Each device has a 7-bit address (a value in the range 0x08 to 0x77) and these must not overlap on the same bus.

  • Sensor modules often have a jumper or pins (A0, A1) that change the address.
  • To use several of the same kind of device, separate them with the address pins, or split channels with an I2C multiplexer (such as the TCA9548A).
  • To check which addresses respond, run an I2C scanner program on the microcontroller, and it prints the addresses of all connected devices.

Wiring tips

  • Short: within tens of centimeters is stable at 100 kHz. If longer, the line capacitance rises and you have to reduce the pull-ups and lower the speed.
  • Run SDA and SCL side by side but away from other signal lines. The clock line injects noise into neighboring lines.
  • Common ground: connect the GND of all devices. Without ground, the signal references differ and communication fails (Power Rails, Grounding, and Decoupling Capacitor Placement).
  • Put a 100 nF close to each device's power pin.
  • On perfboard, connect SDA and SCL lightly with jumper wires, and keeping the pull-up resistors together in one place on the microcontroller side makes them easy to manage.

The order to check when it does not work

StepCheckMethod
1PowerMeasure that the device's VCC voltage (3.3 V/5 V) is right
2GroundContinuity-test that all GNDs are connected
3SDA and SCL positionsCheck they are not swapped and the pin numbers are right
4Pull-upsMeasure that the lines are normally High (0 V means no pull-up or a short)
5VoltageCheck the device and microcontroller logic voltages are the same
6AddressCheck addresses with a scanner program, look for conflicts
7SpeedIf there is a problem, lower the speed to 100 kHz and test
8WaveformCheck the signal with an oscilloscope or logic analyzer (Oscilloscope Basics)

If SDA or SCL is Low even at rest, a device is holding the line or there is a short. If it sits at an in-between voltage, not High, at rest, there is no pull-up or it is too large. Most problems can be found in steps 1 to 4 of the checklist (It Is Finished but It Does Not Work: A Step-by-Step Checklist).

Summary

I2C consists of the two lines SDA and SCL, a pull-up resistor on each (usually 4.7 kΩ), a common ground, the same logic voltage, and non-overlapping addresses. Check whether the modules already have pull-ups, keep the wires short, and when it fails, check power and addresses first. How to mount a board on perfboard continues in Mounting a Development Board on Perfboard.

This article is general guidance for learning purposes. Specifications and pinouts differ between parts, so check the datasheet of the part you use before real work. For safety-related work, read the cautions for each item first.