This is the code for the Arduino and HC12 radio module receiver example for 1 byte data. Read all comments in the code in order to understand more. Downlaod the code from the link below or just copy the code from below as well.
/* 1byte HC12 TRANSMITTER example.
/* Tutorial link: http://electronoobs.com/eng_arduino_tut96.php
* Code: http://electronoobs.com/eng_arduino_tut96_code1.php
* Scheamtic: http://electronoobs.com/eng_arduino_tut96_sch1.php
* Youtube Channel: http://www.youtube/c/electronoobs
*
Module // Arduino UNO/NANO
GND -> GND
Vcc -> 3.3V
Tx -> D10
Rx -> D11
*/
#include <SoftwareSerial.h>
SoftwareSerial HC12(10, 11); // HC-12 TX Pin, HC-12 RX Pin
int pot = A2;
void setup() {
Serial.begin(9600); // Serial port to computer
HC12.begin(9600); // Serial port to HC12
pinMode(pot,INPUT);
}
void loop() {
int val = map(analogRead(pot),0,1024,0,255);
HC12.write(val); // Send that data to HC-12
}