Hi,
I'm currently making a quadcopter out of an arduino using 2 HC-12 for communication. I've followed the topic of tomheylen on Instructables.
Following his instruction, I have been able to parameter the whole thing with the AT command ( using channel 002, 2400 bauds, FU3 ).
I however failed to make it transmit any data. here is the test code I used (with a few lines adapted from tomheylen :
The sending module :
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); //TX, RX
int buttonPin = 8;
boolean onOff = 0;
void setup() {
pinMode(buttonPin, INPUT);
mySerial.begin(2400);
}
void loop() {
int buttonState = digitalRead(buttonPin);//read button state
if(buttonState == 1){//if button is down
mySerial.println(1111);//send unique code to the receiver to turn on. In this case 1111
onOff = 1;//set boolean to 1
}
if(buttonState == 0 && onOff == 1){//Verifier to send off signal once
mySerial.println(0000);//send unique code to the receiver to turn off. In this case 0000
}
delay(20);//delay little for better serial communication
}
The recieving Module :
//HC-12 Momentary Button Receive
//Autor Tom Heylen tomtomheylen.com
#include <SoftwareSerial.h>
SoftwareSerial mySerial(11, 4); // TX, RX
int ledPin = 13;
void setup() {
mySerial.begin(2400);
pinMode(ledPin, OUTPUT);
}
void loop() {
if(mySerial.available() > 1){
int input = mySerial.parseInt();//read serial input and convert to integer (-32,768 to 32,767)
if(input == 1111){//if on code is received
digitalWrite(ledPin, HIGH);//turn LED on
}
if(input == 0000){//if off code is received
digitalWrite(ledPin, LOW);//turn LED off
}
}
mySerial.flush();//clear the serial buffer for unwanted inputs
delay(20);//delay little for better serial communication
}
One of my arduino is a UNO and the other one a 101
Both have made their job configuring the HC-12 so I think the compatibility is good.
Do you have an Idea what can cause this trouble ?
Thx in advance