Here is complete tx code:
Can you pl. sort out where i need to put 0 value
int forward = 8;
int backward = 9;
int rightTurn = 10;
int leftTurn = 11;
int remotePins[]= {8,9,10,11};//array to store pin nos
void setup()
{
Serial.begin(9600); // Debugging only
Serial.println("setup");
// Initialise the IO and ISR
vw_setup(2000); // Bits per sec
vw_set_tx_pin(3); //Transmitter Data Pin to Digital Pin 3
for(int i = 0; i<5 ; i++)
{
pinMode(remotePins[i], INPUT);
digitalWrite(remotePins[i],HIGH);
}
/*
This is what the loop above does :-
pinMode(8, INPUT);
pinMode(9, INPUT);
pinMode(10, INPUT);
pinMode(11, INPUT);
pinMode(6, INPUT);
digitalWrite(8, HIGH);
digitalWrite(9, HIGH);
digitalWrite(10, HIGH);
digitalWrite(11, HIGH);
digitalWrite(6, HIGH);*/
}//close setup
void loop()
{
char *msg2;
if(digitalRead(forward) == LOW)//if the forward button is pressed
{
char *msg2 = "1";//send 1 to the receiver
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg2, strlen(msg2));//send the byte to the receiver
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
}
if(digitalRead(backward) == LOW)//if the back button is pressed
{
char *msg2 = "2";///send 2 to the receiver
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg2, strlen(msg2));//send the byte to the receiver
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
}
if(digitalRead(leftTurn) == LOW)//if the left button is pressed
{
char *msg2 = "3";//send 3 to the receiver
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg2, strlen(msg2));//send the byte to the receiver
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
}
if(digitalRead(rightTurn) == LOW)//if the right button is pressed
{
char *msg2 = "4";//send 4 to the receiver
digitalWrite(13, true); // Flash a light to show transmitting
vw_send((uint8_t *)msg2, strlen(msg2));//send the message to the receiver
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(13, false);
}
}//close loop
Here is complete code in receiver:
/**
//Pinouts
#include <VirtualWire.h>
//Motor A -Front drive
int pinA1 = 11; //11
int pinA2 = 10; //10
///Motor B-Rear drive
int pinB1 = 5; //5
int pinB2 = 4; //4
///Motor C (steering)
int pinC1 = 8; //8
int pinC2 = 7; //7
void setup()
{
Serial.begin(9600);
// Initialise the IO and ISR
vw_setup(2000); // Bits per sec
vw_set_rx_pin(6); //Rx Data pin to Digital Pin 6
vw_rx_start(); // Start the receiver PLL running
/* Initialize Motor A Pin Modes */
pinMode (pinA1, OUTPUT);
pinMode (pinA2, OUTPUT);
/* Initialize Motor B Pin Modes */
pinMode (pinB1, OUTPUT);
pinMode (pinB2, OUTPUT);
/* Initialize Motor C Pin Modes */
pinMode (pinC1, OUTPUT);
pinMode (pinC2, OUTPUT);
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // Non-blocking
{
int i;
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i]);//print received command
if(buf[i] == '1')//if button 1 is pressed.... i.e.forward buton
{
forward();//go forward
Serial.println(" = forward");
}
if(buf[i] == '2')//if button 2 is pressed.... i.e.back buton
{
goBack();//go backward
Serial.println(" = backward");
}
if(buf[i] == '3')//if button 3 is pressed.... i.e.left buton
{
turnLeft();//go left
Serial.println(" = left");
}
if(buf[i] == '4')//if button 4 is pressed.... i.e.right buton
{
turnRight();//go right
Serial.println(" = right");
}
}
}
}
//function to go forward
void forward()
{
digitalWrite (pinA1, LOW);
digitalWrite (pinA2, HIGH);
digitalWrite (pinC1, LOW);
digitalWrite (pinC2, HIGH);
}
//function to stop Motor AC movement
void stopMotorAC()
{
digitalWrite (pinA1,LOW);
digitalWrite (pinA2,LOW);
digitalWrite (pinC1, LOW);
digitalWrite (pinC2, LOW);
}
//function to go back
void goBack()
{
digitalWrite (pinA1,HIGH);
digitalWrite (pinA2,LOW);
digitalWrite (pinC1,HIGH);
digitalWrite (pinC2,LOW);
}
//function to stop Motor B movement
void stopMotorB()
{
digitalWrite (pinB1, LOW);
digitalWrite (pinB2, LOW);
}
//function to turn the RC car right
void turnRight()
{
digitalWrite (pinB1, LOW);
digitalWrite (pinB2, HIGH);
}
//function to turn the RC car left
void turnLeft()
{
digitalWrite (pinB1,HIGH);
digitalWrite (pinB2,LOW);
}