Sub topic 1
What I2C Is and When to Use It
I2C, usually pronounced “I-squared-C,” is a serial communication protocol for connecting integrated circuits. It lets one Arduino communicate with several sensors, displays, memory chips, and other devices using the same two signal wires.
This chapter assumes that you know how to structure an Arduino sketch with setup() and loop(), use the Serial Monitor, and work with basic voltage, current, and resistor concepts. You should also recognize binary and hexadecimal numbers.
The basic working model
An I2C system has two roles:
- The controller starts communication and provides the clock. An Arduino is commonly the controller.
- A target responds to the controller. A temperature sensor or display is commonly a target.
The controller and all targets share two bus lines:
- SDA, the serial data line, carries bits.
- SCL, the serial clock line, tells devices when to read or change a bit.
Each target has a 7-bit address. The controller places an address on the bus before sending or receiving data. Only the target with that address responds. This allows several devices to share the same SDA and SCL wires.
The lines use open-drain signaling. A device can pull a line low, but it does not actively drive the line high. External pull-up resistors return the lines to the supply voltage when no device is pulling them low. Without suitable pull-ups, the bus may appear completely inactive or may produce unreliable data.
When I2C is a good choice
I2C works well when a project needs several low-to-moderate-speed peripherals and limited wiring. For example, one Arduino can connect to an environmental sensor, an OLED display, and a real-time clock without using separate chip-select wires for every device.
I2C is especially useful when:
- Devices already provide I2C support.
- Several devices can use unique addresses.
- Short connections on the same circuit board or breadboard are acceptable.
- You want to save Arduino pins compared with interfaces that need more wires.
I2C is less suitable for long cables, high-speed data streams, or devices that need guaranteed high bandwidth. The shared wiring has electrical limits, and every device adds capacitance. Many devices also have fixed addresses, which can create conflicts. SPI is often a better choice for high speed, while UART is often simpler for a direct connection between two devices.
What happens during communication
An I2C exchange is organized into transactions. The controller sends a START condition, an address, and a read or write direction. The addressed target confirms each received byte with an acknowledgment, called an ACK. The controller then transfers data and ends the exchange with a STOP condition.
The Arduino Wire library hides most of these electrical details. Later chapters use it to scan addresses and access device registers. The important model is that every transaction is controller-initiated, address-based, and shared by all connected targets.
> callout note > An I2C address identifies a device on the bus. It is not the same thing as an Arduino pin number, a register address inside the device, or the device's memory location.
Exercise
You need to connect three I2C sensors and an OLED display to one Arduino. Why can they share the same two signal wires?
Show answer
Each device listens for its own I2C address, so the controller can select one target at a time on the shared SDA and SCL bus.