The display won't light, the sensor returns zeros, and the library says "not found". I2C problems are among the biggest time-wasters. But there's a clear order to follow, and if you work through it, you'll find the problem. If you need the basics first, see UART, I2C and SPI.
1. Run an I2C scanner
This always comes first:
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
for (byte a = 1; a < 127; a++) {
Wire.beginTransmission(a);
if (Wire.endTransmission() == 0) {
Serial.print("Found 0x");
Serial.println(a, HEX);
}
}
Serial.println("done");
}
void loop() {}
- Found the device? The problem is in the code or the address in the library.
- Found nothing? The problem is in the wiring, the power or the pull-ups.
- It hung and never printed "done"? The bus is probably held at ground (SDA or SCL shorted).
2. The correct pins
| Board | SDA | SCL |
|---|---|---|
| Uno and Nano | A4 | A5 |
| Mega | 20 | 21 |
| ESP32 (default) | 21 | 22 |
| ESP8266 (default) | D2 | D1 |
With an ESP32 you can change them: Wire.begin(SDA, SCL);. And the ESP32 has two I2C buses: if you want to isolate a troublesome device, use Wire1 on two other pins.
3. Pull-up resistors
I2C must have pull-ups on SDA and SCL (usually 4.7k):
- Missing: no communication, or communication that drops out.
- Too many: many modules carry their own resistors. 5 modules each with 4.7k → in parallel ≈ 940 Ω, which is too strong. If you have many modules, remove the resistors from some of them.
The Arduino's internal pull-up (about 20–50k) is far too weak for I2C. It may work on a short wire at low speed, but don't rely on it.
In numbers
The bus, wires and modules have capacitance (for example 200 pF on a breadboard with a few modules), and the pull-up charges it. The signal's rise time is roughly 0.85 × R × C:
- 4.7k → about 0.8 µs. The limit for normal speed (100 kHz) is 1 µs, so that's fine.
- 400 kHz has a limit of 0.3 µs → you need about 1.5–1.8k or less.
- And the lower limit: the chip must be able to pull the line down (about 3 mA). At 5 V that's about 1.5k, and at 3.3 V about 1k. Below that, LOW won't be low enough.
Work it out for your conditions with the I2C pull-up calculator.
4. The address
- Two identical addresses on the same bus → a conflict. Well-known examples: the DS3231 RTC and the MPU6050 are both 0x68.
- The fix: change the address if the module allows it (the AD0 pin on the MPU6050 → 0x69).
- Or use a TCA9548A multiplexer to split the bus into 8 channels.
- 8-bit addresses: some datasheets give 0x78 for an OLED display, while the library wants 0x3C (7-bit). Dividing by 2 solves the problem.
Popular addresses
| Module | Address | Alternative |
|---|---|---|
| SSD1306 OLED display | 0x3C | 0x3D |
| LCD with a PCF8574 module | 0x27 | 0x3F (A version) |
| DS3231 | 0x68 | + EEPROM at 0x57 |
| MPU6050 | 0x68 | 0x69 |
| BME280 / BMP280 | 0x76 | 0x77 |
| BH1750 (light) | 0x23 | 0x5C |
| ADS1115 (ADC) | 0x48 | 0x49–0x4B |
| INA219 (current) | 0x40 | 0x41–0x45 |
If the scanner finds an address not in the table, search for it: you'll usually identify the chip from the address.
5. Voltage
- A 3.3 V module with a 5 V Uno: the pull-ups must be at a voltage the module can handle, or use a bidirectional level shifter.
- Make sure there's a common ground.
6. Wires and speed
- I2C is designed for short distances (on a board, or a few centimetres).
- Long wires (more than 50 cm–1 m) → more capacitance → the signal is distorted.
- Lower the speed:
Wire.setClock(50000);. - Slightly smaller pull-ups (for example 2.2k).
- For genuinely long distances there are special extender chips.
- Don't run SDA and SCL alongside motor or relay wires. The noise corrupts the bits.
7. The bus hangs
Sometimes a device stops in the middle of a message (for example, the Arduino reset while reading), and keeps holding SDA LOW forever. The scanner hangs, and nothing works until you remove the power completely.
The fix: before Wire.begin(), produce 9 pulses on SCL by hand so the device finishes its byte and releases the line:
pinMode(SCL, OUTPUT);
for (int i = 0; i < 9; i++) {
digitalWrite(SCL, LOW); delayMicroseconds(5);
digitalWrite(SCL, HIGH); delayMicroseconds(5);
}
Wire.begin();
And on the Uno, the recent Wire library has Wire.setWireTimeout(3000, true) so the program doesn't hang forever if the bus goes down.
8. Still not working?
- Try the module on its own on the bus.
- Change the wires: a jumper wire broken inside is the most common cause.
- Look at the bus with an oscilloscope or a cheap logic analyzer. If the rising edges are sloped like a shark fin, the pull-up is too large or the capacitance too high.
- Measure the voltage on SDA and SCL while idle with a multimeter: they should read the supply voltage. If they read zero or close to it, something is holding the line or there's no pull-up.
Quick summary
| Symptom | Most likely cause |
|---|---|
| The scanner finds nothing | Wiring, no pull-up, or no power |
| The scanner hangs | The bus is shorted, or a device is holding it LOW |
| The address is found but the library fails | Wrong address in the code, or 8-bit instead of 7 |
| Works for a while then stops | Long wires, noise, or too many pull-ups |
| Two addresses missing | A duplicate address |
FAQ
How many devices can I put on the bus? Until the addresses run out or the total capacitance exceeds about 400 pF. In practice, 5–10 modules on short wires is fine.
Why does the module work on the Uno but not on the ESP32? Usually the pins (21 and 22), or the module needs a 5 V supply and its pull-ups to 5 V are feeding into the ESP32's pins. See level shifting.