-
-
Save anonymous/c122d53c04ef2f1cac3a7684c7866edc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* HC12 Send/Receive Example Program 1 | |
By Mark J. Hughes | |
for AllAboutCircuits.com | |
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(HC12.read()); // Send the data to the computer | |
} | |
if(Serial.available()){ // If Arduino's computer rx buffer has data | |
HC12.write(Serial.read()); // Send that data to serial | |
} | |
int sensorValue = analogRead(A0); | |
Serial.print (3.5); | |
Serial.print (" "); | |
Serial.print (0); | |
Serial.print (" "); | |
Serial.println(sensorValue/292); | |
delay(50); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment