Difficulty using the HC-12 for wireless communication

Hey all! I'm new to the forum, so sorry if I posted this in the incorrect section or formatted it incorrectly.

As part of my GCSE DT, I'm attempting to make a tent alarm. In short, when a zip is undone, a connected Arduino Nano will transmit a signal to a remote device (to be carried on the person), using a HC12, and a buzzer will sound. This is mostly irrelevant, but I feel I should give some sort of context.

The whole triggering part is sorted, and I had little trouble with it. My real difficulty though is with the communication between the transmitter and receiver!

I currently have an Arduino Nano (which will serve as the main controller, etc) and a Pro Mini (for the receiver unit carried on the person), as well as two HC-12 modules (one for each device).

All I need to do is send a signal from the Arduino Nano to the Pro Mini using the HC-12 modules, but I'm really struggling with this.

First of all, is this even possible with my current setup? Secondly, where do I wire the RX and TX pins on the HC-12 to and does this even matter? Finally, how do I go about programming it?

I have seen various videos online, but they're mostly using Arduino Unos and just tell you what pins to wire things to instead of why.

I've been struggling with this for a day or so, so any help is appreciated. Thanks!

Secondly, where do I wire the RX and TX pins on the HC-12 to and does this even matter?

If you want to use the hardware serial to talk to the HC-12 then use pins 0 and 1 because that is where the hardware serial is.

If you're using softwareSerial then use whichever two pins you choose.

Where'd you get the HC-12 modules? Did they come with any documentation (or online)? Were any libraries provided? If so, did you try the example code contain therein?

Astrometrics:
I've been struggling with this for a day or so, so any help is appreciated. Thanks!

The following tutorial among NANO-1, HC-12(1), SM1, NANO-2, HC12-(2), and SM2 could be helpful for you.


Figure-1: Connection diagram between two NANOs using HC-12 Modules

(1) Let us build the setup as per circuit diagram of Fig-1.
(2) Create, compile, and upload the following sketch into the flash of the Sender NANO-1.

#include <SoftwareSerial.h>
SoftwareSerial HC12(10, 11); //SRX, STX Pins of NANO
void setup() 
{
  Serial.begin(9600);             // Hardware Serial port to computer
  HC12.begin(9600);               // Software Serial port to HC12
}

void loop() 
{
  while (HC12.available())          // If HC-12 has data
  {        
    Serial.write(HC12.read());      // Send the data to Serial Monitor
  }
}

void serialEvent()                  //only for Hard Serail Port
{
  while (Serial.available())        //data from Serial Monitor-1
  {      // If Serial monitor has data
    HC12.write(Serial.read());      // Send that data to HC-12 via Software UART Port
  }
}

(3) Upload the program codes of Step-2 into the flash of NANO-2.
(4) Bring in SM1 for NANO-1.
(5) Bring in SM2 for NANO-2.
(6) In SM1, enter Hello! And click the Send button. Check that ‘Hello!’ has appeared on the SM2 of NANO-2.
(7) In the InputBox of SM2, enter Fine! And click the Send button. Check that ‘Fine!’ has appeared on SM1.

Thanks for your help everyone! I tried out the example from @GolamMostafa exactly to spec (although one of my boards is a pro mini) but I've unfortunately had no luck. I have an awful feeling I've damaged one of the HC-12s (I have been testing a lot over the past few days), but not too sure. I've attached both board setups. I attempted this using two separate laptops around 2m apart and the boards weren't externally powered (cables/a power module were on the breadboard in each case but not plugged into the wall). Does anything look wrong with the setup?

Thanks again

gfvalvo:
Where'd you get the HC-12 modules? Did they come with any documentation (or online)? Were any libraries provided? If so, did you try the example code contain therein?

These were just bought from AliExpress and arrived in just a static bag without documentation. I found a manual of sorts online (https://www.elecrow.com/download/HC-12.pdf) but honestly don't understand most of it!

I did find some unofficial libraries online, but they were based on the exact same example code I was using from various websites, such as the instructables and howtomechatronics articles. I will still try them though - I'll respond later if I get any results!

Delta_G:
If you want to use the hardware serial to talk to the HC-12 then use pins 0 and 1 because that is where the hardware serial is.

If you're using softwareSerial then use whichever two pins you choose.

I must admit I'm very new to this so don't know much about this serial stuff. Are there actually any disadvantages to using softwareSerial instead of hardware serial?

Also, just to clarify, am I able to use any digital pin on the arduino?

Thanks

You should start by making sure you can achieve a wired serial connection to communicate between two Arduinos, or between an Arduino and a USB-Serial converter connected to a computer. This requires you to connect the TX pin of one Arduino to the RX pin of the other, and vice versa.

If you are using the hardware TX and RX pins to communicate with a laptop, you will need to use SoftwareSerial to create another set of TX and RX pins (unless your Arduino is a model with multiple UARTs)

Once you have that under your belt, work on replacing the wired connection with the HC-12 link.

lefstin:
You should start by making sure you can achieve a wired serial connection to communicate between two Arduinos, or between an Arduino and a USB-Serial converter connected to a computer. This requires you to connect the TX pin of one Arduino to the RX pin of the other, and vice versa.

If you are using the hardware TX and RX pins to communicate with a laptop, you will need to use SoftwareSerial to create another set of TX and RX pins (unless your Arduino is a model with multiple UARTs)

Once you have that under your belt, work on replacing the wired connection with the HC-12 link.

Thanks for this! I had absolutely no clue how any of this "serial" stuff worked, and your response prompted me to do more focused research. I'll test everything with the HC-12 tomorrow. Fingers crossed!

Forgot to mention, for the wired serial link you'll need to make sure the Arduinos share a common ground!

If you have the wired link working, you should be able to just drop the HC12s in, connecting the Arduino TX to the HC12 RX and vice versa.

Remember that the HC12s default to 9600 baud, and according to the datasheet need up to 200mA when transmitting. The datasheet also suggests using a diode on the input power supply if your power supply is over 4.5V, to prevent the module from overheating when transmitting for an extended time.

Finally, be aware that there are a lot of 'clone' HC12 modules floating out there that have trouble communicating with authentic HC12 modules (and vice versa). But if you got all your modules from a single source, they should be communicating with each other.