Hi guys,
I'm beginner and have a problem to add button to to controll relay on receiver side. I found sketch to control relay over rf433 wireless modul. This works perfect so I'm able to turn on/off relay. Now I would like to add button to reciver side to be able also controll the same relay over this button but with delay function so If I press button then relay will turn on for 30 seconds and then swithc off.
Will you help me and show how should I do it? I tried it but without succsess.
Thank you...
Here is the basic sketch>
Receiver >
#include <RH_ASK.h>
#include <SPI.h>
RH_ASK driver;
const int output = 2;
char receive[32];
int output_state = 0;
void setup()
{
driver.init();
pinMode(output, OUTPUT);
}
void loop()
{
uint8_t buf[RH_ASK_MAX_MESSAGE_LEN];
uint8_t buflen = sizeof(buf);
if (driver.recv(buf, &buflen))
{
memset(receive, 0, sizeof(receive));
for (int i = 0; i < buflen; i++) {
receive[i] = buf[i];
}
if (strcmp(receive, "Switch") == 0) {
output_state = !output_state;
digitalWrite(output, output_state);
}
}
}
And trasmiter side>
#include <RH_ASK.h>
#include <SPI.h>
const int switch_in = 3;
int state = 0;
char *msg;
RH_ASK driver;
void setup()
{
driver.init();
pinMode(switch_in, INPUT);
}
void loop()
{
if (digitalRead(switch_in) == HIGH && state == 1) {
msg = "Switch";
driver.send((uint8_t *)msg, strlen(msg));
driver.waitPacketSent();
delay(200);
state = 0;
}
else if (digitalRead(switch_in) == LOW) {
state = 1;
}
}