HC-12 TRANSMITTER TO HC-12 RECEIVER, CONVERT ANALOG VALUES BACK TO INTEGER

// ==== Storing the incoming data into a String variable
while (HC12.available())  // If HC-12 has data
  {           
    Serial.println(ss.c_str());
    Serial.println();
    delay(DT);
    delay(2000);
   }

That code does NOT store incoming data in a String. Your program should have NO Strings. AT ALL.

If there ever is data available, that while loop will never end, since you never actually read the data.

The (transmitter) arduino pro mini serial monitor is showing up but the values remain static.

Well, the only Serial.print() statement that you have in the code is in that while statement's body, where it prints the String it sent once every 2+ seconds.

You never send a second String, so static is reasonable.

Thanks for the clarification....

i got rid of the while loop and turned it into an if statement

i also have the println declared before the if (Serial.available()) statement.

The values on the transmitter serial monitor are now dynamic and I am able to use the code on the arduino pro mini.

For the software serial pins I will change them again
once I get things working like I had before using just pins 0,1.

On the receiver end I know my code is cycling because I get my println statments of
azimuth motor stops
elevation motor stops.

However, I'm getting 0s for all my values. At first i was getting single digits but now I get nothing but 0s.

TRANSMITTER CODE:

// SPECIAL THANKS TO GEO BRUCE ON INSTRUCTABLES.COM

#include <SoftwareSerial.h>
SoftwareSerial HC12(0,1); //RX,TX   

void setup()
{
  Serial.begin(9600); //SERIAL PORT TO PC
  HC12.begin(9600); //SERIAL PORT TO HC12
}
void loop()
{
  String sendTR; //STRING TO STORE ANALOG VALUE
  String sendBR;
  String sendTL;
  String sendBL;
  String sendDT;
  String sendTE;
  String ss;
  
  char buff[6]; //BUFFER FOR 6 CHARACTERS

  //LIGHT SENSORS CONNNECTED TO ANALOG PIN ON ARDUINO BOARD
  int TR = analogRead(A1); //TOP RIGHT SENSOR
  int BR = analogRead(A0); //BOTTOM RIGHT SENSOR
  int TL = analogRead(A2); //TOP LEFT SENSOR
  int BL = analogRead(A3); //BOTTOM LEFT SENSOR
  int DT = analogRead(A6) * 4; //CONTROL DELAY TIME BETWEEN READINGS OF SENSORS
  int TE = analogRead(A7) / 4; //SET TOLERANCE VALUE FOR DIFFERENCE BETWEEN SENSORS
  
  sendTR+=itoa(TR,buff,10); //TAKES AN INTEGER AND CONVERTS IT INTO AN ASCII/NUMBER STRING (CONVERT INTEGER TO STRING (NON-STANDARD FUNCTION))
  sendBR+=itoa(BR,buff,10); //char *  itoa ( int value, char * str, int base );
  sendTL+=itoa(TL,buff,10);
  sendBL+=itoa(BL,buff,10);
  sendDT+=itoa(DT,buff,10);
  sendTE+=itoa(TE,buff,10);
  
  ss+=sendTR; //ss = ss + sentTR
  ss+="&"; //ss = ss + &
  ss+=sendBR;
  ss+="&";
  ss+=sendTL;
  ss+="&";
  ss+=sendBL;
  ss+="&";
  ss+=sendDT;
  ss+="&";
  ss+=sendTE;
  ss+="&";

  Serial.println(ss.c_str());
  Serial.println();
  delay(DT);
  
if (Serial.available())  // IF SERIAL MONITOR HAS DATA
  {
  HC12.write(ss.c_str()); //SEND DATA TO HC-12
  delay(DT);
  }
}

RECEIVER CODE:

// SPECIAL THANKS TO GEO BRUCE ON INSTRUCTABLES.COM

#include <SoftwareSerial.h>
SoftwareSerial HC12(0,1); //RX, TX

byte incomingByte;
String readBuffer = "";

// AZIMUTH AND ELEVATION PWM PINS ON EACH H-BRIDGE MUST BE CONNECTED TO FOUR PWM (PULSE WIDTH MODULATION) PINS ON ARDUINO.
// FOR UNO/MICRO/PRO MINI THEY ARE: 3,5,6,9,10,11.

int AREN = 2; int ARPWM = 3; int ALEN = 4; int ALPWM = 5; // MOTOR AZIMUTH ADJUSTMENT
int EREN = 7; int ERPWM = 6; int ELEN = 8; int ELPWM = 9; // MOTOR ELEVATION ADJUSTMENT

