Problem with HC-12 Wireless Transceiver

Hello Guys,

I have used this forum a ton and learned so much from it, but this is my first post so please forgive if I do it wrong! Here's my problem:

I have 2 hc-12 modules, one connected to a UNO and another connected to a mega. Both are running identical sketches to simply send messages back and forth and print to serial monitor.

When I send a message from the mega the uno outputs it to serial monitor perfectly. When the message is sent from uno to mega... nothing happens.

I have spent hours trying different things, but always the same.

Any ideas?

Also, I have pin 2 connected to TX on HC-12 and pin 3 connected to RX on HC-12

Here is the code:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); //RX, TX

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

void loop() {
  
  
  if(Serial.available() > 0){//Read from serial monitor and send over HC-12
    String input = Serial.readString();
    mySerial.println(input);    
  }
 
  if(mySerial.available() > 1){//Read from HC-12 and send to serial monitor
    String input = mySerial.readString();
    Serial.println(input);    
  }
  delay(20);
}

I found the answer to my question:

Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

cHANGED rx TO PIN 10 AND WORKS LIKE A CHARM!!

1 Like