how to wirelessly send multiple analog signals to one radio reciever

hello,

it is my first time coding on wireless communication and I decided to write the code for it before I purchase it, but doing this means I cant troubleshoot it. I am building a servo arm that I can control wirelessly with several potentiometers

i would like to know how to send all of the analog signals to the radio receiver and be able to interpret each one individually (so potentiometers will only control servo1) , I have watched tutorials on how the HC-12 works and it says it only send bytes of data , I would need to turn those bytes into a char and then into a string but I get error messages.

this is the code for the transmitter

#include <SoftwareSerial.h>
#include <Servo.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //i2c pins

//define potentiometers only used for memory mode
const int pot1 = A1;
const int pot2 = A2;
const int pot3 = A3;
const int pot4 = A4;

//define variable for values of the potentiometers
int pot1Val;
int pot2Val;
int pot3Val;
int pot4Val;

//define variable for angles of the potentiometer
int pot1Angle;
int pot2Angle;
int pot3Angle;
int pot4Angle;

//define variable for saved position of the servos
int servo1PosSave[]={1,1,1,1,1,1,1,1};
int servo2PosSave[]={1,1,1,1,1,1,1,1};
int servo3PosSave[]={1,1,1,1,1,1,1,1};
int servo4PosSave[]={1,1,1,1,1,1,1,1};


//the signals that are going to be transmite wirelessly
char sig1[];
char sig2[];
char sig3[];
char sig4[];

 
void setup() {

  HC12.begin(9600);               // Serial port to HC12
  lcd.begin(16,2);      //WE define our LCD 16 columns and 2 rows
  lcd.backlight();      //Power on the back light
  lcd.backlight();      //Power off the back light

  //defining outputs and inputs
 // pinMode(soundSensor, INPUT);
 // pinMode(memoryButton, INPUT);
 // pinMode(replayButton, INPUT);

  //establish communication with the user
  lcd.setCursor(0,0);
  lcd.print("B.M.O is online"); 
  delay(1000);
  lcd.clear();
}



void loop() {
   
     //----------------------------------------------------------------------------------------------------------------------------//
     //                                                 Manual Control Mode                                                        //
     //----------------------------------------------------------------------------------------------------------------------------//
    
      //read the potentiometer values and define the servo angle to
      //the potentiometer value with the map function
      pot1Val = analogRead(pot1);
      pot1Angle = map (pot1Val, 0, 1023, 10, 180);
      
      pot2Val = analogRead(pot2);
      pot2Angle = map (pot2Val, 0, 1023, 10, 180);
      
      pot3Val = analogRead(pot3);
      pot3Angle = map (pot3Val, 0, 1023, 10, 180);
      
      pot4Val = analogRead(pot4);
      pot4Angle = map (pot4Val, 0, 1023, 10, 180);
      
      //creating the signals that will be transmitted
      sig1[] = "A" + pot1Angle;
      sig2[] = "B" + pot2Angle;
      sig3[] = "C" + pot3Angle;
      sig4[] = "D" + pot4Angle;
      
      //servos move to mapped angles
      HC12.write(sig1[]);
      HC12.write(sig2[]);
      HC12.write(sig3[]);
      HC12.write(sig4[]);

and this is the code for the receiver

#include <Servo.h>
#include <SoftwareSerial.h>

SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin

byte incomsig;
char readbuffer[] = "";

//define the servos
Servo servo1;
Servo servo2;
Servo servo3;
Servo servo4;

//define variable for values of the button
int button1Pressed = 0;
boolean button2Pressed = false;

//define variable for saved position of the servos
int servo1PosSave[]={1,1,1,1,1,1,1,1};
int servo2PosSave[]={1,1,1,1,1,1,1,1};
int servo3PosSave[]={1,1,1,1,1,1,1,1};
int servo4PosSave[]={1,1,1,1,1,1,1,1};


void setup() {
  
  //define attached pins of the servos
  servo1.attach(3);
  servo2.attach(4);
  servo3.attach(5);
  servo4.attach(6);
 
  servo1.write(90);
  servo2.write(90);
  servo3.write(90);
  servo4.write(90);

  HC12.begin(9600);               // Serial port to HC12

}


void loop() {
  while(HC12.available()) {        // If HC-12 has data  
     //----------------------------------------------------------------------------------------------------------------------------//
     //                                                 Manual Control Mode                                                        //
     //----------------------------------------------------------------------------------------------------------------------------//
      incomsig = HC12.read();
      readbuffer += char(incomsig);
      }

     if(readbuffer[0] == "A"){
       readbuffer[] = readbuffer[] - readbuffer[0];
       servo1.write(readbuffer);
       }
     
     
     // servo2.write(pot2Angle);
     // servo3.write(pot3Angle);
     // servo4.write(pot4Angle);

it is not finished yet as I do not know where to go next with the code as soon I would like to implement a memory function so the robot arm can replay saved positions but I can’t even begin to imagin how I would send all of that data wirelessly

Welcome to the forums. +1 Karma for using code tags with your first post.

As for you code.... you are not using char arrays properly. You do not just put empty brackets after the name everywhere (sig1). Read the Serial Input Basics to learn how to properly and reliably send and receive information over serial. There are even examples that deal with sending data and parsing it which you should use.

You can use SerialTransfer.h to automatically packetize and parse your data for inter-Arduino communication without the headace. The library is installable through the Arduino IDE and includes many examples.

Here are the library’s features:

This library:

  • can be downloaded via the Arduino IDE’s Libraries Manager (search “SerialTransfer.h”)
  • works with “software-serial” libraries
  • is non blocking
  • uses packet delimiters
  • uses consistent overhead byte stuffing
  • uses CRC-8 (Polynomial 0x9B with lookup table)
  • allows the use of dynamically sized packets (packets can have payload lengths anywhere from 1 to 254 bytes)
  • can transfer bytes, ints, floats, and even structs!!

Example TX Arduino Sketch:

#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  char buff[] = "hi";

  myTransfer.txObj(buff, sizeof(buff));
  myTransfer.sendData(sizeof(buff));
  delay(100);
}

Example RX Arduino Sketch:

#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  if(myTransfer.available())
  {
    char buff[40];
    
    myTransfer.rxObj(buff, sizeof(buff));
    
    Serial.println("New Data: ");
    Serial.write(buff, sizeof(buff));
    Serial.println();
  }
  else if(myTransfer.status < 0)
  {
    Serial.print("ERROR: ");

    if(myTransfer.status == -1)
      Serial.println(F("CRC_ERROR"));
    else if(myTransfer.status == -2)
      Serial.println(F("PAYLOAD_ERROR"));
    else if(myTransfer.status == -3)
      Serial.println(F("STOP_BYTE_ERROR"));
  }
}

