I found some code written by someone else that I am using with modification, actually minor modification right now. This uses the Virtualwire.h library that lets a simple transmitter and receiver send info via a 433 MHz link. Now I know Virtualwire has been superseded by Radiohead but in this case I don't think it matters which is being used.
I have a breadboard using 2 Pro mini's, 1 for TX and the other for RX. I use 2 laptops with the Arduino IDE on each so the RX and TX modules are separated but not by long distance for now.
I use 2 pots to present varying voltages to simulate sensors using analog ports A0 and A1 on the TX Pro mini. The RX Pro mini is receiving what is being sent as displayed on Serial Monitor window except for 1 item.
TX_ID is set to an integer 3 but when receiving TX_ID is showing a zero. I have tried changing TX_ID to a different number and the RX is seeing that and tells me the ID's don't match (RX_ID is set to 3 also).
I don't know why I am not seeing the TX ID number as sent so I was wondering if someone can point me as to what where and why of this one item.
Here is the code of the transmitter:
#include <VirtualWire.h> // Library Required
int TX_PIN = 11;// Tell Arduino on which pin you would like to Transmit data NOTE should be a PWM Pin
int TX_ID = 3; // Transmitter ID address
typedef struct roverRemoteData// Data Structure
{
int TX_ID; // Initialize a storage place for the outgoing TX ID
int Sensor1Data;// Initialize a storage place for the first integar that you wish to Send
int Sensor2Data;// Initialize a storage place for the Second integar that you wish to Send
int Sensor3Data;// Initialize a storage place for the Third integar that you wish to Send
int Sensor4Data;// Initialize a storage place for the Forth integar that you wish to Send
};
void setup() {
Serial.begin(9600);// Begin Serial port at a Buad speed of 9600bps
vw_setup(2000);// Setup and Begin communication over the radios at 2000bps( MIN Speed is 1000bps MAX 4000bps)
vw_set_tx_pin(TX_PIN);// Set Tx Pin
}
void loop()
{
struct roverRemoteData payload;// In this section is where you would load the data that needs to be sent.
// If you want to read a analog pin and transmit its value you can do it as follows by removing the "//"
payload.TX_ID = TX_ID; // Set the Radio Address
payload.Sensor1Data = analogRead(A0);// analogRead(Sensor1Pin);
payload.Sensor2Data = analogRead(A1);// analogRead(Sensor2Pin);
payload.Sensor3Data =1;// analogRead(Sensor3Pin);
payload.Sensor4Data =1;// analogRead(Sensor4Pin);
vw_send((uint8_t *)&payload, sizeof(payload)); // Send the data
vw_wait_tx();// Wait for all data to be sent
}
Here is the code for the receiver:
[code]
#include <VirtualWire.h> //Library Required
int RX_PIN = 12;// Tell Arduino on which pin you would like to receive data NOTE should be a PWM Pin
int RX_ID = 3;// Recever ID address
int TX_ID;
typedef struct roverRemoteData //Data Structure
{
int TX_ID; // Initialize a storage place for the incoming TX ID
int Sensor1Data;// Initialize a storage place for the first integar that you wish to Receive
int Sensor2Data;// Initialize a storage place for the Second integar that you wish to Receive
int Sensor3Data;// Initialize a storage place for the Third integar that you wish to Receive
int Sensor4Data;// Initialize a storage place for the Forth integar that you wish to Receive
};
void setup() {
Serial.begin(9600);// Begin Serial port at a Buad speed of 9600bps
vw_setup(2000);// Setup and Begin communication over the radios at 2000bps( MIN Speed is 1000bps MAX 4000bps)
vw_set_rx_pin(RX_PIN);// Set RX Pin
vw_rx_start();
}
void loop()
{
struct roverRemoteData receivedData;
uint8_t rcvdSize = sizeof(receivedData);//Incoming data size
vw_wait_rx();// Start to Receive data now
if (vw_get_message((uint8_t *)&receivedData, &rcvdSize)) // Check if data is available
{
if (receivedData.TX_ID == RX_ID) //Check if the radio signal recieved matches the ID of the Reciever
{
// If data was Recieved print it to the serial monitor.
Serial.println("------------------------New MSG-----------------------");
Serial.print("TX ID:");
Serial.println(TX_ID);
Serial.print("Sensor1Data:");
Serial.println(receivedData.Sensor1Data);
Serial.print("Sensor2Data:");
Serial.println(receivedData.Sensor2Data);
Serial.print("SensorData3:");
Serial.println(receivedData.Sensor3Data);
Serial.print("SensorData4:");
Serial.println(receivedData.Sensor4Data);
Serial.println("-----------------------End of MSG--------------------");
}
else
{
Serial.println(" ID Does not match waiting for next transmission ");
}
}
}
Thank you,
Bruce