I changed the transmitter program to transmit in fixed timeperiods (set with interval1=500ms) instead of relying on a change in value for val5:
// http://forum.arduino.cc/index.php?topic=499210.msg3407044#msg3407044
// http://forum.arduino.cc/index.php?topic=396450.0
// HC12 Communication between Arduinos
/*
This program serves to send one integer (or byte) only from two different HC12
transmitters at one sensor each (A and B)to one HC12 receiver at the central
controller Arduino. The receiving HC12 has to know from which transmitter A or B
the value comes.
The data are sent with start- and endmarkers
v2: two integers used, one for the sensor values (integer1FromPC & integer2FromPC) and
one char for the sensor identifier (A or B). At the transmitter the sensors A or B are
identiefied by reading two digital inputs connected to a dipswitch with
2 switches (max: 4 different sensor/transmitters).
v3: fixed retransilission timing
// TRANSMITTER PART
*/
#include <SoftwareSerial.h>
const byte HC12RxdPin = 4; // Recieve Pin on HC12
const byte HC12TxdPin = 5; // Transmit Pin on HC12
SoftwareSerial HC12(HC12TxdPin, HC12RxdPin); // Create Software Serial Port
int analogValue5, val5;
int HC12power = 8;
const int interval1 = 500; // HC12 power-on time in milliseconds
// const int interval2 = 500; // HC12 retransmission time delay
const int interval3 = 200; // HC12 fixed retransmission timings
unsigned long previousMillis1; // timer1
// unsigned long previousMillis2; // timer2
unsigned long previousMillis3 = 0; // timer3
void setup()
{
Serial.begin(115200); // Open serial port to computer
HC12.begin(115200); // Open serial port to HC12
pinMode(HC12power, OUTPUT);
}
void loop()
{
// read analog pin 5
analogValue5 = analogRead(5);
// remap values from the analogValue5 variable to 0 / 255
val5 = map(analogValue5, 0, 1023, 0, 255);
if (millis() - previousMillis3 >= interval3) {
previousMillis3 = millis();
if (digitalRead(HC12power) == LOW)
{
digitalWrite(HC12power, HIGH);
delay(100);
}
HC12.print('<');
HC12.print(val5);
HC12.print(',');
HC12.print(val5);
HC12.print(",B>");
previousMillis3 = millis();
if (millis() - previousMillis1 >= interval1) {
digitalWrite(HC12power, LOW);
previousMillis1 = millis();
}
}
//start timer to switch off HC12
}
Serial window output:
1d3,143,B
143,1d3,B
143,143,B
143\143,B
143,143,⸮
143,143,B
143,1d3,B
143,143,B
143,a43,B
143,143,B~<1d3,143,B
143,14c,B
143,143,B
143,a43,B
143,143,⸮
14c,143,B
143,1d3,B
143,143,B
143\143,B
143,143,⸮
14c,143,B
143,143\B
143,143,B
143,a43,B
143,143,B~<14c,143,B
143,14c,B
143,143,B
143,a43,B
143,143,B~<14c,143,B
143,143\B
a43,143,B
143,1d3,B
143,143,B~<143,143,B
143,143\B
1d3,143,B
143,a43,B
143,143,B
143\143,B
143,143,⸮
1d3,143,B
143,1d3,B
143,143,B
143\143,B
143,143,C
1d3,143,B
143,14c,B
143,143,B
143\143,B
143,143\B
14c,143,B
143,1d3,B
143,143,B
143\143,B
143,143,⸮
1d3,143,B
143,14c,B
143,143,B
143,a43,B
143,143,B~<14c,143,B
143,14c,B
143,143,B
143,a43,B
143,143,B~<1d3,143,B
143,14c,B
a43,143,B
143,1d3,B
143,143,B~<14c,143,B
143,143\B
a43,143,B
143,a43,B
143,143,B~<143,143,B
143,143.B
1d3,143,B
143,1d3,B
143,143,B
143\143,B
143,143,⸮
a43,143,B
143,1d3,B
143,143,B
143\143,B
143,143\B
14c,143,B
143,1d3,B
143,143,B?<143\143,B
143,143,⸮
1d3,143,B
143,14c,B
143,143,B
143\143,B
143,143,⸮
14c,143,B
143,14c,B
143,143,B