RF 433MHz issues

Hey everyone,

Currently working on a project where I’ll be using RF to communicate between arduinos. One reciever and two transmitters. Possibly one tx, we will see how it goes. My issue is pretty standard - cant get the RF tx and rx to work. I’m currently trying to get them to turn on an LED before implementing them into my project. Its not going too well. Initially,nothing would work. I’ve been spending more time than I’d of liked on this section but sure isn’t that the joys of arduino :o !

Right now, I have the rx turning on an LED but its very quickly and very dim, not like the tx LED. Also, the on-board ‘rx’ pin lights up with it.

tx - uno board - bright LED for roughly a second.

rx - mega board 2650 - dim LED for roughly half a second.

Both operating from the 5v pin out. RX is plugged into the computer, TX is plugged into a 9v PS.

Using virtual wire library. I’ve tried radiohead but my laptop wont recognise it.

Screenshot (46).png

Screenshot (47).png

Screenshot (48).png

Screenshot (49).png

VIRTUALWIRE_RX.ino (529 Bytes)

VIRTUALWIRE_TX.ino (469 Bytes)

Sorry, I thought the pictures would show up properly.

Here’s my code:

TRANSMITTER:

/*Sarah tx code*/

#include <VirtualWire.h>
char *msg;
int led = 13;
int button  = 2;

void setup()
{
  pinMode(led, OUTPUT);
 /* pinMode(button, INPUT);*/
  
  vw_set_ptt_inverted(true);
  vw_set_tx_pin(12);
  vw_setup(4000);
}

void loop()
{
  msg = "1";
  vw_send((uint8_t *)msg,strlen(msg));
  vw_wait_tx();
  digitalWrite(led, HIGH);
  delay(2000);
  
  msg = "0";
  vw_send((uint8_t *)msg,strlen(msg));
  vw_wait_tx();
  digitalWrite(led, LOW);
  delay(2000);
}

RECIEVER :

/*Sarah rx code*/

#include <VirtualWire.h>
int led = 13;

void setup()
{
  Serial.begin(9600);
  pinMode(led, OUTPUT);
  vw_set_ptt_inverted(true);
  vw_set_rx_pin(12);
  vw_setup(4000);
  
  vw_rx_start();
}

void loop()
{
  digitalWrite(led, LOW);
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  
  if(vw_get_message(buf, &buflen))
  {
    if(buf[0] == '1')
    {
      digitalWrite(led, HIGH);
      Serial.print("Recieved");
    }
  
  if(buf[0] == '0')
  {
    digitalWrite(led,LOW);
  }
 }
}

The first "digitalWrite(led, LOW);" in your receiver "loop code" is going to turn off the LED almost immediately after it has been turned on. I think you want to move that line to the "setup code".

Many thanks Mr Mark, its now working!