The library is the cornerstone of I2C (Inter-Integrated Circuit) communication in the Arduino ecosystem. If you want to connect your Arduino board to an OLED display, a gyro sensor, a real-time clock (RTC), or a digital compass, you will need to use this library.

If you connect an I2C device and it isn't working, the problem is often an incorrect I2C address. The code below uses Wire.h to scan the entire I2C bus and report the address of any connected device to the Serial Monitor.

BME280 (Temperature/Pressure), MPU6050 (Accelerometer), TCS34725 (Color Sensor). RTC: DS3231 or DS1307 Real-time Clocks.

A simple typo can break everything. Ensure your sketch includes the Wire library with the correct capitalization at the top: #include <Wire.h> . It's case-sensitive and uses angle brackets, not quotes.

class MySensor private: uint8_t _address; public: MySensor(uint8_t addr); bool begin(); float readTemperature(); ;

The Wire library manages I2C communication. This protocol uses only two wires to connect multiple devices to your microcontroller: The line for exchanging data. SCL (Serial Clock): The line for synchronising data timing.

Reinstall the Arduino IDE to ensure all core libraries are present.

Double-check that SDA/SCL pins are connected correctly.

If you want to ensure the library is working correctly, you can open one of its built-in example sketches: Open the . Click on File in the top menu bar. Hover over Examples . Scroll down to the Wire section.