Hi guys, I am trying to do communication between two Arduino Mega by using SoftwareSerial but It doesn't work. Is there anyone to know that, what is the reason ?
Here is my transmitter code :
#include <SoftwareSerial.h>SoftwareSerial active(50, 51);
SoftwareSerial passive(52, 53);
SoftwareSerial standby(10, 11);// Transmitter
int Button1 = 13;
int Button2 = 12;
int Button3 = 7;void setup() {
// put your setup code here, to run once:Serial.begin(9600);
active.begin(9600);
passive.begin(9600);
standby.begin(9600);pinMode(Button1, INPUT_PULLUP); // for read button
pinMode(Button2, INPUT_PULLUP); // for read button
pinMode(Button3, INPUT_PULLUP); // for read button}
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead(Button1) == 0)
{
active.write('1');
Serial.println("button 1 pressed");
}
if (digitalRead(Button2) == 0)
{
passive.write('2');
Serial.println("button 2 pressed");
}
if (digitalRead(Button3) == 0)
{
standby.write('3');
Serial.println("button 3 pressed");
}
delay(50); // waitting message send
}
And here is my receiver code :
#include <SoftwareSerial.h>
SoftwareSerial active(50, 51);
SoftwareSerial passive(52, 53);
SoftwareSerial standby(10, 11);//Reciever
int LED1 = 13;
int LED2 = 12;
int LED3 = 7;
char message1;
char message2;
char message3;void setup() {
// put your setup code here, to run once:
Serial.begin(9600);active.begin(9600);
passive.begin(9600);
standby.begin(9600);pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);}
void loop() {
// put your main code here, to run repeatedly:
if (active.available())
{
message1 = active.read();
if (message1 == '1')
{
digitalWrite(LED1, HIGH);
Serial.println("button 1 pressed");
}
}
if (passive.available())
{
message2 = passive.read();
if (message2 == '2')
{
digitalWrite(LED2, HIGH);
Serial.println("button 2 pressed");
}} if (standby.available()) { message3 = standby.read(); if (message3 == '3') { digitalWrite(LED3, HIGH); Serial.println("button 3 pressed"); } }
delay(20);
digitalWrite(LED1,LOW);
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
}