←Back to Subject
Notes
Notes
Study material and explanations
Diagrams
Diagrams
Visualize concepts easily
Mnemonics
Mnemonics
Tricks to remember faster
One Night Prep
One Night Prep
Short and focused revision
Revision
Revision
Quick summary and key points
Important Questions
Important Questions
Practice most relevant questions
Notes

Sensor Data Communication Protocols: UART, I2C & SPI Explained

Study material and explanations for Unit 4

Sensor Data Communication Protocols: UART, I2C & SPI

Why Do We Need Hardware Communication Protocols?

When connecting sensors (like temperature probes, digital compasses, or small OLED screens) to microcontrollers (like Arduino Uno, ESP32, or Raspberry Pi), how do they exchange data?

If we used a separate wire for every single bit, we would need dozens of messy wires on the circuit board!

Instead, microcontrollers use Serial Communication Protocols to send bits of 1s and 0s one after another over just 2 to 4 thin wires. The three most popular hardware protocols in IoT are:

  1. UART (Universal Asynchronous Receiver-Transmitter)
  2. I2C (Inter-Integrated Circuit)
  3. SPI (Serial Peripheral Interface)

1. UART (Universal Asynchronous Receiver-Transmitter)

UART is a hardware circuit used for asynchronous serial communication between two devices using only two signal wires.

UART Point-to-Point Wiring
Microcontroller (Device A)
TX (Transmit Pin) ───────▶
RX (Receive Pin) ◀───────
⇄
Sensor / Module (Device B)
◀─────── RX (Receive Pin)
───────▶ TX (Transmit Pin)

Key Characteristics of UART:

  • Asynchronous (No Clock Wire): There is no shared clock signal wire. Both devices must be set to the exact same transmission speed beforehand, called the Baud Rate (e.g. 9600 bps or 115200 bps).
  • Two Signal Wires:
    • TX (Transmit): Sends data out.
    • RX (Receive): Reads incoming data.
    • (Note: A common GND wire is also connected).
    • The TX pin of Device A connects directly to the RX pin of Device B, and RX of Device A connects to TX of Device B (cross connection).
  • Packet Format: A UART message frame has:
    [ 1 Start Bit (LOW) ] + [ 8 Data Bits ] + [ Optional Parity Bit ] + [ 1 Stop Bit (HIGH) ]
  • Limitation: Strictly point-to-point (connects only 1 device to 1 device). You cannot connect 5 sensors to the same UART pair.
  • Common IoT Uses: GPS modules (NEO-6M), Bluetooth modules (HC-05), GSM modules (SIM800L), and Arduino Serial Monitor on your computer.

2. I2C (Inter-Integrated Circuit)

Developed by Philips, I2C (pronounced “Eye-Squared-C”) is a synchronous, multi-device serial bus.

It is amazing because it can connect dozens of sensors and screens to a microcontroller using only two physical wires!

I2C Multi-Device Bus Architecture
SDA (Serial Data Line)
Two-way data wire carried through pull-up resistors to power (3.3V or 5V).
SCL (Serial Clock Line)
Clock pulse wire driven by the master microcontroller to keep timing synchronized.
       +5V / +3.3V
           │   │
          [R] [R]  (Pull-Up Resistors: 4.7 kΩ)
           │   │
SDA ───────┴───┼───────────┬───────────────┬───────────────┐
SCL ───────────┴───────┬───┼───────────┬───┼───────────┬───┼
                       │   │           │   │           │   │
                 ┌─────┴───┴───┐ ┌─────┴───┴───┐ ┌─────┴───┴───┐
                 │ Master MCU  │ │ Temp Sensor │ │ OLED Display│
                 │ (ESP32)     │ │ (Addr: 0x48)│ │ (Addr: 0x3C)│
                 └─────────────┘ └─────────────┘ └─────────────┘

