Accelerometer (X,Y,Z) values using 433mhz using virtualwire.h

Hey friends,
I'm working on the project and stucked on a really bad step :0
I want to send Acclerometer sensor values from one arduino to another using 433Mhz Transmitter and Receiver
I tried VirtualWire.h library and getting error on receiving side
Please help me guys
Here is the code of Transmitter

#include <VirtualWire.h> //Library for Transmitting data

const int xpin = A1; // X pin of Accelerometer Sensor
const int ypin = A2; // Y pin of Accelerometer Sensor
const int zpin = A3;// Z pin of Accelerometer Sensor

int minVal = 265; //For Accelerometer Sensor
int maxVal= 402; //for Accelerometer sensor


//to hold the calculated values
double x; //Declaring the double for X:
double y; //Declaring the double for Y:
double z;//Declaring the double for Z:



int xpinData;// Declaring XPIN DATA
int ypinData;//Declaring YPIN DATA
int zpinData;//Declaring ZPIN DATA


char xpinCharMsg[4]; // Declating space for the provided pin
char ypinCharMsg[4]; // Declating space for the provided pin
char zpinCharMsg[4]; // Declating space for the provided pin

void setup()
{
  Serial.begin(9600);// Start Serial (DEBUGGING ONLY)
 
  vw_setup(2000); //Bits per sec
  
}
void loop()
{
  int xRead = analogRead(xpin); //Analog Reading from the XPIN
  int yRead = analogRead(ypin);//Analog Reading from the YPIN
  int zRead = analogRead(zpin);//Analog Reading from the ZPIN
  
  
  //convert read values to degrees -90 to 90 - Needed for atan2
  int xAng = map(xRead, minVal, maxVal, -90, 90);
  int yAng = map(yRead, minVal, maxVal, -90, 90);
  int zAng = map(zRead, minVal, maxVal, -90, 90);

 
  
  x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI); // Converting the values in an angle
  y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI); // Converting the values in an angle
  z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI); // Converting the values in an angle
  
  
  itoa(x,xpinCharMsg,10);
  itoa(y,ypinCharMsg,10);
  itoa(z,zpinCharMsg,10);
  
  
  Serial.print("Data from X:     " );
  Serial.println(x);
  Serial.print("Data from Y:    ");
  Serial.println(y);
  Serial.print("Data from Z:   ");
  Serial.println(z);
  
  delay(100);
  
  vw_send((uint8_t *) xpinCharMsg,strlen(xpinCharMsg));
    vw_send((uint8_t *) ypinCharMsg,strlen(ypinCharMsg));
      vw_send((uint8_t *) zpinCharMsg,strlen(zpinCharMsg));
  vw_wait_tx();
  delay(50);
}

And Reveiver

#include <VirtualWire.h>

int xpinData;
int ypinData;
int zpinData;

// RF Transmission container
char xpinCharMsg[4];
char ypinCharMsg[4];
char zpinCharMsg[4];

void setup() {
  Serial.begin(9600);
    vw_set_ptt_inverted(true); 
    // Bits per sec
    vw_setup(2000);     
    
    // Start the receiver PLL running
    vw_rx_start();       

} // END void setup

void loop(){
    uint8_t buf[VW_MAX_MESSAGE_LEN];
    uint8_t buflen = VW_MAX_MESSAGE_LEN;
    
    // Non-blocking
    if (vw_get_message(buf, &buflen)) 
    {
    int i;
        // Turn on a light to show received good message 

    
        // Message with a good checksum received, dump it. 
        for (i = 0; i < buflen; i++)
    {            
          // Fill Sensor1CharMsg Char array with corresponding 
          // chars from buffer.   
          xpinCharMsg[i]=char (buf[i]);
          ypinCharMsg[i]=char (buf[i]);
          zpinCharMsg[i]=char (buf[i]);

    }
        
       
        xpinCharMsg[buflen] = '\0';
        ypinCharMsg[buflen] = '\0';
        zpinCharMsg[buflen] = '\0';

        
        // Convert Sensor1CharMsg Char array to integer
        xpinData = atoi(xpinCharMsg);
        ypinData = atoi(ypinCharMsg);
        zpinData = atoi(zpinCharMsg);


        Serial.print("DATA X:");
        Serial.println(xpinData);
        
        
        Serial.print("DATA Y:");
        Serial.println(ypinData);
        
        
        Serial.print("DATA Z:");
        Serial.println(zpinData);
    }
}

Please Help me =( =( =( =( =(

Have you got VirtualWire.h on your PC and where is it ?
Turn on verbose output during compilation (File/Preferences) and try verifying the code. What error messages do you get ?

mudassir9999, I think you are making things hard for yourself.
It is better to transmit a package with just the binary values. For example with 3 float or integers for x,y,z.

I doubt if 4 bytes is always enough for the itoa() function, and you don't handle the data very well in the receiver.
You also use itoa() with double, but itoa() is for integers.

When talking about a 'package', a structure is used.

// untested example code

// declare a template and variable
struct package_t
{
  int x;
  int y;
  int z;
} package;

// fill the data in the transmitter
package.x = (int) x;
package.y = (int) y;
package.z = (int) z;

// transmit it
vw_send((uint8_t *) &package, sizeof (package));

// In the receiver, you use a pointer to 'buf' that contains the received data.

struct package_t
{
  int x;
  int y;
  int z;
};

struct package_t *pPackage;

pPackage = (struct package_t*) buf;

xpinData = pPackage->x;
ypinData = pPackage->y;
zpinData = pPackage->z;

I don't know much about Programming stuffs! & all, And the Error i got is They mixed up all each other like, X-values are coming in Y and Y in X and Z vice versa, They all mixed up with each other and you people know we can't work on them :frowning: :frowning: :frowning:

Or just tell me how can i send & Receive Multi Sensor data in an easier way! :grin:

Instead of a struct, you can use an array of 3 integers: int xyz[3];
you fill it like this:
xyz[0] = x;
xyz[1] = y;
xyz[2] = z;
The size of that array is 6 bytes. So send that array with 6 as size.

Can you remove all the strings, all the 'char', all the 'Msg' and all the itoa part of you sketch. And try to use the array ?

Okay brother I will try to do as you said Thanks in between :slight_smile: