Go Down

Topic: Hc12 out of range problem (Read 130 times) previous topic - next topic

psidat

So have this project it works . but when the transmitter is turned off or out of range the last values are kept which is the problem. I would like it to go to a set value if not receiving any data it's probably easy but i am new to this .

thanks in advance   

sterretje

Do you have the sender code and the receiver code swapped? The sender reads from serial, The receiver prints to serial.


Please post your code inline; it's small enough.

Type [code]
Paste your code after that
Type [/code] after that

Do this for each code.
If you understand an example, use it.
If you don't understand an example, don't use it.

Electronics engineer by trade, software engineer by profession. Trying to get back into electronics after 15 years absence.

PaulS

Sending binary data WILL eventually cause you serious issues, when a byte gets lost.

Code: [Select]
  while (Serial.available() == 0) {}
  x = Serial.read();
  delay(10);
  y = Serial.read();
  delay(10);
  z = Serial.read();
  delay(10);
  t = Serial.read();
 // Serial.println(t);
  delay(10);
  a = Serial.read();
  delay(10);
  b = Serial.read();
  delay(10);

The delay(10) is NOT a guarantee that a byte will arrive. This is a piss-poor way of reading serial data. If you need to wait (you do NOT) for 6 bytes, then wait for 6 bytes, not 1.

When you get the 6 bytes, use the 6 bytes. Do NOT unconditionally use any old crap left over in the variables.
The art of getting good answers lies in asking good questions.

Robin2

So have this project it works . but when the transmitter is turned off or out of range the last values are kept which is the problem. I would like it to go to a set value if not receiving any data it's probably easy but i am new to this .
If the Tx sends a message at a regular interval the Rx can note the time when a message arrives and if the gap to the next message is too long it can take action.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up