Arduino Uno Interrupt

Hi everyone. I have been trying to use 433 mHZ transmitter and receiver module with my Arduino Uno.
I have only one Arduino, that’s why I don’t have any chance except using interrupts.
I want to light my led when I push the button through RF Receiver and Transmitter.

Here is my code…

#include <VirtualWire.h>

// Variables

const int transmitter = 4;
const int button = 2;
const int led = 8;
const int receiver = 3;
int buttonstatus;
char msgon[1] = {'1'};
char msgoff[1] = {'0'};



void setup(){


    pinMode(led,OUTPUT);
    pinMode(button,INPUT);


    attachInterrupt(0, Transmitter, RISING);
  
  }


void Transmitter() {
   
    vw_set_tx_pin(transmitter);
    vw_set_ptt_inverted(true);
    vw_setup(2000);

  buttonstatus = digitalRead(button);

  if(buttonstatus == HIGH){
      vw_send((uint8_t *)msgon , 1);
      vw_wait_tx();
    }

  else if(buttonstatus == LOW){
      vw_send((uint8_t *)msgoff, 1);
      vw_wait_tx();
    }


  attachInterrupt(0, Receiver, FALLING);  // To Interrupt Receiver
  
  }


void Receiver() {
  
  vw_set_rx_pin(receiver);
  vw_set_ptt_inverted(true);
  vw_setup(2000);
  vw_rx_start();

  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflength = VW_MAX_MESSAGE_LEN;

  if(vw_get_message(buf, &buflength)){

      if(buf[0] == '1') digitalWrite(led, HIGH);
      if(buf[0] == '0') digitalWrite(led, LOW);

    }

  attachInterrupt(0, Transmitter, FALLING);  // To Interrupt Transmitter
  
  }


void loop() {}

But it didn’t work…

Thanks in advance.

Hello,

you are not really helping us help you when you say "it didn't work". It would be helpful to know what symptoms you have. Are you getting Errors? Does it seem to transmit but not receive or vice versa?

Generally speaking, you Need to determine what is working in order to determine what isn't. For example, if you add an LED and put code in the transmit function, does the LED ever go on? If not, the functin isn't being called and that Points you in one direction. If the LED does light, it Points you in another.

Also, tx and rx usually indicate Serial Transmission. Serial Transmission is a timed sequence and usually relies on Interrupts itself to do the Timing. Therefore, usually Serial Transmission can't ever work within an Interrupt routine.

PIC16F84A:
I have only one Arduino, that's why I don't have any chance except using interrupts.

That does not make any sense. Why would having another Arduino make a difference?

Have a look at the demo Several Things at a Time. It does not need interrupts.

You may also find some useful ideas in Serial Input Basics

...R

check the first part of this blog

you don't need two arduinos, just manually set the Transmit to HIGH and use the code they have in step 1 for the arduino.

You'll see you don't need any interrupt or complex set up. When you read analog(A0) you need to experiment a bit to set a high and low threshold that makes sense for your hardware. when the A0 pin gets above the high threshold, you can consider the button is pressed, when it goes below the low you can consider the button has been released

does this help?