HC-12 for controlling switches
hi every one. can used hc-12 module remotely controlled 16 switches?
thanks
thanks
i tried sample net , works fine switches only. when extend 3 16 switches,, gives me intermittent problem.. turn on switch , not.. wander if there alternative use other module other hc-12.
thanks
thanks
code: [select]
// transmitt side
#include <softwareserial.h>
softwareserial myserial(2, 3); //rx, tx
int buttonpin = 8;
boolean onoff = 0;
void setup() {
pinmode(buttonpin, input);
myserial.begin(9600);
}
void loop() {
int buttonstate = digitalread(buttonpin);
if(buttonstate == 1){//if button down
myserial.println(1111);//send unique code receiver turn on. in case 1111
onoff = 1;//set boolean 1
}
if(buttonstate == 0 && onoff == 1){//verifier send off signal once
myserial.println(0000);//send unique code receiver turn off. in case 0000
}
delay(20);//delay little better serial communication
}
code: [select]
// receiver's side
#include <softwareserial.h>
softwareserial myserial(2, 3); // rx, tx
int ledpin = 13;
unsigned long last = millis();//set timer
void setup() {
myserial.begin(9600);
pinmode(ledpin, output);
}
void loop() {
boolean ledstate = digitalread(ledpin);//check if led turned on or off. returns 1 or 0
if(myserial.available() > 1){
int input = myserial.parseint();//read serial input , convert integer (-32,768 32,767)
if(millis() - last > 250){//if time 250 milliseconds greater last time
if(ledstate == 0 && input == 1234){//if led off , button code ok
digitalwrite(ledpin, high);
}else if(ledstate == 1 && input == 1234){//if led on , button code ok
digitalwrite(ledpin, low);
}
}
myserial.flush();//clear serial buffer unwanted inputs
last = millis();//reset timer
}
delay(20);//delay little better serial communication
}
Arduino Forum > Using Arduino > Programming Questions > HC-12 for controlling switches
arduino
Comments
Post a Comment