Hwello, I'm trying to connect 2 Arduino to communicate with each other via serial communication using the tx and Rx pins. It is transmitting the data but not receiving the data. I'm using chatgpt to code. The code I'm using is:
sender:
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
Serial.println("hello"); // Send "hello" over serial
delay(1000); // Delay for stability
}
receiver:
void setup() {
Serial.begin(9600); // Initialize serial communication
}
void loop() {
if (Serial.available() > 0) {
String receivedData = Serial.readStringUntil('\n');
if (receivedData.equals("hello")) {
Serial.println("goodbye"); // Respond with "goodbye"
}
}
}
whats wrong?? thx
Hi @UwUsername69. I see from your picture that you are using Leonardo clones. On the Leonardo, the hardware serial instance for pins 0 and 1 is Serial1:
You are using Serial in your sketch. On the Leonardo, Serial is only used for communication with the computer over the USB cable, not via pins 0 and 1. So you will need to adjust your code accordingly.