Trouble with wireless communication using HC-12 modules

Hey.
I am trying to use two HC-12 modules to achieve wireless communication between two arduinos. The arduinos are connected like this:

VCC -> 5V
GND -> GND
RXD -> PIN 8
TXD -> PIN 7
SET -> NC

This is my code:

#include <SoftwareSerial.h>

SoftwareSerial HC12(7, 8); // HC-12 TX Pin, HC-12 RX Pin

void setup() {
  Serial.begin(9600);             // Serial port to computer
  HC12.begin(9600);               // Serial port to HC12
  
}

void loop() {
  while (HC12.available()) {        // If HC-12 has data
    Serial.write(HC12.read());      // Send the data to Serial monitor
  }
  while (Serial.available()) {      // If Serial monitor has data
    int data = Serial.read();
    Serial.print("Sending: ");
    Serial.println(data);
    HC12.write(data);      // Send that data to HC-12
  }
}

When running the sketch I am able to send messages one way by typing data in one serial monitor and it showing up in the serial monitor of the other arduino.

When I try to communicate the other way, this shows up in the serial monitor:
(Sent message is "Hey")

Sending: 72
Sending: 101
Sending: 121
Sending: 10
H⸮)

(Pictures should be attached to the post)

It looks like the arduino sending the data is also receiving it, and that the other arduino is not receiving any data.
What could be the problem?


I have also tried to set the SET pin on the HC-12 to GDN and sending an AT command, I get nothing in return.
I have seen through an SDR and an antenna that data is being sent over the air.

HC-12 datasheet: https://statics3.seeedstudio.com/assets/file/bazaar/product/HC-12_english_datasheets.pdf[](https://statics3.seeedstudio.com/assets/file/bazaar/product/HC-12_english_datasheets.pdf)

One-way.png

Other-way.png

One-way.png

Other-way.png

int data = Serial.read();you are receiving a single byte into a 2 byte variable, of which you send both bytes. Change the type for data to 'uint8_t'

Thank you! That fixed the problem :smiley:

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