For theory behind robust serial communication, check out the tutorials Serial Input Basics and Serial Input Advanced.

Maybe this will help.

F3RD1N4ND:
it is my first time coding on wireless communication and I decided to write the code for it before I purchase it, but doing this means I cant troubleshoot it.

I understand the inconvenience of not having the hardware available but it is not a good idea to write a program of several parts without testing each part as you go. If you try to build it all as a single piece you will have a lot more trouble tracking down an error.

Wireless problems can be very difficult to debug because there is no means to know whether the problem is in the Tx or the Rx. Be sure to get a few spare wireless modules in case you have a doubt that one of them may be faulty.

...R

I am new to wireless communication and don’t know how to send multiple analog signals with a HC-12 and have it de able to be distinguished so potentiometer 1 controls servo one instead on all of them, I am making a servo arm wireless, I reallly need help as this is all just confusing me

here is the code for the transmitter

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); //i2c pins
 

SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin

//define the sensors
//const int soundSensor = 12; //microphone
//define button to activate memory mode
//const int memoryButton = 15;
//const int replayButton = 16;

//define variable for values of the button
//int button1Pressed = 0;
//boolean button2Pressed = false;

//define potentiometers only used for memory mode
const int pot1 = A1;
const int pot2 = A2;
const int pot3 = A3;
const int pot4 = A4;

//define variable for values of the potentiometers
int pot1Val;
int pot2Val;
int pot3Val;
int pot4Val;

//define variable for angles of the potentiometer
int pot1Angle;
int pot2Angle;
int pot3Angle;
int pot4Angle;

//define variable for saved position of the servos
int servo1PosSave[]={1,1,1,1,1,1,1,1};
int servo2PosSave[]={1,1,1,1,1,1,1,1};
int servo3PosSave[]={1,1,1,1,1,1,1,1};
int servo4PosSave[]={1,1,1,1,1,1,1,1};


//the signals that are going to be transmitted wirelessly
char sig1[];
char sig2[];
char sig3[];
char sig4[];

 
void setup() {

  HC12.begin(9600);               // Serial port to HC12
  lcd.begin(16,2);      //WE define our LCD 16 columns and 2 rows
  lcd.backlight();      //Power on the back light
  lcd.backlight();      //Power off the back light

  //defining outputs and inputs
 // pinMode(soundSensor, INPUT);
 // pinMode(memoryButton, INPUT);
 // pinMode(replayButton, INPUT);

  //establish communication with the user
  lcd.setCursor(0,0);
  lcd.print("B.M.O is online"); 
  delay(1000);
  lcd.clear();
}



void loop() {
   
     //----------------------------------------------------------------------------------------------------------------------------//
     //                                                 Manual Control Mode                                                        //
     //----------------------------------------------------------------------------------------------------------------------------//
    
      //read the potentiometer values and define the servo angle to
      //the potentiometer value with the map function
      pot1Val = analogRead(pot1);
      pot1Angle = map (pot1Val, 0, 1023, 10, 180);
      
      pot2Val = analogRead(pot2);
      pot2Angle = map (pot2Val, 0, 1023, 10, 180);
      
      pot3Val = analogRead(pot3);
      pot3Angle = map (pot3Val, 0, 1023, 10, 180);
      
      pot4Val = analogRead(pot4);
      pot4Angle = map (pot4Val, 0, 1023, 10, 180);
      
      //creating the signals that will be transmitted
      sig1[] = "A" + pot1Angle;
      sig2[] = "B" + pot2Angle;
      sig3[] = "C" + pot3Angle;
      sig4[] = "D" + pot4Angle;
      
      //servos move to mapped angles
      HC12.write(sig1[]);
      HC12.write(sig2[]);
      HC12.write(sig3[]);
      HC12.write(sig4[]);

I soon would like to add a memory feature but at this point in time it seems impossible

Go back several steps. Forget the servos for now.

Have you been able to use the HC-12 to transmit a single value and have the receiver display that value on the serial monitor ?

@F3RD1N4ND

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.