Arduino Serial Communication, One Transmiter with Three Receivers - Tann Thona

Telecommunication and Electronic Engineering

Post

Post Top Ad

Tuesday, December 11, 2018

Arduino Serial Communication, One Transmiter with Three Receivers

Transmit Data from One Arduino to Three Arduino

1. Objective

The objective of this project is talk about arduino serial communication. one arduino is a transmitter and three arduino are receiver. Transmitter have three buttons to control LED light at receiver.

2. Requirement

  • Arduino Uno (x4)
  • USB Cable
  • Resistor (220ohm or 330ohm)
  • Button
  • LED
  • Electronic Wire

3. Circuit Connection

Build circuit like figure 1.


Figure 1. Circuit connection arduino serial communication

 4. Coding

Transmitter Code:

// Code by Tann Thona 24 April 2017
int button1 = 13;
int button2 = 12;
int button3 = 11;
char inByte1 = '1';
char inByte2 = '2';
char inByte3 = '3';

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

void loop() {
  // put your main code here, to run repeatedly:
  if(digitalRead(button1)==0)
  {
    Serial.write(inByte1);
    delay(100);
  }
  else if(digitalRead(button2)==0)
  {
    Serial.write(inByte2);
    delay(100);
  }
  if(digitalRead(button3)==0)
  {
    Serial.write(inByte3);
    delay(100);
  }
  else
  {
    Serial.write('0');
    delay(100);
  }

}
 

Receiver 1 Code:
// Code by Tann Thona 24 April 2017
int led1 = 13;
char inByte1 = '1';

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

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

}

Receiver 2 Code:
// Code by Tann Thona 24 April 2017
int led2 = 13;
char inByte2 = '2';

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

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

} 


Receiver 3 Code:
// Code by Tann Thona 24 April 2017
int led3 = 13;
char inByte3 = '3';

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

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

}

5. Result

Now we get result:
  • Push button1 arduino transmitter tansmit number 1, LED's receiver 1 bright.
  • Push button 2 arduino transmitter tansmit number 2, LED's receiver 2 bright.
  • Push button 3 arduino transmitter tansmit number 3, LED's receiver 3 bright.








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