HC-12 & Nano - hardware or software problem?

I am starting a program to manage HC-12s. Read the current configuration, or reconfigure as necessary.

It compiles, it tells me it is talking to the HC-12, and nothing comes back. It could be my code, my setup, or my HC-12s. If anyone has a spare HC-12 and a spare minute could you tell me if this works?

//based on code from: Tom Heylen

#include <SoftwareSerial.h>

#define rxPin 2
#define txPin 3
#define stPin 7

SoftwareSerial HC12(rxPin, txPin); 
long baud = 9600;

void setup() 
  pinMode(rxPin,  INPUT);
  pinMode(txPin, OUTPUT);
  pinMode(stPin, OUTPUT);
  Serial.println(); Serial.println();
  while (!Serial) // wait for serial port to connect. Needed for native USB port only 
  digitalWrite(stPin, HIGH);
  Serial.println("HC-12 Test & configure");
  Serial.println("HC-12 started");  
  if (HC12.isListening()) 
   Serial.println("HC-12 is Listening ");
   if (!HC12.available())
   Serial.println("HC-12 is not responding");

  //test HC-12
  digitalWrite(stPin, LOW);
  Serial.println("Sending AT+RX");
  HC12.print("AT+RX");                // Send different commands to see which method works
  Serial.println("command sent");
  Serial.println("setup end"); Serial.println();
  digitalWrite(stPin, HIGH);

void loop() 
  if (HC12.available())
  while (HC12.available())         // If HC-12 has data 
    Serial.write(HC12.read());     // Send the data to Serial monitor
   digitalWrite(stPin, LOW); 
  while (Serial.available())       // If Serial monitor has data
   HC12.write(Serial.read());      // Send that data to HC-12
   digitalWrite(stPin, LOW);  

The data sheets I see indicate that the set pin needs to be GND to be in AT mode. Are you doing that?

Yes. no effect.


Try different line terminations. I don't know if this module takes a special set, but usually all command lines must start with "AT" and end with a carriage return character. This is for when you are sending an AT command from within the code, and not entering the command in the serial monitor. The line endings from the serial monitor should be echoed in the software serial communication to the module.


Make sure that you are coming out of the set mode when you are not sending AT commands.

When you send an AT command from within the code, you will need code to read the response and sent it back to the monitor. Something like this

while (HC12.available() )

In general, I think you should be using the .print() instead of .write().

The HC12 needs the AT commands to be sent with no gaps between the characters, otherwise the command parser times out.

A command like this

will work, and the HC12 will respond with OK usually.

Typing the same chars in the serial monitor wont work.

4 HC-12s, 2 nanos, tried everything above, always !HC12.available

finally, one works

HC-12 Test & configure
HC-12 started
HC-12 is Listening 
HC-12 is not responding
Sending AT+RX
command sent
setup end


so I get to make 2 links with one radio...

amended program in original post

edit: it worked once. I think the HC-12s burned up. they are only getting 3.45 V, and they cooked