Issues with HC-12 and a Mega

I am trying to make a remote control car, but I am have issues trying to get my HC-12s to communicate. The main board is a Mega, and the remote is currently a Uno, but will soon-ish be a Nano. I currently have them both connected to separate laptops, with the latest IDE install on both. Originally They both had the same code:

#include <SoftwareSerial.h>

SoftwareSerial HC12(10, 11);

void setup() {
  Serial.begin(9600);
  HC12.begin(9600);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  digitalWrite(12, HIGH);
}

void loop() {
  while (HC12.available()) {
    Serial.write(HC12.read());
    digitalWrite(13, HIGH);
    delay(10);
    digitalWrite(13, LOW);
  }

  while (Serial.available()) {
    HC12.write(Serial.read());
  }
}

But after doing some research, I found out that I don’t need to have software serial on the Mega, so I changed the code to:

byte rx_byte = 0;

void setup() {
  Serial.begin(9600);
  Serial3.begin(9600);
  pinMode(12, OUTPUT);
  digitalWrite(12, HIGH);
}

void loop() {
  if (Serial.available()) {
    rx_byte = Serial.read();
    Serial3.write(rx_byte);
  }
  if (Serial3.available()) {
    rx_byte = Serial3.read();
    Serial.write(rx_byte);
  }
}

On the Uno, I have pin setup:

Uno HC-12
GND GND
Pin 12 Vcc
Pin 11 Rx
Pin 10 Tx

On the Mega, I have pin setup:

Mega HC-12
GND GND
Pin 12 Vcc
Pin 14 Rx
Pin 15 Tx

The issue is when I try to send with the Mega, either the Uno doesn’t show what was sent, or the Mega doesn’t send properly. I tried to change the port, with the ‘AT+’ command, and I didn’t see the ‘OK+’ message, so I think the issue is with the Mega/that chip. Any help would be greatly appreciated.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.