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 =( =( =( =( =(