I have an RF 433 Transmitter and Receiver pair. The transmitter is connected to an Arduino Nano and the Receiver is connected to an Arduino Uno. What is the best code to use to have commands sent from the Nano to the Uno.
The Nano will have four inputs into D2,D3,D4 and D5 (active high) and will output via D13.
The Uno receives via D13.
What code for the Nano would be best to send out commands and what code would be best for the Uno to receive, I have 4 sub procedures set out on the Uno for whichever command is received.
I've been looking for a while now, as I am fairly new to this a lot of it doesn't make sense to me. I was hoping that someone might be able to help me.
Vcc, Gnd are obvious
Antenna needs to have a 173mm wire - maybe yours is already fitted with one
On the emitter connect the data wire to pin 12
On the receiver side connect the data wire to pin 11
install this on the emitter side:
#include <VirtualWire.h>
void setup() {
Serial.begin(115200);
vw_setup(2000);
}
void loop() {
byte message[VW_MAX_MESSAGE_LEN]; // defined in VirtualWire
int messageSize = Serial.readBytesUntil('\n', (char*) message, VW_MAX_MESSAGE_LEN - 1);
if (! messageSize) {
return; // no message
}
message[messageSize] = '\0'; // end the strings
vw_send(message, messageSize + 1); // send the message
vw_wait_tx(); // wait until it's gone
}
On the receiver side install that code:
#include <VirtualWire.h>
void setup() {
Serial.begin(115200);
vw_setup(2000);
vw_rx_start(); // ready to receive
}
void loop() {
byte message[VW_MAX_MESSAGE_LEN];
byte messageSize = VW_MAX_MESSAGE_LEN; // needs to be initialized
// wait for a message
vw_wait_rx();
if (vw_get_message(message, &messageSize)) {
Serial.println((char*) message); // display message
}
}
Now connect both arduinos through USB to your computer, open the IDE console by selecting the port of the emitter. set baud rate to 115200 and set end of line to send '\n'
Open a terminal emulator (coolTerm for example) on the serial port of the receiver and set it to 115200 bauds
start both arduinos
type something in the Arduino IDE Serial console and hit return - you should see it displayed in the coolTerm window