HC-12 programming

Hey! I am working on making a RC boat, powered by brushless motor and a servo.

So I am going to be using two button(for servo) and a potentiometer(for brushless motor 1000kv). on the transmitting end.

I will be using a brushless motor and servo on the receiving end.

PROBLEM 1:

So first trial I tried to control brushless motor, and servo separately. The servo part worked ,but when I am trying to transmit the potentiometer values, the values at the receiving end is disturbed. Here is the program.(NOTE: This program is only to check is the values transmitting and receiving are proper)

Transmitter

#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 10); //RX, TX
int vcc=8;
int gnd=9;
int pot=A0;  //potentiometer pin
int potval;


void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(vcc,OUTPUT);
  pinMode(gnd,OUTPUT);

  pinMode(pot,INPUT);
 
}



void loop() {
  digitalWrite(vcc,HIGH);
  digitalWrite(gnd,LOW);
  
  potval=analogRead(pot);

Serial.println(potval);
mySerial.println(potval);

 
  delay(10);
}

Receiver

#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 10); //RX, TX
int vcc=8;
int gnd=9;
int input;

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(vcc,OUTPUT);
  pinMode(gnd,OUTPUT);

}


void loop() {
  digitalWrite(vcc,HIGH);
  digitalWrite(gnd,LOW);
  
 input=mySerial.parseInt();
  Serial.println(input);


  delay(10);
}

and here is the output I get

223
2249
3
277
2292
2
318
3337
59
13370
407
25675
464
15744
515
-10007
5542
-9986
5559
5570
5580
5
596
6604
621
6635
642
6654
4
682
6693
8
715
7728
43
6656
7777
1366
814
23297
8851
23331
8883
8903
9911
9
929
9943
962
9963
969
9971
5
973
9974
36
975
9974
76
5110
7975
-3067
976
-31091
9993
-31095
9986
9987
9992
9
993
9994
991
9993
994
9953
1
988
9950
65
11669
942
-5265
798
23531
9955
-31185
8793
6659
5572
5522
5492
4
459
4438
402
3366
4
321
3300
1
265
2242
22
24024
141
12190
39
328
25
115
115
17
110
11
112
112
26
313
13
112
114
14
34
13
514
2266
962
1
19
716
1134
116
6
15
115
1113
113
35
14
115
1112
114

I don't understand what is the problem here and how to correct it.


Problem 2:

I want to control the brushless motor and the servo. So the signal transmitted should differentiate which is for servo and which is for brushless. I am not sure how this problem should be tackled and what should be done.

Thanks in advance.

  pinMode(pot,INPUT);

You should not be setting the digital mode of a pin that you are using as an analog pin.

 input=mySerial.parseInt();
  Serial.println(input);

On EVERY pass through loop(), wait for a new value. Not the best approach.

  delay(10);

You haven't stuck your head in the sand for long enough already?

Serial.println(potval);
mySerial.println(potval);

Sharing the sending end data would be useful.

What, exactly, is connected to pins 10 and 11 on each end? I am CERTAIN that it is not a mySerial, despite the stupid instance name.

  1. I don't understand what you mean by "digital mode of a pin that you are using as an analog pin."

2.I don't understand what you mean by "On EVERY pass through loop(), wait for a new value. Not the best approach."

3.I don't understand what you mean by "You haven't stuck your head in the sand for long enough already?"

4."Sharing the sending end data would be useful." do you mean to send the values received back to the transmitter ?

could you please explain like what i should do and what is the problem ?

  1. Actually i made the HC-12 module like a mount on where the pin 8 and 9 are connected to the positive and negative ends. Pin 11 and 12 are the transmitting and receiving part of the pin.

And just to clarify if you think there is any problem with the setup or the board. I tried other programs like sending text from one side to another and onn and off a led wirelessly.

  1. I don't understand what you mean by "digital mode of a pin that you are using as an analog pin."

Then you should be starting with a MUCH simpler project. Some pins are digital only. Some pins are analog pins that share space with a digital pin.

You need to set the mode of digital pins. You do not need to set the mode of analog pins, which are input only.

2.I don't understand what you mean by "On EVERY pass through loop(), wait for a new value. Not the best approach."

What don't you understand? On EVERY pass through loop(), you call a blocking function, which waits for serial data to arrive. You COULD check whether there is serial data to read, and not block unless there is some (maybe not complete) data to read.

3.I don't understand what you mean by "You haven't stuck your head in the sand for long enough already?"

Perhaps you would if the delay() function was properly named - stickYourHeadInTheSandForAWhile().

4."Sharing the sending end data would be useful." do you mean to send the values received back to the transmitter ?

No. I mean sharing the serial monitor output with us.

  1. Actually i made the HC-12 module like a mount on where the pin 8 and 9 are connected to the positive and negative ends. Pin 11 and 12 are the transmitting and receiving part of the pin.

That's clear. As mud. Draw a schematic and post it. No more hand-waving.

And just to clarify if you think there is any problem with the setup or the board. I tried other programs like sending text from one side to another and onn and off a led wirelessly.

And you are keeping the results of those tests secret.

I'm wondering if you really do want help.