433MHZ turn Relay on and off

Hello,
New to arduino have a project to turn on a motor from a relay over a 433MHZ transmitter receiver. I found a sketch to turn it on and after doing the diagram it works but only turns the relay on. I would like to turn it off by the transmit button or have the receiver reset after 3 seconds. any help is greatly appreciated.

Transmitter Sketch:

#include <VirtualWire.h>
int Button1 = 2;
boolean val ;

void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
pinMode (Button1, INPUT);
vw_set_tx_pin(12);
vw_setup(4000);// speed of data transfer in bps, can max out at 10000
}

void loop()
{
char *senddata="0123456789abcdef";
val = digitalRead (Button1);
if (val == 0){
Serial.print(val);
digitalWrite(13,1);
vw_send((uint8_t *)senddata, strlen(senddata));
vw_wait_tx();
digitalWrite(13,0);
delay(1000);
}
}

Receiver Sketch:
#include <VirtualWire.h>

int Buzzer = 6;
int Relay = 2;

// here i set up the tones, you can change them @ void loop.
int tones[] = {261, 277, 293, 311, 329, 349, 369, 392, 415, 440, 466, 493, 523 ,554};
// 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// You can add more tones but i added 14. Just fill in what tone you would like to use, @ void loop you see " tone(Buzzer, tones[12]); " below, digitalWrite(Buzzer, HIGH);
// here you can change the tones by filling in a number between 1 and 14

void setup()
{
Serial.begin(9600); //we wanna be able to read what we got
vw_set_rx_pin(12);//connect the receiver data pin to pin 12
vw_setup(4000); // speed of data transfer in bps, maxes out at 10000
pinMode(13, OUTPUT);
pinMode (Buzzer, OUTPUT);
pinMode (Relay, OUTPUT);

vw_rx_start(); // Start the receiver PLL running
for (int i = 0; i < Buzzer; i++) ;
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;

if (vw_get_message(buf, &buflen)) // if we get a message that we recognize on this buffer...
{

String out = "";

// we have data coming in, let's aknowledge somehow that we've received it

digitalWrite(Buzzer, HIGH);
digitalWrite(13, HIGH);
tone(Buzzer, tones[2]);
delay(100);
digitalWrite(Buzzer, LOW);
digitalWrite(13, LOW);
noTone(Buzzer);
delay(100);
digitalWrite(Buzzer, HIGH);
digitalWrite(13, HIGH);
tone(Buzzer, tones[14]);
delay(100);
digitalWrite(Buzzer, LOW);
digitalWrite(13, LOW);
noTone(Buzzer);
delay(100);

digitalWrite(Buzzer, HIGH);
digitalWrite(13, HIGH);
tone(Buzzer, tones[2]);
delay(100);
digitalWrite(Buzzer, LOW);
digitalWrite(13, LOW);
noTone(Buzzer);
delay(100);
digitalWrite(Buzzer, HIGH);
digitalWrite(13, HIGH);
tone(Buzzer, tones[14]);
delay(100);
digitalWrite(Buzzer, LOW);
digitalWrite(13, LOW);
noTone(Buzzer);
delay(100);

digitalWrite(Relay, HIGH);
digitalWrite(13, HIGH);

for (int i = 0; i<buflen; i++)
{
out +=(char)buf*; // fill the string with the data received*

  • }*

  • Serial.println(out); // simple enough*
    // digitalWrite(13,0); //transmission ended

  • }*
    }

If you want to turn off the relay after it turns on, you could set a variable such as relay_on to true and set another variable start_on to 0 then compare the current_time to start_on repeatedly until 3 seconds or whatever has elapsed or not.

Please use code tags when posting code.

When learning to use VirtualWire, I strongly recommend to start with the simple example that comes with the library, and understand how that works.

It would be much easier to make that simple example do what you want, than to work through all the bad ideas and useless junk in the receiver sketch you posted.

Yes I know theirs useless junk I'm not using the buzzer or the LED that is in the code But I am a newbie when interfacing hardware with software. all I know is there should be a way of either putting a delay on the relay to reset or just a timer that will reset for the button to be pushed again to turn it off.
I'm willing to learn but need the right direction or example to do other functions with other projects in the future to increase my skills and imagination.

yarb106:
all I know is there should be a way of either putting a delay on the relay to reset or just a timer that will reset for the button to be pushed again to turn it off.

You are going to have to write that code yourself.