Exercise 5 Arduino To Arduino Communication
Exercise 5 Arduino To Arduino Communication
Introduction:
The ability for microcontrollers to exchange data effectively is crucial for building complex
interconnected systems. This laboratory activity focuses on exploring and simulating various
communication protocols used for Arduino-to-Arduino communication within the Proteus software
environment.
Wired Protocols:
• Inter-Integrated Circuit (I2C): This master-slave protocol shines when efficiency is key. Imagine
connecting multiple sensors and actuators to your Arduino – I2C allows you to achieve this with
only two wires (SCL for clock and SDA for data) because it facilitates communication between a
single master device (the Arduino) and multiple slave devices (the sensors and actuators). This
reduces wiring complexity and board space, making it perfect for applications with a dense cluster
of peripherals, like building a weather station that collects temperature, humidity, and pressure
data.
• Serial Peripheral Interface (SPI): When high-speed data exchange becomes the priority, SPI
emerges as the champion. This synchronous protocol utilizes four wires (SCK for clock, MOSI for
master-out-slave-in, MISO for master-in-slave-out, and SS for slave select) to establish a dedicated
communication channel. This structured approach allows for faster and more reliable data transfer
compared to UART, making it a great choice for applications involving real-time data acquisition,
like controlling a high-resolution display or capturing audio data from a microphone.
Wireless Protocols:
• Bluetooth: A familiar name in the world of personal devices, offers a user-friendly solution for
short-range data exchange between Arduinos and smartphones or tablets. Its moderate data rates
make it suitable for tasks like control or monitoring in simple projects. Setting up and using
Bluetooth is relatively straightforward, and its widespread device support ensures compatibility
with a vast range of gadgets. An additional perk is the lower power consumption compared to Wi-
Fi, making it a good choice for battery-powered projects. However, Bluetooth's range is typically
limited to under 10 meters, and it's not ideal for applications requiring high data transfer speeds.
Security considerations also come into play when transmitting sensitive data over Bluetooth
connections.
• Zigbee: Zigbee shines brightly in the domain of low-power, low-data-rate wireless sensor
networks. This mesh networking protocol allows for robust and scalable communication between
battery-powered devices, making it ideal for building environmental monitoring systems or
implementing smart home automation with low-maintenance sensors. Zigbee's strength lies in its
ability to establish a self-healing mesh topology, meaning data can be routed through different
nodes if one becomes unavailable, ensuring reliable communication. Security features are built-
in for secure communication, adding another layer of trust. The trade-off for Zigbee's benefits lies
in its very low data rate, limiting its use for applications requiring high bandwidth. Setting up a
mesh network also involves additional configuration compared to simpler protocols. Furthermore,
the availability of Zigbee-enabled devices might be lower compared to Bluetooth.
• WiFi: For scenarios requiring high data transfer speeds, Wi-Fi emerges as the champion.
Leveraging existing Wi-Fi infrastructure, it facilitates streaming data or controlling Arduinos
remotely with multimedia content. Imagine sending live video feeds from your Arduino project
to a computer or controlling a robot with real-time commands – Wi-Fi's high data rates make these
applications possible. The long range of Wi-Fi allows communication over wider areas,
eliminating the limitations of short-range protocols. However, this convenience comes at the cost
of higher power consumption. Wi-Fi-powered devices typically require a constant power source,
limiting their use in battery-powered projects. Additionally, accessing a Wi-Fi network or hotspot
is a prerequisite for using Wi-Fi, and security concerns arise when connecting to public networks.
• LoRaWAN: LoRaWAN takes the crown for communication over vast distances. This low-power,
wide-area networking protocol enables data transmission over kilometers in some cases, making
it perfect for applications like remote sensor data collection in agriculture or building smart city
infrastructure. Imagine collecting temperature data from sensors scattered across a vast farm or
monitoring environmental conditions in remote locations – LoRaWAN's exceptional range makes
these scenarios achievable. The key to its long range lies in its extremely low data rate. While
this limits the type of data that can be transmitted, the trade-off is exceptional range and battery
efficiency. LoRaWAN is ideal for situations where long-distance communication reigns supreme,
even if the data itself is minimal. However, operating a LoRaWAN network requires additional
infrastructure like gateways and servers, and the availability of LoRaWAN-enabled devices might
be lower compared to some other protocols.
Objectives:
Equipment Required:
Sample Arduino code for each communication protocol (provided or developed during the activity)
Procedures:
Transmitter:
void setup() {
Serial.begin(9600);
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
}
void loop() {
b1=digitalRead(button1);
b2=digitalRead(button2);
if((b1==LOW)&&(b2==HIGH))
{
Serial.print('a');
delay(10);
}
if((b1==HIGH)&&(b2==LOW))
{
Serial.print('b');
delay(10);
}
if((b1==LOW)&&(b2==LOW))
{
Serial.print('c');
delay(10);
}
if((b1==HIGH)&&(b2==HIGH))
{
Serial.print('d');
delay(10);
}
}
Receiver:
void setup() {
Serial.begin(9600);
pinMode(bulb1,OUTPUT);
pinMode(bulb2,OUTPUT);
}
void loop() {
data=Serial.read();
if(data=='a')
{
digitalWrite(bulb1,HIGH);
digitalWrite(bulb2,LOW);
delay(10);
}
if(data=='b')
{
digitalWrite(bulb1,LOW);
digitalWrite(bulb2,HIGH);
delay(10);
}
if(data=='c')
{
digitalWrite(bulb1,HIGH);
digitalWrite(bulb2,HIGH);
delay(10);
}
if(data=='d')
{
digitalWrite(bulb1,LOW);
digitalWrite(bulb2,LOW);
delay(10);
}
}
Simulation Environment:
Conclusion:
Questions to answer:
1. When designing a simple robot controlled remotely with basic commands (start, stop, turn) via
Bluetooth or Zigbee, which factors (range, power consumption, ease of use) are most critical for
selecting the optimal wireless protocol?
2. In a network of temperature sensors deployed across a large farm for data collection, battery life
and reliable data transmission are crucial. How do the characteristics of LoRaWAN and Zigbee
protocols influence their suitability for this application?
3. When using Bluetooth communication between two Arduinos that are paired and within range but
not transmitting data, what troubleshooting steps can be taken to identify the cause of the
communication failure?
4. What potential factors, such as network node density, power limitations, or wireless interference,
could contribute to data loss in a Zigbee sensor network? How can these factors be addressed to
improve network stability?
5. While Wi-Fi offers high data rates suitable for live video streaming from an Arduino project, its
power consumption can limit battery life. What alternative approaches, such as reducing video
resolution, exploring LoRaWAN (despite its lower data rate), or optimizing Arduino code, could
be considered to balance video quality, data transmission needs, and battery life?
References: