Skip to content

Instantly share code, notes, and snippets.

/example.c Secret

Created Dec 3, 2017
What would you like to do?
/* HC12 Send/Receive Example Program 1
By Mark J. Hughes
Connect HC12 "RXD" pin to Arduino Digital Pin 4
Connect HC12 "TXD" pin to Arduino Digital Pin 5
Connect HC12 "Set" pin to Arduino Digital Pin 6
Do not power over USB. Per datasheet,
power HC12 with a supply of at least 100 mA with
a 22 uF - 1000 uF reservoir capacitor.
Upload code to two Arduinos connected to two computers.
Transceivers must be at least several meters apart to work.
int potPin = A0;
int value = 0;
#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
void setup() {
Serial.begin(9600); // Open serial port to computer
HC12.begin(9600); // Open serial port to HC12
void loop() {
if(HC12.available()){ // If Arduino's HC12 rx buffer has data
Serial.write(; // Send the data to the computer
if(Serial.available()){ // If Arduino's computer rx buffer has data
HC12.write(; // Send that data to serial
int sensorValue = analogRead(A0);
Serial.print (3.5);
Serial.print (" ");
Serial.print (0);
Serial.print (" ");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment