I'm am building an RC Tank. I'm using two MKR 1000 boards. I've got a 433 MHz Transmitter and Receiver modules. I found some code that is incomplete can anybody help me get it to work so that I can transmit data?
Transmitter Code
// oddWires: this is a simple exmaple that shows the 433Mhz module working. It sends a simple message to the receiver
#include
void setup()
{
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for RF Link module
vw_set_tx_pin(10); // pin 10 is used as the transmit data out to the TX Link module,
// change this to suit your needs.
}
void loop()
{
rfSend("this is a test");
delay(5000);
}
void rfSend(String message)
{
char output[100];
message.toCharArray(output, 99);
vw_setup(2000);
vw_send((uint8_t *)output, strlen(output));
vw_wait_tx(); // Wait for message to finish
vw_setup(40);
}
Receiver Code
// oddWires: this is a simple example that shows the 433Mhz module working. It receives simple message from the transmitter
#include
#define rxPin 2
const int ledPin = 13; // the number of the LED pin
int ledState = LOW; // ledState used to set the LED
long onMillis = 0; // will store last time LED was updated
void setup()
{
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
// Initialise the IO and ISR
vw_set_ptt_inverted(true); // Required for RX Link Module
vw_setup(2000); // Bits per sec
vw_set_rx_pin(rxPin); // We will be receiving on pin 2 ie the RX pin from the module connects to this pin.
vw_rx_start(); // Start the receiver
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // check to see if anything has been received
{
int i;
// Message with a good checksum received.
for (i = 0; i < buflen; i++)
{
Serial.print((char)buf*); // print the received data stored in buffer to the serial monitor*
- }*
- Serial.println(" ");*
- digitalWrite(ledPin, HIGH);*
- onMillis = millis();*
- }*
- if (millis() - onMillis > 100 && onMillis > 0)*
- {*
- onMillis = 0;*
- digitalWrite(ledPin, LOW);*
- }*
}