Wireless Control of devices using Arduino and RF ASK module.
Components required:-
Components required:-
- RF ASK Module.
- Two Arduino Boards.
- Jumper wires.
- Devices to be controlled.
- Two 9 volt battery.
- ASK Communication.
- Basic Arduino Programming.
Let's start...
Transmitter :-
# include<VirtualWire.h>
int joyleft = 8;
int joyright = 9;
int f=10,b=11;
const int tx_pin = 7;
char msg[1],p;
void setup()
{
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
vw_set_tx_pin(tx_pin);
Serial.begin(9600);
vw_setup(2000);
}
void loop()
{ int l=0,r=0;
int s = 0,i=0,b; char d;
s = digitalRead(f);
i = digitalRead(11);
r=digitalRead(joyright);
l=digitalRead(joyleft);
if(s==0 && i==0 && r==0 && l==0)
{msg[0]= 'S';
Serial.println("STOP");
}
if(s==1 && i==0)
{
msg[0]='F';
Serial.println("Forward");
}
if(s==0 && i==1)
{
msg[0]='B';
Serial.println("Backward");
}
if(r==0 && l==1)
{
msg[0]='L';
Serial.println("Left");
}
if(r==1 && l==0)
{
msg[0]='R';
Serial.println("right");
}
// for(i=0;i<4;i++)
//{d=msg[i];
//Serial.print(d);
//}Serial.println();
vw_send((uint8_t *)msg,1);
vw_wait_tx();
}
int joyleft = 8;
int joyright = 9;
int f=10,b=11;
const int tx_pin = 7;
char msg[1],p;
void setup()
{
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
vw_set_tx_pin(tx_pin);
Serial.begin(9600);
vw_setup(2000);
}
void loop()
{ int l=0,r=0;
int s = 0,i=0,b; char d;
s = digitalRead(f);
i = digitalRead(11);
r=digitalRead(joyright);
l=digitalRead(joyleft);
if(s==0 && i==0 && r==0 && l==0)
{msg[0]= 'S';
Serial.println("STOP");
}
if(s==1 && i==0)
{
msg[0]='F';
Serial.println("Forward");
}
if(s==0 && i==1)
{
msg[0]='B';
Serial.println("Backward");
}
if(r==0 && l==1)
{
msg[0]='L';
Serial.println("Left");
}
if(r==1 && l==0)
{
msg[0]='R';
Serial.println("right");
}
// for(i=0;i<4;i++)
//{d=msg[i];
//Serial.print(d);
//}Serial.println();
vw_send((uint8_t *)msg,1);
vw_wait_tx();
}
Code
Receiver Code RX code
This code is a Protocol of Transmitter code and is for switching any device ON or OFF.
Receiver :-
Code
# include<VirtualWire.h>
char r;
const int rx_pin = 6;
int i, c, l;
int motor_left1 =7, motor_left2 = 5;
int motor_right1 =4, motor_right2 = 3;
char p;
void setup()
{
pinMode(7, OUTPUT);
pinMode(5, OUTPUT);
pinMode(4, OUTPUT);
pinMode(3, OUTPUT);
vw_set_rx_pin(rx_pin);
Serial.begin(9600);
vw_setup(2000);
vw_rx_start();
}
void loop()
{// digitalWrite(motor_right1, LOW);
// digitalWrite(motor_right2, LOW);
// digitalWrite(motor_left1, LOW);
// digitalWrite(motor_left2, LOW);
{ int b = 0, c = 0;
char f,l,r;
uint8_t buflen = VW_MAX_MESSAGE_LEN;
uint8_t buf[buflen];
//Serial.println("gopu");
if (vw_get_message(buf, &buflen))
{ //Serial.println("bajpai");
// for(i=0;i<4;i++)
// {
// p=buf[i];
// Serial.print(p);
// }Serial.println();
f=buf[0];
Serial.println(f);
if(f=='S')
{
digitalWrite(motor_right1, LOW);
digitalWrite(motor_right2, LOW);
digitalWrite(motor_left1, LOW);
digitalWrite(motor_left2, LOW);
Serial.println("stop");
}
if (f=='F')
{
digitalWrite(motor_right1, HIGH);
digitalWrite(motor_right2, LOW);
digitalWrite(motor_left1, HIGH);
digitalWrite(motor_left2, LOW);
Serial.println("forward");
}
b=buf[0];
if (b=='B')
{
digitalWrite(motor_right1, LOW);
digitalWrite(motor_right2, HIGH);
digitalWrite(motor_left1,HIGH);
digitalWrite(motor_left2,LOW);
Serial.println("Turning Right");
}
l=buf[0];
if (l == 'L')
{
digitalWrite(motor_right1, HIGH);
digitalWrite(motor_right2, LOW);
digitalWrite(motor_left1,LOW);
digitalWrite(motor_left2,HIGH);
Serial.println("Turning left");
}
r=buf[0];
if (r == 'R')
{
digitalWrite(motor_right1,LOW);
digitalWrite(motor_right2,HIGH);
digitalWrite(motor_left1,LOW);
digitalWrite(motor_left2,HIGH);
Serial.println("BACKWARD");
}
}
}}
This code is a Protocol of Receiver code and is for switching any device ON or OFF.
Note :- From above given material one can learn How to make Transmitter and receiver. This kit of Transmitter and Receiver can be used to control various devices like making a remote control car.Codes of Transmitter and Receiver of RC Car:-
To download Tx Rx Code Click the link below.
Transmitter Code TX codeReceiver Code RX code
Comments