Hi guys,
How can i make an Array that can store Integer with multiple Sensor value
I don't have much experience in C Programming
Actually i want to send multiple sensor value through 433Mhz Tx & Rx And you know they are all mixing up in Rx Side
Here is the code for Transmission
#include <VirtualWire.h> //Library for Transmitting data
const int xPin = A1;
const int yPin = A2;
const int zPin = A3;
#define echoPin 7 // Echo Pin
#define trigPin 8 // Trigger Pin
#define LEDPin 13 // Onboard LED
int minVal = 265;
int maxVal = 402;
int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
double x;
double y;
double z;
int distanceData;
int xData;
int yData;
int zData;
char distanceCharMsg[4];
char xCharMsg[4];
char yCharMsg[4];
char zCharMsg[4];
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
vw_setup(2000); //Bits per sec
}
void loop() {
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
// End of ultrasonic sensor
//Start of 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);
Serial.print("distance");
Serial.println(distance);
Serial.print("x");
Serial.println(x);
Serial.print("y");
Serial.println(y);
itoa(distance,distanceCharMsg,10);
itoa(x,xCharMsg,10);
itoa(y,yCharMsg,10);
vw_send((uint8_t *) distanceCharMsg,strlen(distanceCharMsg));
vw_send((uint8_t *) xCharMsg,strlen(xCharMsg));
vw_send((uint8_t *) yCharMsg,strlen(yCharMsg));
vw_wait_tx();
delay (50);
}
and Here is the code for Receiving
#include<VirtualWire.h>
int distanceData;
int xData;
int yData;
int zData;
char distanceCharMsg[4];
char xCharMsg[4];
char yCharMsg[4];
void setup()
{
delay(1000);
Serial.begin(9600); // Debugging only
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
}
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++)
{
distanceCharMsg[i] = char(buf[i]);
Serial.print(' ');
}
distanceCharMsg[buflen] = '\0' ;
xCharMsg[buflen] = '\0' ;
yCharMsg[buflen] = '\0' ;
distanceData = atoi(distanceCharMsg);
xData = atoi(xCharMsg);
yData = atoi(yCharMsg);
Serial.print("distance");
Serial.println(distanceData);
Serial.print("x");
Serial.println(xData);
Serial.print("y");
Serial.println(yData);
}
delay (100);
}
Please help