void setup()
{
  Serial.begin(9600); //SERIAL PORT TO PC
  HC12.begin(9600); //SERIAL PORT TO HC12
  pinMode(AREN, OUTPUT); pinMode(ARPWM, OUTPUT); pinMode(ALEN, OUTPUT); pinMode(ALPWM, OUTPUT);  //SET ALL MOTOR CONTROL PINS TO OUTPUTS
  pinMode(EREN, OUTPUT); pinMode(ERPWM, OUTPUT); pinMode(ELEN, OUTPUT); pinMode(ELPWM, OUTPUT);
}
void loop()
{
// ==== STORING THE INCOMING DATA INTO A STRING VARIABLE
readBuffer="";
if (HC12.available()) //IF HC-12 HAS DATA
  {          
    incomingByte = HC12.read();          //STORE EACH INCOMING BYTE FROM HC-12
    readBuffer += char(incomingByte);    //ADD EACH BYTE TO ReadBuffer STRING VARIABLE
  }

//SYNTAX: string.indexOf(val) - LOCATES A CHARACTER OR STRING WITHIN ANOTHER STRING. BY DEFAULT, SEARCHES FROM THE BEGINNING OF THE STRING, BUT CAN ALSO START FROM A GIVEN INDEX, ALLOWING FOR THE LOCATING OF ALL INSTANCES OF THE CHARACTER OR STRING.

int firstAnd= readBuffer.indexOf("&");    
String firstTR = readBuffer.substring(0,firstAnd);
int TR= firstTR.toInt();

int secondAnd= readBuffer.indexOf("&", firstAnd+1);
String firstBR = readBuffer.substring(firstAnd+1,secondAnd);
int BR= firstBR.toInt();

int thirdAnd= readBuffer.indexOf("&", secondAnd+1);
String firstTL = readBuffer.substring(secondAnd+1,thirdAnd);
int TL= firstTL.toInt();
 
int fourthAnd= readBuffer.indexOf("&",thirdAnd+1);
String firstBL = readBuffer.substring(thirdAnd+1,fourthAnd);
int BL = firstBL.toInt();

int fifthAnd= readBuffer.indexOf("&",fourthAnd+1);
String firstDT = readBuffer.substring(fourthAnd+1,fifthAnd);
int DT= firstDT.toInt();

int sixthAnd= readBuffer.indexOf("&", fifthAnd+1);
String firstTE = readBuffer.substring(fifthAnd+1,sixthAnd);
int TE= firstTE.toInt();

Serial.println(TR);
Serial.println(BR);
Serial.println(TL);
Serial.println(BL);
Serial.println(DT);
Serial.println(TE);
Serial.println("========================");
delay(4000);

int count = 0; //START MILLISECOND COUNT OF LIGHT SENSOR READINGS
count++; //INCREMENTAL COUNT INCREASE, CONTINUES TO SHOW LIGHT SENSOR RESULTS

int avt = (TR + TL) / 2; // AVERAGE VALUE TOP
int avd = (BL + BR) / 2; // AVERAGE VALUE DOWN
int avl = (TL + BL) / 2; // AVERAGE VALUE LEFT
int avr = (TR + BR) / 2; // AVERAGE VALUE RIGHT

int dv = avt - avd; // AVERAGE DIFFERENCE OF TOP AND BOTTOM LIGHT SENSORS
int dh = avl - avr;// AVERAGE DIFFERENCE OF LEFT AND RIGHT LIGHT SENSORS

  if (-1 * TE > dh || dh > TE) // CHECK IF THE DIFFERENCE IN LEFT AND RIGHT LIGHT SENSORS IS WITHIN TOLERANCE RANGE
  {
    if (avl > avr) // IF AVERAGE LIGHT SENSOR VALUES ON LEFT SIDE ARE GREATER THAN RIGHT SIDE, AZIMUTH MOTOR ROTATES CLOCKWISE
    {
      digitalWrite(AREN, HIGH); analogWrite(ARPWM, 255); // SET SPEED OUT OF POSSIBLE RANGE 0~255

      digitalWrite(ALEN, HIGH);  digitalWrite (ALPWM, LOW);
      Serial.println("AZIMUTH MOTOR MOVES CLOCKWISE");
      Serial.println("   ");
    }
    else // IF AVERAGE LIGHT SENSOR VALUES ON RIGHT SIDE ARE GREATER THAN ON LEFT SIDE, AZIMUTH MOTOR ROTATES COUNTERCLOCKWISE
    {
      digitalWrite(ALEN, HIGH); analogWrite(ALPWM, 255);
      digitalWrite(AREN, HIGH); digitalWrite(ARPWM, LOW);
      Serial.println("AZIMUTH MOTOR MOVES COUNTERCLOCKWISE");
      Serial.println("   ");
    }
  }
  else if (-1 * TE < dh || dh < TE) //IF DIFFERENCE IS SMALLER THAN TOLERANCE, STOP AZIMUTH MOTOR
  {
    digitalWrite(AREN, LOW);  digitalWrite(ALEN, LOW);
    Serial.println("AZIMUTH MOTOR STOPS");
    Serial.println("   ");
  }

  if (-1 * TE > dv || dv > TE) //CHECK IF THE DIFFERENCE IN TOP/BOTTOM LIGHT SENSORS IS GREATER THAN TOLERANCE
  {
    if (avt > avd) //IF AVERAGE LIGHT SENSOR VALUES ON TOP SIDE ARE GREATER THAN ON BOTTOM SIDE THEN ELEVATION MOTOR ROTATES CLOCKWISE
    {
      digitalWrite(EREN, HIGH); analogWrite(ERPWM, 255);
      digitalWrite(ELEN, HIGH); digitalWrite(ELPWM, LOW);
      Serial.println("ELEVATION MOTOR MOVES CLOCKWISE");
      Serial.println("   ");
    }
    else //IF AVERAGE LIGHT SENSOR VALUES ON BOTTOM SIDE ARE GREATER THAN ON TOP SIDE THEN ELEVATION MOTOR ROTATES COUNTERCLOCKWISE
    {
      digitalWrite(ELEN, HIGH); analogWrite(ELPWM, 255);
      digitalWrite(EREN, HIGH); digitalWrite(ERPWM, LOW);
      Serial.println("ELEVATION MOTOR MOVES COUNTERCLOCKWISE");
      Serial.println("   ");
    }
  }
  else if (-1 * TE < dv || dv < TE) //IF DIFFERENCE IS SMALLER THAN TOLERANCE, STOP ELEVATION MOTOR
  {
    digitalWrite(EREN, LOW);  digitalWrite(ELEN, LOW);
    Serial.println("ELEVATION MOTOR STOPS");
    Serial.println("   ");
  }
  delay(DT);
}

