433Mhz sending and receiving array.

Hi,
I’m a n00bie in this section.I want to send array using VirtualWire library from 433Mhz Rx & Tx Modules I want to Transmit the data and receive at another side using Arduino,I prepared these two sketches at the receiver Serial monitor it only shows 0’s in X,Y,Z.
Please help

Receiver code

#include <VirtualWire.h>

// LED's
int ledPin = 13;

char sensorArray[10];

char x;
char y;
char z;

const int receive_pin = 11;




void setup() {

  vw_set_rx_pin(receive_pin);

  Serial.begin(9600);

  // sets the digital pin as output
  pinMode(ledPin, OUTPUT);

  // VirtualWire
  // Initialise the IO and ISR
  // Required for DR3100
  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
    digitalWrite(13, true);

    // Message with a good checksum received, dump it.
    for (i = 0; i < buflen; i++)
    {
      // Fill Sensor1CharMsg Char array with corresponding
      // chars from buffer.
      sensorArray[i] = char(buf[i]);
    }
    sensorArray[0] == x;
    sensorArray[1] == y;
    sensorArray[2] == z;



    // DEBUG
    Serial.print("X: ");
    Serial.println(x);

    Serial.print("Y: ");
    Serial.println(y);

    Serial.print("z: ");
    Serial.println(z);

    // END DEBUG

    // Turn off light to and await next message
    digitalWrite(13, false);
  }
}

Transmitter code

#include <VirtualWire.h>

const int transmit_pin = 12;


//Analog read pins
const int xPin = 0;
const int yPin = 1;
const int zPin = 2;

//The minimum and maximum values that came from
//the accelerometer while standing still
//You very well may need to change these
int minVal = 265;
int maxVal = 402;


//to hold the caculated values
double x;
double y;
double z;


//buffer
int Sensor1Data;
int Sensor2Data;
int Sensor3Data;





void setup() {

  vw_set_tx_pin(transmit_pin);

  // VirtualWire setup
  vw_setup(2000);     // Bits per sec

  Serial.begin(9600);
}


void loop() {

  //read the analog values from the accelerometer
  int xRead = analogRead(xPin);
  int yRead = analogRead(yPin);
  int zRead = analogRead(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);

  //Caculate 360deg values like so: atan2(-yAng, -zAng)
  //atan2 outputs the value of -π to π (radians)
  //We are then converting the radians to degrees
  x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
  y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
  z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);



//printing values
  Serial.print("X: ");
  Serial.print(x);

  Serial.print("  Y: ");
  Serial.print(y);

  Serial.print("  Z:");
  Serial.println(z);


char sensorArray[] = {x, y, z};


  digitalWrite(13, true); // Turn on a light to show transmitting
  vw_send((uint8_t *)sensorArray, strlen(sensorArray));
  vw_wait_tx(); // Wait until the whole message is gon
  delay(50);




}

Thanks in Advance

In the transmit code, your data is an array of doubles, so just break it into bytes with the uint8_t* cast and send those bytes. Here’s the code with dummy variables for the analogReads.

#include <VirtualWire.h>

const int transmit_pin = 12;


//Analog read pins
const int xPin = 0;
const int yPin = 1;
const int zPin = 2;

//The minimum and maximum values that came from
//the accelerometer while standing still
//You very well may need to change these
int minVal = 265;
int maxVal = 402;


//to hold the caculated values
double x;
double y;
double z;

//buffer
int Sensor1Data;
int Sensor2Data;
int Sensor3Data;

void setup() {

  vw_set_tx_pin(transmit_pin);

  // VirtualWire setup
  vw_setup(2000);     // Bits per sec

  Serial.begin(9600);
}


void loop() {

  //read the analog values from the accelerometer
  int xRead = 300;//analogRead(xPin);
  int yRead = 600;//analogRead(yPin);
  int zRead = 900;//analogRead(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);

  //Caculate 360deg values like so: atan2(-yAng, -zAng)
  //atan2 outputs the value of -π to π (radians)
  //We are then converting the radians to degrees
  x = RAD_TO_DEG * (atan2(-yAng, -zAng) + PI);
  y = RAD_TO_DEG * (atan2(-xAng, -zAng) + PI);
  z = RAD_TO_DEG * (atan2(-yAng, -xAng) + PI);



//printing values
  Serial.print("X: ");
  Serial.print(x);

  Serial.print("  Y: ");
  Serial.print(y);

  Serial.print("  Z:");
  Serial.println(z);


//char sensorArray[] = {x, y, z};
double sensorArray[] = {x, y, z};

  digitalWrite(13, true); // Turn on a light to show transmitting
  //vw_send((uint8_t *)&sensorArray, strlen(sensorArray));
  vw_send((uint8_t *)sensorArray, sizeof(sensorArray));
  vw_wait_tx(); // Wait until the whole message is gon
  delay(50);

}

On the receive you declare the same double sensorArray that you send and copy the buffer into that. That will reconstruct the sent bytes back into the doubles.

#include <VirtualWire.h>

// LED's
int ledPin = 13;

//char sensorArray[10];
//char x;
//char y;
//char z;

double x,y,z;
double sensorArray[3] = {};

const int receive_pin = 11;




void setup() {

  vw_set_rx_pin(receive_pin);

  Serial.begin(9600);

  // sets the digital pin as output
  pinMode(ledPin, OUTPUT);

  // VirtualWire
  // Initialise the IO and ISR
  // Required for DR3100
  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))
  {
    memcpy(sensorArray, buf, buflen);
    //int i;
    // Turn on a light to show received good message
    digitalWrite(13, true);

    // Message with a good checksum received, dump it.
    //for (i = 0; i < buflen; i++)
    //{
      // Fill Sensor1CharMsg Char array with corresponding
      // chars from buffer.
      //sensorArray[i] = char(buf[i]);
     
    //}
   x= sensorArray[0];// == x;
   y= sensorArray[1]; //== y;
   z= sensorArray[2]; //== z;



    // DEBUG
    Serial.print("X: ");
    Serial.println(x);

    Serial.print("Y: ");
    Serial.println(y);

    Serial.print("z: ");
    Serial.println(z);

    // END DEBUG

    // Turn off light to and await next message
    digitalWrite(13, false);
  }
}

THanks man it works.. :D :D