HC-12 433MHz module problems programming

Hello everybody,

I'm kindly asking for help with the HC-12 RF modules http://www.seeedstudio.com/wiki/images/b/b0/HC-12_User_Manual.pdf.
The thing is I don't get the modules to receive or transmit any data and i might need some help on that. What i managed to do is making a program that adjusts the settings of the modules in the "command mode". I hope some one is willing to help me with making the modules communicate with each other.

thanks....

Hi there,

The same problem with Arduino and hc-12 transceiving data. I need to transmit an "ALARM" or whatever string, and identify it by the other Arduino (the idea is to connect an autonomous alarm system in one building with a GSM alarm system in the other building wirelessly. In my case only one alarm activation is allowed), but can't get it working.

So long the Tx code is:

#include <SoftwareSerial.h>
SoftwareSerial hc12(9,11); // RX, TX
int PCNPin = 3; // dry contact of the autonomous alarm system
boolean alarmOn = false;

void setup() {
 pinMode(7,OUTPUT); //  setPin on hc12
 pinMode(PCNPin,INPUT_PULLUP); // pin connected to PCN3 (output) of the alarm system
 hc12.begin(9600); // Start the software serial port
 
 // setup of the hc12 module
 digitalWrite(7,LOW); // enter AT command mode
 hc12.print(F("AT+DEFAULT\r\n")); // 9600, CH1, FU3, (F) to bypass flash memory
 delay(100);
 digitalWrite(7,HIGH); // enter transparent mode

}

void loop() {
 if(digitalRead(PCNPin) == LOW && alarmOn == false) {
 for(int i = 0; i < 5; i++)
 {
 hc12.println("ALARM");
 delay(1000);
 }
 alarmOn = true; // After five tries (to eliminate any interference) Arduino can go to sleep
 hc12.end();
 }
}

And the draft Rx code goes:

#include <SoftwareSerial.h>
SoftwareSerial hc12(9,11); // RX, TX
int relayPin = 3;
boolean alarmOn = false;

void setup() {
 pinMode(7,OUTPUT); //  setPin on hc12
 pinMode(relayPin, OUTPUT);
 Serial.begin(9600); // Start the hardware serial port
 hc12.begin(9600); // Start the software serial port
 
 // setup of the hc12 module
 digitalWrite(7,LOW); // enter AT command mode
 hc12.print(F("AT+DEFAULT\r\n")); // 9600, CH1, FU3, (F) to bypass flash memory
 delay(100);
 digitalWrite(7,HIGH); // enter transparent mode
 
}

void loop() {
 if(hc12.available() > 0 && alarmOn == false) { //TO BE MODIFIED!!!

 Serial.write(hc12.read());
 
 if(Serial.find("ALARM")) {
 
 digitalWrite(relayPin, HIGH); // The control line of the GSM alarm system to be cut only once
 delay(5000);
 digitalWrite(relayPin, LOW);
 alarmOn = true;
 }
}
}

In fact, this is merely my draft. I'm a complete beginner and don't know how to correctly receive a String with HC-12 (hope, the Tx is correct) and identify the trigger word "ALARM" in it. All I have tried so far doesn't work. Any advice would be appreciated!

ValeryOD:
Hi there, ...................
Any advice would be appreciated!

You have hijacked 'backfromhome's thread.

OldSteve:
You have hijacked 'backfromhome's thread.

I surrender) But the topic is actually the same. HC-12 is set up, but we don't know hot to get it to work to transmit or receive data (in my case - a string).

ValeryOD:
I surrender) But the topic is actually the same. HC-12 is set up, but we don't know hot to get it to work to transmit or receive data (in my case - a string).

If your problem is the same, sit back and watch, see what the responses are. Posting your code in someone else's thread and asking for help with it isn't good form, and takes the focus away from the OP.

The person who should have posted his/her code didn't do so.

@backfromhome, post your code, showing what you tried, and someone might be able to help. (And ValeryOD might benefit as well. :smiley: )

This topic is so old now, I think like one week after it worked it seemed like i just had the modules too close with 100mW less than 30 cm it works like a charm and I had more than 200m range with one module inside a grounded metal container with just 1 window.

But as for @ValeryOD what I would suggest is ditching the string to make it more efficient just send a single character for instance:

if((hc12.available()>0)&&(alarmOn == false)){
int inByte = hc12.read();
if( inByte = 'A'){
// what ever you want it to do
}
}

This so there is less time spend on reading characters or making strings, Next to that i found out working with the hc-12 it's less error sensitive

backfromhome:
This topic is so old now, I think like one week after it worked it seemed like i just had the modules too close with 100mW less than 30 cm it works like a charm and I had more than 200m range with one module inside a grounded metal container with just 1 window.

But as for @ValeryOD what I would suggest is ditching the string to make it more efficient just send a single character for instance:

if((hc12.available()>0)&&(alarmOn == false)){

int inByte = hc12.read();
if( inByte = 'A'){
// what ever you want it to do
}
}




This so there is less time spend on reading characters or making strings, Next to that i found out working with the hc-12 it's less error sensitive

Oh, another case of someone dredging up an old thread. When ValeryOD replied, I assumed that your post was recent as well. I never think to double-check the date.
Anyway, I'm glad you sorted out your problem, even if it was a little over a year ago.

@ValeryOD, in future it's better to start your own thread, rather than dig up ancient ones and reply to them. It's far too confusing.