i also have the println declared before the if (Serial.available()) statement.

I'm sure that that collection of words meant something to you when you typed them. They mean nothing to me.

For the software serial pins I will change them again
once I get things working like I had before using just pins 0,1.

When I'm done doing something that can't be done...

Serial.println(ss.c_str());
Serial.println();
delay(DT);

if (Serial.available())  // IF SERIAL MONITOR HAS DATA
{
HC12.write(ss.c_str()); //SEND DATA TO HC-12
delay(DT);
}
}

I moved these before the if statement:

Serial.println(ss.c_str());
Serial.println();
delay(DT);

{
HC12.write(ss.c_str()); //SEND DATA TO HC-12
delay(DT);
// Serial.println(ss.c_str());
// Serial.println();
// delay(DT);
}

So the output on the transmitting serial monitor shows up as this:

I've been taking a look at the c_str function at:
http://www.cplusplus.com/reference/string/string/c_str/

I'm wondering is the reason why I'm not receiving code properly on the receiver side is because I don't have a proper Null character i.e. '0'?

knightridar:
So the output on the transmitting serial monitor shows up as this:

In Reply #12 I told you that those images are unreadable.

I also gave you a link to some code that would probably have solved your problem.

...R

@Robin2 I did check out the serial input basics guide a while back.
I read over it again a few times.
Thanks!!!
Examples 4 and 5 seem like the closest to what I'm trying to achieve.
I was confused with parts of the code that didn't have any comments.

FYI... for the images with text try holding CTRL and press + to zoom in.
It works for me. If not I'll start pasting in my outputs anyways.

//************************************//

I found this example online and it accomplishes almost half of what I'm trying to do:

http://www.botsrule.com/pattonrobotics/Multi%20Analog%20Read%20RF%20transmit%20and%20recieve%20demo.html

//******************************************************************//

The code below was easy for me to understand and implement/modify.
The problem I'm getting is my last two variables are not showing any results on the receiver side serial monitor.

My goal is to convert this received data back into an integer and then use it for the rest of the program

A = 338
B = 409
C = 309
D = 351
E =
F =

A = 337
B = 419
C = 313
D = 358
E =
F =

A = 356
B = 450
C = 331
D = 380
E =
F =

TRANSMITTER CODE:

#include <SoftwareSerial.h>

int HC12RxdPin = 12;                  // Receive Pin on HC12
int HC12TxdPin = 11;                  // Transmit Pin on HC12

SoftwareSerial HC12(HC12TxdPin,HC12RxdPin); // Create Software Serial Port

