RF 2 ways communicatoin
hello new here
please me 2 ways communication.i use 2 arduino , pair rf , push button , leds. for 1 ways communication 2 way have problems.i hope can me
here coding
transmitter
//----------------------transmitter--------------------//
#include <virtualwire.h>
int button_gate = 3;
int button_gate_read = 0;
//----------------------receiver-------------------------//
#include <virtualwire.h>
void setup() {
//--------------------transmitter-------------------------//
serial.begin(9600);
pinmode(button_gate, input);
vw_setup(2000);
vw_set_tx_pin(6);
//-----------------------receiver------------------------//
pinmode(13,output);
digitalwrite(13,low);
vw_setup(2000);
vw_set_rx_pin(7);
vw_rx_start();
}
void loop() {
// put main code here, run repeatedly:
//------------------------receiver----------------------//
uint8_t buflen = vw_max_message_len;
uint8_t buf[buflen];
if(vw_get_message(buf, &buflen))
{
for(int = 0;i < buflen;i++)
{
if(buf == 'on_01')
{
digitalwrite(13,high);
}
else if(buf == 'off_01')
{
digitalwrite(13,low);
}
}
}
//--------------------------trasnmitter------------------//
char on_1[100] = {'on_2'};
char off_1[100] = {'off_2'};
button_gate_read = digitalread(button_gate);
if (button_gate_read == high)
{
vw_send((uint8_t *)on_1, 100);
}
else if (button_gate_read == low)
{
vw_send((uint8_t *)off_1, 100);
}
}
receiver
//----------------------transmitter--------------------//
#include <virtualwire.h>
int button_gate = 3;
int button_gate_read = 0;
//----------------------receiver-------------------------//
#include <virtualwire.h>
void setup() {
//--------------------transmitter-------------------------//
serial.begin(9600);
pinmode(button_gate, input);
vw_setup(2000);
vw_set_tx_pin(6);
//-----------------------receiver------------------------//
pinmode(13,output);
digitalwrite(13,low);
vw_setup(2000);
vw_set_rx_pin(7);
vw_rx_start();
}
void loop() {
// put main code here, run repeatedly:
//--------------------------trasnmitter------------------//
char on_2[100] = {'on_01'};
char off_2[100] = {'off_01'};
button_gate_read = digitalread(button_gate);
if (button_gate_read == high)
{
vw_send((uint8_t *)on_2, 100);
}
else if (button_gate_read == low)
{
vw_send((uint8_t *)off_2, 100);
}
//------------------------receiver----------------------//
uint8_t buflen = vw_max_message_len;
uint8_t buf[buflen];
if(vw_get_message(buf, &buflen))
{
for(int = 0;i < buflen;i++)
{
if(buf == 'on_02')
{
digitalwrite(13,high);
}
else if(buf == 'on_02')
{
digitalwrite(13,low);
}
}
}
}
please me 2 ways communication.i use 2 arduino , pair rf , push button , leds. for 1 ways communication 2 way have problems.i hope can me
here coding
transmitter
//----------------------transmitter--------------------//
#include <virtualwire.h>
int button_gate = 3;
int button_gate_read = 0;
//----------------------receiver-------------------------//
#include <virtualwire.h>
void setup() {
//--------------------transmitter-------------------------//
serial.begin(9600);
pinmode(button_gate, input);
vw_setup(2000);
vw_set_tx_pin(6);
//-----------------------receiver------------------------//
pinmode(13,output);
digitalwrite(13,low);
vw_setup(2000);
vw_set_rx_pin(7);
vw_rx_start();
}
void loop() {
// put main code here, run repeatedly:
//------------------------receiver----------------------//
uint8_t buflen = vw_max_message_len;
uint8_t buf[buflen];
if(vw_get_message(buf, &buflen))
{
for(int = 0;i < buflen;i++)
{
if(buf == 'on_01')
{
digitalwrite(13,high);
}
else if(buf == 'off_01')
{
digitalwrite(13,low);
}
}
}
//--------------------------trasnmitter------------------//
char on_1[100] = {'on_2'};
char off_1[100] = {'off_2'};
button_gate_read = digitalread(button_gate);
if (button_gate_read == high)
{
vw_send((uint8_t *)on_1, 100);
}
else if (button_gate_read == low)
{
vw_send((uint8_t *)off_1, 100);
}
}
receiver
//----------------------transmitter--------------------//
#include <virtualwire.h>
int button_gate = 3;
int button_gate_read = 0;
//----------------------receiver-------------------------//
#include <virtualwire.h>
void setup() {
//--------------------transmitter-------------------------//
serial.begin(9600);
pinmode(button_gate, input);
vw_setup(2000);
vw_set_tx_pin(6);
//-----------------------receiver------------------------//
pinmode(13,output);
digitalwrite(13,low);
vw_setup(2000);
vw_set_rx_pin(7);
vw_rx_start();
}
void loop() {
// put main code here, run repeatedly:
//--------------------------trasnmitter------------------//
char on_2[100] = {'on_01'};
char off_2[100] = {'off_01'};
button_gate_read = digitalread(button_gate);
if (button_gate_read == high)
{
vw_send((uint8_t *)on_2, 100);
}
else if (button_gate_read == low)
{
vw_send((uint8_t *)off_2, 100);
}
//------------------------receiver----------------------//
uint8_t buflen = vw_max_message_len;
uint8_t buf[buflen];
if(vw_get_message(buf, &buflen))
{
for(int = 0;i < buflen;i++)
{
if(buf == 'on_02')
{
digitalwrite(13,high);
}
else if(buf == 'on_02')
{
digitalwrite(13,low);
}
}
}
}
please read "how use forum" post , follow directions. edit post add code tags.
Arduino Forum > Using Arduino > Networking, Protocols, and Devices (Moderator: fabioc84) > RF 2 ways communicatoin
arduino
Comments
Post a Comment