RF 433MHz Transmitter and Receiver on same Arduino

I bought an RF Transmitter and Receiver like these:

But how would I use them on the same arduino, I need this because it is easier to program this way. I only have one arduino, but also an ATTiny85 and there is the other one going to be used for, but using an arduino it is easier to program.

So how could I do this?

    #include <VirtualWire.h>
    
    const uint8_t transmitterPin = 2;
    const uint8_t receiverPin = 12;
    
    void setup()
    {
    	Serial.begin(9600);
    	pinMode(5, OUTPUT);
    
    	vw_set_ptt_inverted(true);
    	vw_set_tx_pin(transmitterPin);
    	vw_set_rx_pin(receiverPin);
    	vw_setup(2000);
    	vw_rx_start();
    }
    
    void loop()
    {
    	uint8_t buf[VW_MAX_MESSAGE_LEN];
    	uint8_t buflen = VW_MAX_MESSAGE_LEN;
    	
    	char* msg = "hey";
    	vw_send((uint8_t*)msg, 3);
    	// vw_wait_tx() we don't use this because then the data maybe is gone already
    	
    	vw_wait_rx();	//Wait for message
    	if (vw_get_message(buf, &buflen)) 
    	{
    		digitalWrite(5, HIGH);
    		delay(400);
    		Serial.print("Got: ");
    
    		for (int i = 0; i < buflen; i++)
    		{
    			Serial.print(buf[i], HEX);
    			Serial.print(' ');
    		}
    		Serial.println();
    		digitalWrite(5, LOW);
    	}
    }

The code you posted does something. You didn't say what. You want the code you posted to do something. You didn't way what.

How are we supposed to help you?

iVision if you do get some code for that running (Both on the one Arduino Uno) - id love to do the same thing! :D i hope it wokrs for you eventually.

I've never seen anyone get a Tx module and a Rx module running on the same Arduino. The data is bitbanged out & received the same way, software serial style. You can't do two things at once - the data is sent; and then the code looks for a message to come back - too late.

Also, take out this line. vw_set_ptt_inverted(true); Very few 433 MHz tx modules have an input pin for this.

PaulS: The code you posted does something. You didn't say what. You want the code you posted to do something. You didn't way what.

How are we supposed to help you?

Uhmm, I thought the code isn't that complex? I mean I just copied a virtual wire examples (transmitter, receiver) and merged them together but still if you want explanation just say it and Ill go through the code line by line.

CrossRoads: I've never seen anyone get a Tx module and a Rx module running on the same Arduino. The data is bitbanged out & received the same way, software serial style. You can't do two things at once - the data is sent; and then the code looks for a message to come back - too late.

Also, take out this line. vw_set_ptt_inverted(true); Very few 433 MHz tx modules have an input pin for this.

Hmm yea that is what I thought, so any ideas how I can manage this? Okay, well it was in almost every example and I didn't really understand its documentation either.

Need to have Tx on one Arduino, and Rx on another Arduino.

Hi!

I have the same needs however with another proposal:

I have two Arduino and I want to put each other send and receive data from RF433 modules (like iVision presented), i.e.:

Arduino 1: - it has code to read sensores and send data(by RF433) to Arduino 2; - it has also 2 digital outputs.

Arduino 2: - it receive data from Arduino 1 (by RF433); - and I want send a signal by RF433 to activate the digital outputs on Arduino 1.

Could some one help me to solve this problem?

Thank you in advance. Best Regards.

How is the receiver on Arduino 1 supposed to distinguish between data it sent and data the other radio sent, when the receiver receives both inputs?

carlos_oliveira_10:
Arduino 1:

  • it has code to read sensores and send data(by RF433) to Arduino 2;
  • it has also 2 digital outputs.

Arduino 2:

  • it receive data from Arduino 1 (by RF433);
  • and I want send a signal by RF433 to activate the digital outputs on Arduino 1.

Could some one help me to solve this problem?

For you it is easy, as you do not want to send and receive at the same time.

Just use two different Arduinos to develop your application: One Arduino as sender, and one Arduino as receiver.

Wenn ready with the programming logic, put the sending/receiving logic all together into one sketch. When using VirtaulWire as a library, the sending Arduino will never receive its own transmission, as the VirtualWire-Library is not able to send and receive at the same time.

But if you really would need a thing that one Arduino receives its own RF transmission, for debugging reasons or what else, it would be easy to develop such code for these cheap RF sender/transmitter pairs.

But you cannot use VirtualWire. You’d have develop your own code that works like this:

Sender logic:
The sender sends its bits from a user function that is blocking the Arduino while sending. So if the transmission lasts 30 milliseconds (for example) or more, the sender will user ON/delay/OFF/delay to push all the bits out to the sender. After 30 milliseconds everything is sent and the rest of the user code is executed.

Receiver logic:
The receiver has set up a hardware CHANGE interrupt on the Arduino: If something is received within the interrupt handler, the bits and bytes are stuffed into a receive buffer. When the receive buffer is complete, it is checked (CRC checksum) and if it is complete and correct, the contents is stuffed into a FIFO buffer. The user code can then later retrieve the data from the FIFO-buffer where the received data are waiting.

This is not rocket science, but it is a little bit more complicated than writing “#include <VirtualWire.h>” into your sketch.

I would finesse the issue completely and get a proper transceiver module such as RFM12B for any node that needs to both send and receive. Apart from anything else you get a guarantee with such a module that the transmitter is definitely OFF when the receiver is listening.

Hi!

Thank you for your answers. I “broke stone” and my mind :slight_smile: to find the best code to solve this situation and I solved my problem. The solution is:

1 - The code to receive and send don’t work at same time (answer to PaulS) so if Arduino 1 send and RF message it isn’t able to receive their own message;
2- I develloped two different functions: one to receive and another to send and it is on void loop().
3- I felt one problem: when Arduino 1 try to receive one RF message it stopped on this line and wait for a long time so I put a timeout to garantee that Arduino 1 continues working without delays.

Here is my code:

void send (char *message)
{
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx(); // Wait until the whole message is gone
}

void receiveRF()
{

vw_rx_start(); //start receive
vw_wait_rx_max(100); //timeout
uint8_t message[VW_MAX_MESSAGE_LEN];
uint8_t msgLength = VW_MAX_MESSAGE_LEN;
if (vw_get_message(message, &messageLength)) // Non-blocking
{
for (int i = 0; i < messageLength; i++)
{
Serial.write(message*);*

  • }*
  • Serial.println();*
  • }*
  • vw_rx_stop(); //stop receive*
    }
    With this information I hope to help everybody that have this needs.

I have just set up this system using the following driver that replaces virtual wire, the ASK examples are what you need.

http://www.airspayce.com/mikem/arduino/RadioHead/