void setup() {
// initialize serial communications at 9600 bits per second for each port:
  Serial.begin(9600);
  HC12.begin(9600); //SERIAL PORT TO HC12
}
//********************************************************
//    Send Hardware Serial data
//********************************************************
void sendHWSerial() {

  //LIGHT SENSORS CONNNECTED TO ANALOG PIN ON ARDUINO BOARD
  int TR = analogRead(A1); //TOP RIGHT SENSOR
  int BR = analogRead(A0); //BOTTOM RIGHT SENSOR
  int TL = analogRead(A2); //TOP LEFT SENSOR
  int BL = analogRead(A3); //BOTTOM LEFT SENSOR
  int DT = analogRead(A6) * 4; //CONTROL DELAY TIME BETWEEN READINGS OF SENSORS
  int TE = analogRead(A7) / 4; //SET TOLERANCE VALUE FOR DIFFERENCE BETWEEN SENSORS

  Serial.println('A' + String(TR)); // print out the value you read:
  Serial.println('B' + String(BR)); // print out the value you read:
  Serial.println('C' + String(TL)); // print out the value you read:
  Serial.println('D' + String(BL)); // print out the value you read:
  Serial.println('E' + String(DT)); // print out the value you read:
  Serial.println('F' + String(TE)); // print out the value you read:
  Serial.println(" ");
  
  HC12.print(String(TR) + 'A'); // Send data to Hardware Serial
  HC12.print(String(BR) + 'B'); // Send data to Hardware Serial
  HC12.print(String(TL) + 'C'); // Send data to Hardware Serial
  HC12.print(String(BL) + 'D'); // Send data to Hardware Serial
  HC12.print(String(DT) + 'E'); // Send data to Hardware Serial
  HC12.print(String(TE) + 'F'); // Send data to Hardware Serial
  HC12.print(" "); // Send data to Hardware Serial
  delay(4000);
}
//********************************************************
//      Main Loop (loops forever)
//********************************************************
void loop() {
{                   // If Arduino's computer rx buffer has data
   sendHWSerial();            // Send that data to serial
   delay(10);        // delay in between reads for stability
}
}

RECEIVER CODE:

#include <SoftwareSerial.h>

const byte HC12RxdPin = 11;                  // Receive Pin on HC12
const byte HC12TxdPin = 12;                  // Transmit Pin on HC12

SoftwareSerial HC12(HC12TxdPin,HC12RxdPin); // Create Software Serial Port

void setup() {
// initialize serial communications at 9600 bits per second for each port:
  Serial.begin(9600);
  HC12.begin(9600); //SERIAL PORT TO HC12
}
//********************************************************
//    Receive Hardware Serial data
//********************************************************
void getHWSerial() {
  while (HC12.available() == 0);  // wait until there is data in the buffer
  if (HC12.available() > 0) { //if there is data in the serial buffer.....
    Serial.read();
    Serial.println("A = " + String(HC12.readStringUntil('A')));    // Print Collected data until a 'A' is detected
    Serial.println("B = " + String(HC12.readStringUntil('B')));    
    Serial.println("C = " + String(HC12.readStringUntil('C')));
    Serial.println("D = " + String(HC12.readStringUntil('D')));
    Serial.println("E = " + String(HC12.readStringUntil('E')));
    Serial.println("F = " + String(HC12.readStringUntil('F')));    
    Serial.println(" ");    //
  }
  
}

//********************************************************
//      Main Loop (loops forever)
//********************************************************
void loop() {
  getHWSerial();
  delay(10);        // delay in between reads for stability
}

if there is part of my Serial Input Basics code that you don't understand then I will try to help if you tell me what it is.

The code you posted in Reply #25 uses the String class which I advised against in Reply #10

...R

Why are you printing one thing to the hardware serial port and another to the software serial port?

Why the f**k can't you use two print() calls instead of wasting memory on converting an int to a String that the print() method has to then unwrap? The print() method is perfectly capable of converting an int to a string, without your "help".

Why does sendHWSerial() send data to the software serial port?

Geez no need for crude language.
I'm not a native programmer by profession or trade.
I'm trying to learn on my own as a hobby.

All I can say it at this point...

  1. I see what you mean I can get rid of the strings on the println portion of the code.
    I just copied code from the site mentioned in my previous post and adapted it to my application.

