Jump to content

Send A String From Arduino To Arduino

Judd

So I have one goal, to simply send a string with letters and numbers from 1 Arduino to another. Here is the receiver code I have:

String message = "";

void setup() {
Serial.begin(9600);
Serial.println("Program Started");
}

void loop() { 

  while(Serial.available()){
    message = Serial.readString();
     Serial.println(message);
     delay(100);
     message = "";
  }
}

The Sender code is this:

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.write("Hello123");
  delay(1000);
}

So I have the arduinos on separate computers to easily upload code and view the Serial messages. also, after I upload both of the Arduino's code to the board I connect the GND pins on the arduinos from Sender to Receiver, then I connect the TX pin of the sender to the RX pin of the Receiver. However, there is no message being displayed from the Receiver. the sender is every second saying Hello123 in the terminal but the receiver is not receiving anything. Have I coded something or set up something incorrectly? Any help would be appreciated. Thanks

Link to comment
Share on other sites

Link to post
Share on other sites

Good you are getting into arduino. It's generally recommended to always connect both RX and TX. 

TX --- RX

RX --- TX

 

Also make sure the 2 arduino's are connected via ground.

GND --- GND

 

I don't see an issue with your code, I usually don't use strings but I don't see why it wouldn't work.

 

Here is a link to a guide on how to do serial communication between 2 arduino's - https://iotguider.in/arduino/serial-communication-between-two-arduino-boards/. This guide isn't perfect as it uses a set length for both sending and receiving but it's good enough to test your setup.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×