Serial Communication Transmit Data Between Two Arduino - TANN THONA

Department of Telecommunication and Electronic Engineering

Hot

Post Top Ad

Thursday, December 6, 2018

Serial Communication Transmit Data Between Two Arduino

Serial Communication Between Two Arduino

1. Objective

The objective is talk about, serial communication between two Arduino that use serial port Tx and Rx. A Arduino is transmitter and another one is receiver. Transmitter push button send data 1 or 0 to receiver to control LED light.

2. Requirement

  • Arduino Uno x2
  • USB Cable x2
  • Breadboard
  • LED
  • Resistor (220Ohm or 330Ohm)
  • Button
  • Electronic Wire

3. Build Circuit Serial Communication

Build circuit like Fig1.1.

Fig1.1. Serial communication between two Arduino

Transmitter Code:
 
// Code by Tann Thona (24/04/2017)
// Transmitter Coder
int button = 13;
char inByte = '1';

void setup() {
// put your setup code here, to run once:
pinMode(button,INPUT_PULLUP);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
if(digitalRead(button)==0)
{
Serial.write(inByte);
delay(100);
}
else
{
Serial.write('0');
delay(100);
}
}


Receiver Code:

// Code by Tann Thona (24/04/2017)
// Reciever Coder
int led = 13;
char inByte = '1';

void setup() {
// put your setup code here, to run once:
pinMode(led,OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
if(Serial.available())
{
inByte = Serial.read();
if(inByte == '1')
{
digitalWrite(led,1);
}
else
{
digitalWrite(led,0);
}
}

}


4. Result

According to code above, if we push button transmitter send number 1 to receiver and LED is bright. Then if we release button transmitter send number 0 to receiver and LED is dark.








Royal University of Phnom Penh
Faculty of Engineering
Dep. Telecommunication and Electronic Engineering

Group Member:
1. Tann Thona
2. Thach Soveasna
3. Chhoy Noreath
4. Neth Channa
5. Mok Vira

Instructor: Prof. Chann Tola
Date: 24 April 2017

No comments:

Post a Comment

Post Top Ad