RF433 Wireless Switch Automation
RF433 Automation Circuit Diagram
Arduino code for RF 433 Mhz Transmitter and Receiver Remote control Switch
// RF 433 TX code#include <VirtualWire.h>
#define button 6
char *data;
int val;
int value = 0;
void setup()
{
vw_set_tx_pin(12);
vw_setup(2000);
pinMode(button, INPUT_PULLUP);
}
void loop()
{
val = digitalRead(button);
if(val == LOW && value == 0)
{
data="a";
vw_send((uint8_t *)data, strlen(data));
vw_wait_tx();
delay(500);
value = 1;
}
else if(val == LOW && value == 1)
{
data="b";
vw_send((uint8_t *)data, strlen(data));
vw_wait_tx();
delay(500);
value = 0;
}
delay(200);
}
//RF433 Rx code
#include <VirtualWire.h>
#define ledPin 13// change the pin number according to you reuirement
void setup()
{
vw_set_rx_pin(11);
vw_setup(2000);
pinMode(ledPin, OUTPUT);
vw_rx_start();
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
if(buf[0]=='a')
{
digitalWrite(ledPin,HIGH);
}
else if(buf[0]=='b')
{
digitalWrite(ledPin,LOW);
}
}
}
//RF433 Mhz Relay control(Receiver Code)
#include <VirtualWire.h>
#define ledPin 13//connect pin # 13 of Arduino to LED Indicator
#define RelayPin 6//connect pin # 6 of Arduino to Relay module IN.
void setup()
{
vw_set_rx_pin(11);//connect pin # 11 of Arduino to Data pin of RF module.
vw_setup(2000);
pinMode(ledPin, OUTPUT);
pinMode(RelayPin, OUTPUT);
vw_rx_start();
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen))
{
if(buf[0]=='a')
{
digitalWrite(ledPin,HIGH);
digitalWrite(RelayPin,LOW);
}
else if(buf[0]=='b')
{
digitalWrite(ledPin,LOW);
digitalWrite(RelayPin,HIGH);
}
}
}
RF433Mhz relay (Transmitter code)
#include <VirtualWire.h>
#define ledPin 13
#define button 6
char *data;
int val;
int value = 0;
void setup()
{
vw_set_tx_pin(12);
vw_setup(2000);
pinMode(ledPin, OUTPUT);
pinMode(button, INPUT_PULLUP);
}
void loop()
{
val = digitalRead(button);
if(val == LOW && value == 0)
{
data="a";
vw_send((uint8_t *)data, strlen(data));
vw_wait_tx();
digitalWrite(ledPin,HIGH);
delay(500);
value = 1;
}
else if(val == LOW && value == 1)
{
data="b";
vw_send((uint8_t *)data, strlen(data));
vw_wait_tx();
digitalWrite(ledPin,LOW);
delay(500);
value = 0;
}
delay(200);
}
Comments
Post a Comment