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);
}
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.
// 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?
{
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);
}