Today I took a $3 433 MHz transmitter / receiver pair, and sent a string of characters 20′ from one Arduino to another. This could be useful for weather sensors, security alarms or remote control, etc.
There are only 3 wires to connect on each unit, 5v, Gnd, and Data (spelled ATAD on the smaller board, which is the transmitter). Add a 13cm wire to transmitter ANT connection for greater range.
You will need two Arduino boards, 6 jumpers, and 2 solderless breadboards for this project.
A 4 AA battery pack or a 9v for the transmitter Arduino will make it wireless, the receiver will be plugged into your computer. Alternatively, the Transmitter could be plugged into another computer or a USB charger for power. We are using our LiPo battery shield.
Become the Maker you were born to be. Try Arduino Academy for FREE!
Download and install the Virtual Wire (VirtualWire.zip) library (we have slightly customized the sketches found at this site, so try ours found below first, they are much more satisfactory).
Connect the smaller transmitter board to one Arduino, using +5v, Gnd, and “ATAD” to Arduino pin 11.
Connect the larger receiver board to the second Arduino, using +5v (VCC), GND, and either of the 2 DATA pins to Arduino pin 11.
When the code below is uploaded to the appropriate Arduino, you should see the following in the RX Arduino serial monitor:
Upload the following sketch to the TX Arduino:
#include <VirtualWire.h>
const int led_pin = 13;
const int transmit_pin = 11;
const int receive_pin = 2;
const int transmit_en_pin = 3;
void setup()
{
// Initialise the IO and ISR
vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
vw_set_ptt_pin(transmit_en_pin);
vw_set_ptt_inverted(true); // Required for DR3100
vw_setup(2000); // Bits per sec
}
byte count = 1;
void loop()
{
char msg[7] = {‘h’,‘e’,‘l’,‘l’,‘o’,‘ ‘,‘#’};
msg[6] = count;
digitalWrite(led_pin, HIGH); // Flash a light to show transmitting
vw_send((uint8_t *)msg, 7);
vw_wait_tx(); // Wait until the whole message is gone
digitalWrite(led_pin, LOW);
delay(1000);
count = count + 1;
}
Upload the following sketch to the RX Arduino
#include <VirtualWire.h>
const int led_pin = 13;
const int transmit_pin = 12;
const int receive_pin = 11;
const int transmit_en_pin = 3;
void setup()
{
delay(1000);
Serial.begin(9600); // Debugging only
Serial.println(“setup”);
// Initialise the IO and ISR
vw_set_tx_pin(transmit_pin);
vw_set_rx_pin(receive_pin);
vw_set_ptt_pin(transmit_en_pin);
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;
digitalWrite(led_pin, HIGH); // Flash a light to show received good message
// Message with a good checksum received, print it.
Serial.print(“Got: “);
for (i = 0; i < buflen -2; i++)
{
//Serial.print(buf[i], HEX);
Serial.write(buf[i]);
//Serial.print(‘ ‘);
}
Serial.println();
digitalWrite(led_pin, LOW);
}
}
Become the Maker you were born to be. Try Arduino Academy for FREE!