Communication in Arduino
Arduino supports several methods for communication between:
Arduino and a computer
Arduino and other microcontrollers
Arduino and sensors, modules, or devices
Here are the major communication methods in Arduino:
1. Serial Communication (UART)
Most common method using Serial library.
Uses TX (transmit) and RX (receive) pins.
Baud rate defines speed (e.g., 9600 bps). (In Arduino
communication, baud rate is the number of bits
transmitted per second over a serial port)
Used to communicate with PCs, Bluetooth modules (HC-
05), GPS, etc.
Example:
Serial.begin(9600); // Start serial communication
Serial.println("Hello"); // Send data
2. I2C Communication (Inter-Integrated Circuit)
Master-slave protocol, uses only 2 wires:
SDA (data) and SCL (clock)
Good for communicating with multiple devices (e.g.,
sensors, LCDs).
Use 'Wire.h' library.
Example:
#include <Wire.h>
Wire.begin(); // Join I2C bus as master
Wire.beginTransmission(8); // Start transmission to device
#8
Wire.write("Hello");
Wire.endTransmission(); // Stop transmission
3. SPI Communication (Serial Peripheral Interface)
Faster than I2C, used for high-speed communication.
Uses 4 wires: MISO, MOSI, SCK, and SS.
Common with SD cards, RF modules (nRF24L01).
Use 'SPI.h' library.
Example:
#include <SPI.h>
SPI.begin();
SPI.transfer(0x01); // Send data
4. USB Communication
When connected to a computer via USB, Arduino uses
serial over USB.
Can send data to/from Serial Monitor or interface with
software like Processing or Python.
5. Wireless Communication
Includes methods like:
Bluetooth (HC-05, HC-06)
Wi-Fi (ESP8266, ESP32)
LoRa, Zigbee (XBee)
RF 433 MHz modules
Each requires a specific library and setup.
6. CAN Communication (Controller Area Network)
Used in automotive and industrial systems.
Requires CAN modules (e.g., MCP2515).