0% found this document useful (0 votes)
13 views6 pages

DA-3 (Embedded Systems)

Uploaded by

aadityaa2606
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views6 pages

DA-3 (Embedded Systems)

Uploaded by

aadityaa2606
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Embedded Systems

DA - 3

Name: Aadityaa.N Reg.No: 21BCE1964

Objective:

To simulate a system where an LED connected to one Arduino (Slave) is


controlled using I2C communication by another Arduino (Master). The
Master receives user input via Serial Monitor and sends commands to
the Slave to turn the LED ON or OFF.

Components needed:

1. Two Arduino Uno boards (Master and Slave)


2. 1 LED
3. 1 Resistor (220 ohms)
4. Connecting wires

Step-by-Step Instructions:

1. Set Up the Workspace in Tinkercad


1. Log in to your TinkerCad account.
2. Navigate to Circuits and click on Create New Circuit.
3. Drag and drop two Arduino Uno boards from the components
menu onto the workspace.
4. Label one as Master and the other as Slave for clarity.
5. Connect the LED and Resistor to the Slave Arduino
a. Drag an LED from the components menu:
i. Connect the anode (longer leg) of the LED to pin 13 of
the Slave Arduino.
ii. Connect the cathode (shorter leg) to one end of a
220-ohm resistor.
iii. Connect the other end of the resistor to the GND pin on
the Slave Arduino.

6. Connect the Master and Slave Arduinos

Using the I2C Protocol:

1. Connect the SDA pin (A4) of the Master Arduino to the SDA pin
(A4) of the Slave Arduino.
2. Connect the SCL pin (A5) of the Master Arduino to the SCL pin (A5)
of the Slave Arduino.

Shared Ground:

1. Connect the GND pin of the Master Arduino to the GND pin of the
Slave Arduino.
a. This ensures a common reference for both devices.

4. Upload the Code


Master Arduino Code:
C/C++

#include <Wire.h>

void setup() {
Wire.begin(); // Join I2C bus as master
Serial.begin(9600); // Start Serial communication
Serial.println("Enter 0 to turn OFF LED or 1 to
turn ON LED:");
}

void loop() {

if (Serial.available()) {
char command = Serial.read(); // Read user input
if (command == '0' || command == '1') {
Wire.beginTransmission(8); // Address of the
slave
Wire.write(command); // Send the command
Wire.endTransmission();
}
}
}

1. Click on the Master Arduino.


2. Open the Code Editor and select Text mode.
3. Paste the following code into the editor:

Slave Code:

C/C++

#include <Wire.h>

#define LED_PIN 13

void setup() {
pinMode(LED_PIN, OUTPUT); // Set LED pin as
output
Wire.begin(8); // Join I2C bus with address 8
Wire.onReceive(receiveEvent); // Register event
handler
}

void loop() {
// Nothing to do here; everything is handled in
the receiveEvent

}
void receiveEvent(int bytes) {
char command = Wire.read(); // Read the command
from master
if (command == '0') {
digitalWrite(LED_PIN, LOW); // Turn LED OFF
} else if (command == '1') {
digitalWrite(LED_PIN, HIGH); // Turn LED ON
}
}

5. Simulate and Test

1. Click Start Simulation in Tinkercad.


2. Open the Serial Monitor for the Master Arduino:
a. Click the Master Arduino.
b. Select the Serial Monitor icon from the menu on the right.

Test the Setup:

1. In the Serial Monitor:


a. Enter 0 and press Enter.
b. The LED on the Slave Arduino should turn OFF.
2. Enter 1 and press Enter.
a. The LED on the Slave Arduino should turn ON.
Conclusion

You have successfully implemented and tested an I2C-based LED control


system in Tinkercad. The Master Arduino reads user input from the
Serial Monitor and communicates with the Slave Arduino to control the
LED’s state. This project demonstrates basic I2C communication
between Arduinos.

You might also like