HC-12 communication using 2 Leonardo

Hey everyone,

I’m working on a project that requires simple communication between two arduino Leonardo using two hc-12 modules.

I’m having some troubles getting the transceivers to work and communicate with each others. I’ve been through so many tutorials and read so many topics and I still can’t make them to communicate. I started by following two methods that I found online:

I tried at first these methods with the exact same pins they used, after that, I changed Rx and Tx to the pins 9 and 10, and Set is on pin 11. But after reading a topic on this forum:

I’ve tried to change the pins to 0 and 1 for Rx and Tx, and worked with Serial1 instead of Serial, still no results.

After that, I’ve tried to check with an oscilloscope if I really send anything, I’ve seen that the arduino sends a signal to the Tx pin of my hc-12, but this signal is not received by the second hc-12. I don’t know how to check if this signal is really being transmitted, because I only check if the Tx pin on my hc-12 module receives something, but I guess that if the RF module receives the signal, it’s going to transmit it.

I keep thinking that maybe one of the hc-12 is not working properly, but I really doubt it as I just received them. Anyway, I ordered two more that will arrive in the next week, so we’ll see.

Here are the code that I’m using (I also used the code in the links that I provided, wth no results), I did try and change the pins to 0 and 1 while using Serial1 and It’s not working either.

#include <SoftwareSerial.h>

SoftwareSerial hc12(10, 9);

void setup() {
  pinMode(11, OUTPUT);
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(11, LOW); 
  Serial.begin(9600); 
  while (!Serial){ }
  hc12.begin(9600);
  hc12.print(F("AT+C001\r\n")); // set to channel 1
  delay(100);
  //digitalWrite(11,HIGH);// enter transparent mode
}

void loop() {
  
  if (Serial.available()) hc12.write(Serial.read());
  if (hc12.available())
    {
      Serial.write(hc12.read());
      digitalWrite(LED_BUILTIN,HIGH);
    }
}

I appreciate your help as I have no idea why it’s not working for me.

You have Leonardos, why the hell do you use that crippled SoftwareSerial when you have an unused hardware serial interface?

When you say to use the hardware serial interface on my Leonardos, you're talking about the pins 0 and 1 right? I forgot to say that I'm quite new to all this and I've never used an arduino before.

So if I understood you correctly, I should remove the SoftwareSerial library and instead of defining a softwareserial variable "hc12", I should directly use Serial1 as it's going to send and receive data to my hc12 modules? after connecting the Rx and Tx of my hc12 to Tx and Rx of the Leonardo of course.

Thanks for the reply

So if I understood you correctly, I should remove the SoftwareSerial library and instead of defining a softwareserial variable "hc12", I should directly use Serial1 as it's going to send and receive data to my hc12 modules? after connecting the Rx and Tx of my hc12 to Tx and Rx of the Leonardo of course.

Instead of using an instance of SoftwareSerial, use Serial1 on the Leonardo. Serial1 is connected to the TX and RX pins.