Only reason I'm printing on the hardware serial port so I can view what I am outputting from
the transmitting Arduino on the serial monitor.
If I print via software serial I can't view anything on my serial monitor.
Correct???

  1. sendHWSerial() ---> Maybe I just need to rename this, I'm sending data via the software serial port and HC-12 transmitter based on your earlier recommendations that hardware serial ports 0,1
    should/can't be used.

  2. My main objective is to convert my transmitted analog values
    (vary from 0 to 1023 for 4 light dependent resistors,
    and for potentiometers it's 0-255, 0 to 4096)) and assign them
    to their respective variables on the HC-12 receiver side.

My understanding is that I'm sending my analog values as a string of characters???
(Based on a post I read on the forum if data is sent via bytes my analog sensor values can only be sent between the ranges of 0 to 255.)

I need some sort of delimiter to split the values so that they can be assigned to the proper respective variables on the receiver end of my code.

I am writing up some code using the parse function (i.e example 4 modified <TR, 1023>) in the serial basics guide provided by Robin2 to try to mimic the same functionality as the code below.

My friends add-ons to my code were working at one point on the receiver end but all I get now are 0s printing on the receiver serial monitor.
He is using the "&" character as a delimiter if my understanding is correct.

int firstAnd= readBuffer.indexOf("&");    
String firstTR = readBuffer.substring(0,firstAnd);
int TR= firstTR.toInt();

int secondAnd= readBuffer.indexOf("&", firstAnd+1);
String firstBR = readBuffer.substring(firstAnd+1,secondAnd);
int BR= firstBR.toInt();

int thirdAnd= readBuffer.indexOf("&", secondAnd+1);
String firstTL = readBuffer.substring(secondAnd+1,thirdAnd);
int TL= firstTL.toInt();
 
int fourthAnd= readBuffer.indexOf("&",thirdAnd+1);
String firstBL = readBuffer.substring(thirdAnd+1,fourthAnd);
int BL = firstBL.toInt();

int fifthAnd= readBuffer.indexOf("&",fourthAnd+1);
String firstDT = readBuffer.substring(fourthAnd+1,fifthAnd);
int DT= firstDT.toInt();

int sixthAnd= readBuffer.indexOf("&", fifthAnd+1);
String firstTE = readBuffer.substring(fifthAnd+1,sixthAnd);
int TE= firstTE.toInt();

Only reason I'm printing on the hardware serial port so I can view what I am outputting from
the transmitting Arduino on the serial monitor.
If I print via software serial I can't view anything on my serial monitor.
Correct???

Yes, that is correct. But, the whole idea of printing the serial port is so that you can see what is also being sent to the bluetooth device, so you can parse it on the other end.

It makes no sense to print one thing to the hardware serial port and something else to the softare serial port. You haven't learned a thing about what you need to parse.

knightridar:
I am writing up some code using the parse function (i.e example 4 modified <TR, 1023>) in the serial basics guide provided by Robin2 to try to mimic the same functionality as the code below.

My friends add-ons to my code were working at one point on the receiver end but all I get now are 0s printing on the receiver serial monitor.
He is using the "&" character as a delimiter if my understanding is correct.

If this was my project I would use the code in my Serial Input Basics and I believe it would be working inside an hour.

Start by just receiving the data and printing it to the Serial Monitor.

When that works extend it to parse the data.

...R

@Robin2 Thanks. I read through the guide more thoroughly.

The code is working for data transmission from one Arduino Uno to another Arduino Uno.

When I hook up the HC-12 to my Arduino Pro Mini for transmission I am able to see that the data is properly being printed on the serial monitor on the transmitter side.

However, on the receiver end the Arduino Uno doesn't get data. The serial monitor shows a blank screen.

My guess is it's not a program issue at this point now but probably
an insufficient power provided to the HC-12 issue. Not 100% sure.
The Arduino Pro Mini is the 3.3V, 8 Mhz version.

I got the completed code for anyone that may need to refer to it or use it written below.

Here is what data looks like on the transmission end:

<380,148,224,260,1196,79>

Here is what successful reception of data looks like (between two Arduino Uno's):

<732,180,264,290,1272,82>
AZIMUTH MOTOR MOVES COUNTERCLOCKWISE
   
ELEVATION MOTOR MOVES CLOCKWISE

TRANSMITTER CODE:

#include <SoftwareSerial.h>

const byte HC12RxdPin = 11;                   // RECEIVE PIN ON HC12
const byte HC12TxdPin = 12;                   // TRANSMIT PIN ON HC12

SoftwareSerial HC12(HC12TxdPin, HC12RxdPin); // CREATE SOFTWARE SERIAL PORT

void setup() {
  HC12.begin(9600); //SERIAL PORT TO HC12
}

void loop() {
  //LIGHT SENSORS CONNNECTED TO ANALOG PIN ON ARDUINO BOARD
  int TR = analogRead(A1); //TOP RIGHT SENSOR
  int BR = analogRead(A0); //BOTTOM RIGHT SENSOR
  int TL = analogRead(A2); //TOP LEFT SENSOR
  int BL = analogRead(A3); //BOTTOM LEFT SENSOR
  int DT = analogRead(A6) * 4; //CONTROL DELAY TIME BETWEEN READINGS OF SENSORS
  int TE = analogRead(A7) / 4; //SET TOLERANCE VALUE FOR DIFFERENCE BETWEEN SENSORS

  HC12.print("<"); //SENDS ANALOG VALUES IN THIS FORMAT: I.E. <380,148,224,260,1196,79>
  HC12.print(TR);
  HC12.print(",");
  HC12.print(BR);
  HC12.print(",");
  HC12.print(TL);
  HC12.print(",");
  HC12.print(BL);
  HC12.print(",");
  HC12.print(DT);
  HC12.print(",");
  HC12.print(TE);
  HC12.print(">");
  HC12.println();

  delay(DT);
}

RECEIVER CODE:

#include <SoftwareSerial.h>

const byte HC12RxdPin = 11;                   // RECEIVE PIN ON HC12
const byte HC12TxdPin = 12;                   // TRANSMIT PIN ON HC12

SoftwareSerial HC12(HC12TxdPin, HC12RxdPin);  // CREATE SOFTWARE SERIAL PORT

// AZIMUTH AND ELEVATION PWM PINS ON EACH H-BRIDGE MUST BE CONNECTED TO FOUR PWM (PULSE WIDTH MODULATION) PINS ON ARDUINO.
// FOR UNO/MICRO/PRO MINI THEY ARE: 3,5,6,9,10,11.

int AREN = 2; int ARPWM = 3; int ALEN = 4; int ALPWM = 5; // MOTOR AZIMUTH ADJUSTMENT
int EREN = 7; int ERPWM = 6; int ELEN = 8; int ELPWM = 9; // MOTOR ELEVATION ADJUSTMENT

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];        // TEMPORARY ARRAY FOR USE WHEN PARSING

// VARIABLES TO HOLD THE PARSED DATA
int TR = 0; //TOP RIGHT SENSOR
int BR = 0; //BOTTOM RIGHT SENSOR
int TL = 0; //TOP LEFT SENSOR
int BL = 0; //BOTTOM LEFT SENSOR
int DT = 0; //CONTROL DELAY TIME BETWEEN READINGS OF SENSORS
int TE = 0; //SET TOLERANCE VALUE FOR DIFFERENCE BETWEEN SENSORS

boolean newData = false;

//====================

void setup() {
  Serial.begin(9600); //SERIAL PORT TO PC
  HC12.begin(9600); //SERIAL PORT TO HC12
  pinMode(AREN, OUTPUT); pinMode(ARPWM, OUTPUT); pinMode(ALEN, OUTPUT); pinMode(ALPWM, OUTPUT);  //SET ALL MOTOR CONTROL PINS TO OUTPUTS
  pinMode(EREN, OUTPUT); pinMode(ERPWM, OUTPUT); pinMode(ELEN, OUTPUT); pinMode(ELPWM, OUTPUT);
}

void loop() {
  recvWithStartEndMarkers();
  if (newData == true) {
    strcpy(tempChars, receivedChars);
    // THIS TEMPORARY COPY IS NECESSARY TO PROTECT THE ORIGINAL DATA
    // BECAUSE STRTOK() USED IN PARSEDATA() REPLACES THE COMMAS WITH \0
    parseData();
    showParsedData();
    newData = false;
  }

  int avt = (TR + TL) / 2; // AVERAGE VALUE TOP
  int avd = (BL + BR) / 2; // AVERAGE VALUE DOWN
  int avl = (TL + BL) / 2; // AVERAGE VALUE LEFT
  int avr = (TR + BR) / 2; // AVERAGE VALUE RIGHT

  int dv = avt - avd; // AVERAGE DIFFERENCE OF TOP AND BOTTOM LIGHT SENSORS
  int dh = avl - avr;// AVERAGE DIFFERENCE OF LEFT AND RIGHT LIGHT SENSORS

  if (-1 * TE > dh || dh > TE) // CHECK IF THE DIFFERENCE IN LEFT AND RIGHT LIGHT SENSORS IS WITHIN TOLERANCE RANGE
  {
    if (avl > avr) // IF AVERAGE LIGHT SENSOR VALUES ON LEFT SIDE ARE GREATER THAN RIGHT SIDE, AZIMUTH MOTOR ROTATES CLOCKWISE
    {
      digitalWrite(AREN, HIGH); analogWrite(ARPWM, 255); // SET SPEED OUT OF POSSIBLE RANGE 0~255

      digitalWrite(ALEN, HIGH);  digitalWrite (ALPWM, LOW);
      Serial.println("AZIMUTH MOTOR MOVES CLOCKWISE");
      Serial.println("   ");
    }
    else // IF AVERAGE LIGHT SENSOR VALUES ON RIGHT SIDE ARE GREATER THAN ON LEFT SIDE, AZIMUTH MOTOR ROTATES COUNTERCLOCKWISE
    {
      digitalWrite(ALEN, HIGH); analogWrite(ALPWM, 255);
      digitalWrite(AREN, HIGH); digitalWrite(ARPWM, LOW);
      Serial.println("AZIMUTH MOTOR MOVES COUNTERCLOCKWISE");
      Serial.println("   ");
    }
  }
  else if (-1 * TE < dh || dh < TE) //IF DIFFERENCE IS SMALLER THAN TOLERANCE, STOP AZIMUTH MOTOR
  {
    digitalWrite(AREN, LOW);  digitalWrite(ALEN, LOW);
    Serial.println("AZIMUTH MOTOR STOPS");
    Serial.println("   ");
  }

  if (-1 * TE > dv || dv > TE) //CHECK IF THE DIFFERENCE IN TOP/BOTTOM LIGHT SENSORS IS GREATER THAN TOLERANCE
  {
    if (avt > avd) //IF AVERAGE LIGHT SENSOR VALUES ON TOP SIDE ARE GREATER THAN ON BOTTOM SIDE THEN ELEVATION MOTOR ROTATES CLOCKWISE
    {
      digitalWrite(EREN, HIGH); analogWrite(ERPWM, 255);
      digitalWrite(ELEN, HIGH); digitalWrite(ELPWM, LOW);
      Serial.println("ELEVATION MOTOR MOVES CLOCKWISE");
      Serial.println("   ");
    }
    else //IF AVERAGE LIGHT SENSOR VALUES ON BOTTOM SIDE ARE GREATER THAN ON TOP SIDE THEN ELEVATION MOTOR ROTATES COUNTERCLOCKWISE
    {
      digitalWrite(ELEN, HIGH); analogWrite(ELPWM, 255);
      digitalWrite(EREN, HIGH); digitalWrite(ERPWM, LOW);
      Serial.println("ELEVATION MOTOR MOVES COUNTERCLOCKWISE");
      Serial.println("   ");
    }
  }
  else if (-1 * TE < dv || dv < TE) //IF DIFFERENCE IS SMALLER THAN TOLERANCE, STOP ELEVATION MOTOR
  {
    digitalWrite(EREN, LOW);  digitalWrite(ELEN, LOW);
    Serial.println("ELEVATION MOTOR STOPS");
    Serial.println("   ");
  }
  delay(DT);
}

void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (HC12.available() > 0 && newData == false) {
    rc = HC12.read();

    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else {
        receivedChars[ndx] = '\0'; // TERMINATE THE STRING
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
}

//===================

void parseData() {   // SPLIT THE DATA INTO ITS PARTS

  char * strtokIndx;  // THIS IS USED BY STRTOK() AS AN INDEX

  strtokIndx = strtok(tempChars, ",");     // GET THE FIRST PART - THE STRING
  TR = atoi(strtokIndx);      // CONVERT THIS PART TO AN INTEGER

  strtokIndx = strtok(NULL, ","); // THIS CONTINUES WHERE THE PREVIOUS CALL LEFT OFF
  BR = atoi(strtokIndx);

  strtokIndx = strtok(NULL, ","); //
  TL = atoi(strtokIndx);

  strtokIndx = strtok(NULL, ","); //
  BL = atoi(strtokIndx);

  strtokIndx = strtok(NULL, ","); //
  DT = atoi(strtokIndx);

  strtokIndx = strtok(NULL, ","); //
  TE = atoi(strtokIndx);
}

//======================

void showParsedData() {  // SHOWS PARSED DATA IN SERIAL MONITOR OUTPUT OF PC
  Serial.print("<");
  Serial.print(TR);
  Serial.print(",");
  Serial.print(BR);
  Serial.print(",");
  Serial.print(TL);
  Serial.print(",");
  Serial.print(BL);
  Serial.print(",");
  Serial.print(DT);
  Serial.print(",");
  Serial.print(TE);
  Serial.print(">");
  Serial.println();
}

When you have a wireless problem simplify simplify.

Try these

// TX
#include <SoftwareSerial.h>

const byte HC12RxdPin = 11;                   // RECEIVE PIN ON HC12
const byte HC12TxdPin = 12;                   // TRANSMIT PIN ON HC12

SoftwareSerial HC12(HC12TxdPin, HC12RxdPin); // CREATE SOFTWARE SERIAL PORT

void setup() {
  HC12.begin(9600); //SERIAL PORT TO HC12
}

void loop() {
  //LIGHT SENSORS CONNNECTED TO ANALOG PIN ON ARDUINO BOARD
  static int TR = 24;


  HC12.print("<"); //SENDS ANALOG VALUES IN THIS FORMAT: I.E. <380,148,224,260,1196,79>
  HC12.print(TR);
  HC12.print(">");
  HC12.println();

  delay(500);
  TR += 1;
}

and

// RX
#include <SoftwareSerial.h>

const byte HC12RxdPin = 11;                   // RECEIVE PIN ON HC12
const byte HC12TxdPin = 12;                   // TRANSMIT PIN ON HC12

SoftwareSerial HC12(HC12TxdPin, HC12RxdPin);  // CREATE SOFTWARE SERIAL PORT

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];        // TEMPORARY ARRAY FOR USE WHEN PARSING

boolean newData = false;

//====================

void setup() {
  Serial.begin(9600); //SERIAL PORT TO PC
  HC12.begin(9600); //SERIAL PORT TO HC12

}

void loop() {
  recvWithStartEndMarkers();
  if (newData == true) {
    Serial.println(receivedChars);
    newData = false;
  }
}

void recvWithStartEndMarkers() {
  static boolean recvInProgress = false;
  static byte ndx = 0;
  char startMarker = '<';
  char endMarker = '>';
  char rc;

  while (HC12.available() > 0 && newData == false) {
    rc = HC12.read();

    if (recvInProgress == true) {
      if (rc != endMarker) {
        receivedChars[ndx] = rc;
        ndx++;
        if (ndx >= numChars) {
          ndx = numChars - 1;
        }
      }
      else {
        receivedChars[ndx] = '\0'; // TERMINATE THE STRING
        recvInProgress = false;
        ndx = 0;
        newData = true;
      }
    }

    else if (rc == startMarker) {
      recvInProgress = true;
    }
  }
}

Note that I have not tested them - but they are unlikely to be too far wrong.

By the way I notice that you have a delay() in loop() in your Rx code - that's a complete NO NO because it could mean that the Rx misses something. Do the timing on the Tx side only.

...R

I removed the delay time (DT) variable from the receiver code.

Information is easily being transferred from one Arduino Uno to another Arduino Uno.
I then put the transmitter code in the Arduino Pro Mini (3.3 V, 8 Mhz) and
the receiver code into the Arduino Uno (5V, 16 Mhz).
This time around there is no delay time (DT) in the void loop of the code.
Still no transfer of information.

I wanted to see if this was an issue between different models of Arduinos.
So I have the transmitter Arduino Pro Mini (3.3V, 8 Mhz) hooked up outside and transmitting data.
I then uploaded the receiver code to another Arduino Pro Mini (3.3V, 8 Mhz) that's hooked up to my PC and I am monitoring the data through the serial monitor and it works!

Really weird that two different Arduino models can't talk to each other via the HC-12 modules, but if they are the same model they can talk to each other.
When they are the same models the HC-12 modules are working!
A mystery to me but maybe useful for others if they run into similar issues.

Thanks again everyone!

Here are pictures below:

Here is some sample data from the Receiver Arduino Pro Mini:

<964,891,854,972,4056,106>
AZIMUTH MOTOR STOPS
   
ELEVATION MOTOR STOPS
   
AZIMUTH MOTOR STOPS
   
ELEVATION MOTOR STOPS
   
AZIMUTH MOTOR STOPS
   
ELEVATION MOTOR STOPS
   
AZIMUTH MOTOR STOPS
   
ELEVATION MOTOR STOPS
   
AZIMUTH MOTOR STOPS

knightridar:
Really weird that two different Arduino models can't talk to each other via the HC-12 modules, but if they are the same model they can talk to each other.

That makes me wonder how you are powering the HC12.

If you are drawing power from the Arduino's 3.3v pin that could be the problem - they cannot really supply enough current. Try putting a 10µF capacitor across Vcc and GND on the HC12.

Or, better still, try using a separate 3,3v power supply with a common GND to the Arduino. You could probably use a pair of AA alkaline cells (3v) for testing.

...R

When I tried using the Arduino Pro mini and sending data to the Arduino Uno,
I tried the method suggested on the site below:

I used the recommended range capacitor and diode and I used a separate power supply.
It didn't work. Data transmission was still blank on the receiver end. Weird.

Setups that are working: (Arduino Pro Mini to Arduino Pro Mini or Arduino Uno to Arduino Uno)

Current setup:Arduino Pro Mini to Arduino Pro Mini

Right now I am powering the transmitter end via the Vcc pin with a 5V, 200 mA solar panel.
On a good sunny day the voltage can get up to 5.2~5.4 volts but that's fine since I read the Arduino Pro mini can handle up to 12 volts input.

For the receiver end I am just currently powering it via the 5V usb to ftdi adapter with the jumper set to 3.3v settings.

Transmitting data successfully with devices about 15-20 meters apart.

Can I use other pins

elavarasan7092:
Can I use other pins

For what?