Howe can I get a button to start a RF 433MHz transmitter to send a message?

I have a pair of this cheep 433 mhz transmitter/reciver. I have make a cod so the sending and reciving works good.
I want to make it as a remote control. So when a switch is acivated i vant a message to be sent .
But I can’t figure it out howe to do that.

//Reciver

#include <VirtualWire.h>

#undef int
#undef abs
#undef double
#undef float
#undef round

void setup()
{
  Serial.begin(9600); //debygging endast
  Serial.println("setup");
  vw_set_rx_pin(7);
  vw_setup(2000);
  vw_rx_start();
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;
  if (vw_get_message(buf, &buflen))
  {
    int i;
    digitalWrite(12, true);
    Serial.print("GOT: ");
    for (i = 0; i < buflen; i++)
    {
      Serial.print(buf[i], HEX);
      Serial.print("  ");
    }
    Serial.println(" ");
    digitalWrite(12, false);
  }}
//Transmitter

#include <VirtualWire.h>
#undef int
#undef abs
#undef double
#undef float
#undef round

void setup()
{
  Serial.begin(9600); // debugging endast
  Serial.println("setup");
  vw_set_tx_pin (7);
  vw_setup(2000);
}
void loop()
{
  const char *msg = "Hello";
  digitalWrite(13,true); //tänder Led för att visa sändning
  vw_send((uint8_t *)msg,strlen(msg));
  vw_wait_tx();
  digitalWrite(13, false);
  delay(200);
}

If anyone have a tip to give me i would be glad.

Bertil

Do you really mean remote control or do you mean a wired switch or button ?

Hello

I made a complete tutorial about this kits in my blog

controlrobotics.rodrigomompo.com

If you're kit is already working, you just see Part 4 of the tutorial. In my case I used a jostick for controling a robot car.

Good Luck

Ok I will check your blog.

I mean a wired button.

Thanks

Bertil

I mean a wired button.

How is it wired? Where are you reading the state of the switch? Wiring a button to the Arduino may prove useless. Put the button back on the shirt, and use a switch. Much more reliable.

Router 45 I wounder about this lines in your code

 // Turn on a light to show transmitting
 vw_send((uint8_t *)Sensor1CharMsg, strlen(Sensor1CharMsg));
 vw_wait_tx(); // Wait until the whole message is gone
 // Turn off a light after transmission
 delay(40);

I missing what is the code for tourn on and of the light?

Berti

This is a mistake in the code

the code for turning on the light doesn't exit. Just ignore the coments about the led.

svarven: void loop() {   const char *msg = "Hello";   digitalWrite(13,true); //tänder Led för att visa sändning   vw_send((uint8_t *)msg,strlen(msg));   vw_wait_tx();   digitalWrite(13, false);   delay(200); }

If anyone have a tip to give me i would be glad.

Bertil

Change loop() like this and define the new global variables before setup()

void loop() {
    readButton();
    sendMessage();
}

void readButton() {
   if (digitalRead(buttonPin) == LOW) {
       buttonPressed = true;
   }
}

void sendMessage() {
  if (buttonPressed == false) {
     return;
  }

  const char *msg = "Hello";
  digitalWrite(13,true); //tänder Led för att visa sändning
  vw_send((uint8_t *)msg,strlen(msg));
  vw_wait_tx();
  digitalWrite(13, false);
   buttonPressed = false;
  delay(200);
}

...R