If you have ever wondered how to make 2 arduinos communicates without using expensive shield, here is the solution: there are some RF modules sold for about 2$ (transmitter + receiver) that offer one way, easy-to-use communication with a range of about 150 meters.
In this post I'll explain how to use this modules.
First of all you'll need:
-2 arduinos
-a rf transmitter
-a rf receiver
STEP 1: the transmitter
Connect the transmitter to arduino this way:
Upload this code to the arduino connected to the transmitter:
#include <VirtualWire.h>
void setup(){
vw_setup(2000); // bps
}
void loop(){
send("hello world"); //your message
delay(1000);
}
void send (char *message){
vw_send((uint8_t *)message, strlen(message));
vw_wait_tx();
}
STEP 2: the receiver
Connect the receiver to the arduino this way:
Upload this code to the arduino connected to the receiver:
#include <VirtualWire.h>
byte message[VW_MAX_MESSAGE_LEN];
byte messageLength = VW_MAX_MESSAGE_LEN;
void setup(){
Serial.begin(9600);
Serial.println("Device is ready");
vw_setup(2000); //bps
vw_rx_start();
}
void loop(){
if (vw_get_message(message, &messageLength)){
Serial.print("Received: ");
for (int i = 0; i < messageLength; i++){
Serial.write(message[i]);
}
Serial.println();
}
}
STEP 3: test ;)
Connect the 2 arudino and check with the serial monitor if it works
I hope you like this post, if you have any question please comment or send me an email to damianoandre@gmail.com
Bye, Dami