How I2C Works:

  1. Device Addresses: Every sensor has its own unique 7-bit hardware address (supporting up to 127 devices on the exact same 2 wires!).
  2. Master Control: The microcontroller sends a START signal, calls out the sensor’s address (e.g. 0x3C), waits for an ACK (acknowledgment bit), and begins data transfer.
  3. Pull-Up Resistors: Because I2C pins are open-drain, two 4.7 kΩ pull-up resistors are required to pull the wires HIGH when idle.
  4. Common IoT Uses: 0.96-inch OLED displays, BMP280 pressure sensors, and MPU6050 gyroscope/accelerometer modules.

3. SPI (Serial Peripheral Interface)

Invented by Motorola, SPI is a synchronous, four-wire, full-duplex protocol built for high-speed data transfer over short distances.

Instead of software addresses, SPI uses a dedicated wire to select which device to talk to.

SPI 4-Wire Master-Slave Configuration
MOSI (Master Out Slave In)
Sends data from the Microcontroller to the Sensor / Display.
MISO (Master In Slave Out)
Sends data from the Sensor back to the Microcontroller.
SCK (Serial Clock)
Clock pulse line driven by the Master to time bit transfers.
SS / CS (Slave Select / Chip Select)
Dedicated pin pulled LOW by Master to wake up that specific device.

Advantages of SPI:

  • Full-Duplex: The master can send data and receive data at the exact same clock pulse.
  • Blazing Fast: Speeds reach 10 Mbps to 50+ Mbps (much faster than I2C).
  • Simple Hardware: No pull-up resistors or software addressing needed.
  • Drawback: Each extra sensor needs its own extra CS pin on the microcontroller.
  • Common IoT Uses: MicroSD card readers, high-resolution color TFT screens, RFID RC522 readers, and NRF24L01 radio modules.

4. Summary Comparison: UART vs. I2C vs. SPI

Feature UART I2C SPI
Number of Wires 2 wires (TX, RX) 2 wires (SDA, SCL) 4 wires (MOSI, MISO, SCK, CS)
Clock Line Asynchronous (No clock; uses Baud Rate) Synchronous (SCL clock line) Synchronous (SCK clock line)
Communication Mode Full-Duplex Half-Duplex Full-Duplex
Connection Type Point-to-Point (1 to 1 only) Multi-Master, Multi-Slave Single Master, Multi-Slave
How Devices are Selected No addressing 7-bit software address per chip Dedicated CS (Chip Select) wire per chip
Data Speed Up to 115.2 kbps (up to 1 Mbps) 100 kbps to 400 kbps (High speed: 3.4 Mbps) 10 Mbps to 50+ Mbps (Very Fast!)
Best Used For GPS modules, Bluetooth, Serial Monitor Sensors, small OLED screens, RTC clocks SD cards, color graphical displays, RFID

💡 DAVV Exam Preparation Tips

5-Mark Question: “Explain the working of I2C protocol. Why are pull-up resistors needed?”

  • Two Wires: SDA (Serial Data) and SCL (Serial Clock).
  • Addressing: Uses 7-bit addresses to connect up to 127 devices on the same 2 wires.
  • Pull-up Resistors: I2C lines are open-drain, meaning devices can only pull the line LOW. Pull-up resistors (4.7 kΩ) are required to pull the line HIGH when no device is transmitting.

5-Mark Question: “Compare synchronous and asynchronous serial communication with examples.”

  • Synchronous: Shares a separate clock signal wire (e.g. SPI, I2C) to keep sender and receiver synchronized at high speeds.
  • Asynchronous: Has no clock wire (e.g. UART). Instead, both ends must agree in advance on a fixed Baud Rate (like 9600 bps) and use Start and Stop bits.

10-Mark Question: “Compare UART, I2C, and SPI protocols with respect to wiring, speed, multi-device capabilities, and practical IoT applications.”

  • Draw the 3 circuit diagrams: UART (TX/RX cross), I2C (SDA/SCL with pull-ups), SPI (4 wires with CS line).
  • Explain the working principle of each protocol.
  • Provide the complete 7-row comparison table.
  • Give practical examples for each: UART for GPS/Bluetooth, I2C for temperature sensors and OLED screens, SPI for SD card modules and RFID readers.