Wireless control using Arduino | Robot Controlling | Arduino Coding

Wireless Control of devices using Arduino and RF  ASK module.

Components required:-
  1. RF ASK Module.
  2. Two Arduino Boards.
  3. Jumper wires.
  4. Devices to be controlled.
  5. Two 9 volt battery.
Prerequisites:-
  •  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();

}
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 code
Receiver Code       RX code



Comments

. said…
If your system does not not have Virtual wire library you need to download it otherwise code will not get compiled.
Unknown said…
wow it is going to be very helpful..
Unknown said…
For an overview of the basics , it's really nice. Please do post more of the stuffs like this and also the Ultrasonic Standing Waves levitation phenomena, which you've had discussed earlier.☺
. said…
Yeah I will try to work on that in future.
Shanti Mehra said…
Well done govind :)