433Mhz Remote Motion Detector Help

Hello, I bought two Arduino Nano boards, which should communicate via 433Mhz. On one Nano a motion detector is connected, the other Nano has an LED. I now have a code that shows me serially whether motion has been detected or not (Source: https://openhomeautomation.net/wireless-motion-sensor-arduino/)
My question is: how can I make the LED on one Arduino light up when the other Arduino detects movement?

// Include VirtualWire library
#include <VirtualWire.h>

// Pins definition
const int led_pin = 13;
const int transmit_pin = 12;
const int receive_pin = 11;

void setup()
{
   // Init
   delay(1000);
   Serial.begin(9600); // Debugging only
   Serial.println("setup");

   // Initialise the IO and ISR
   vw_set_rx_pin(receive_pin);
   vw_setup(2000); // Transmission rate

   // Start the receiver PLL
   vw_rx_start();

   // Set LED pin
   pinMode(led_pin, OUTPUT);
}

void loop()
{
   uint8_t buf[VW_MAX_MESSAGE_LEN];
   uint8_t buflen = VW_MAX_MESSAGE_LEN;

   // Check if a message was received
   if (vw_get_message(buf, &buflen))
   {
   // Flash a light to show received good message
   digitalWrite(led_pin, HIGH);
   Serial.print("Got: ");

   // Print message
   for (int i = 0; i < buflen; i++)
   {
     Serial.print(char(buf[i]));
     Serial.print(' ');
   }
   Serial.println();
   digitalWrite(led_pin, LOW);
   }
}

This is the receiver code. Unfortunately, I’m a beginner, so can someone tell me what I need to change so that the LED lights on the receiver? Many Thanks

What does it do now? Anything printed on Serial monitor?

Steve

Aln_Wlkr:
Hello, I bought two Arduino Nano boards, which should communicate via 433Mhz. On one Nano a motion detector is connected, the other Nano has an LED. I now have a code that shows me serially whether motion has been detected or not (Source: https://openhomeautomation.net/wireless-motion-sensor-arduino/)
My question is: how can I make the LED on one Arduino light up when the other Arduino detects movement?

// Include VirtualWire library

#include <VirtualWire.h>

// Pins definition
const int led_pin = 13;
const int transmit_pin = 12;
const int receive_pin = 11;

void setup()
{
  // Init
  delay(1000);
  Serial.begin(9600); // Debugging only
  Serial.println(“setup”);

// Initialise the IO and ISR
  vw_set_rx_pin(receive_pin);
  vw_setup(2000); // Transmission rate

// Start the receiver PLL
  vw_rx_start();

// Set LED pin
  pinMode(led_pin, OUTPUT);
}

void loop()
{
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;

// Check if a message was received
  if (vw_get_message(buf, &buflen))
  {
  // Flash a light to show received good message
  digitalWrite(led_pin, HIGH);
  Serial.print("Got: ");

// Print message
  for (int i = 0; i < buflen; i++)
  {
    Serial.print(char(buf[i]));
    Serial.print(’ ');
  }
  Serial.println();
  digitalWrite(led_pin, LOW);
  }
}




This is the receiver code. Unfortunately, I'm a beginner, so can someone tell me what I need to change so that the LED lights on the receiver? Many Thanks

Change nothing. Add something when there is no valid message so you can debug. You continue on after the get-message like you will always have a valid message. Obviously that is not the case.

Paul

slipstick: What does it do now? Anything printed on Serial monitor?

Steve

yes right, but I do not really need that, only the LED should shine.

Paul_KD7HB: Change nothing. Add something when there is no valid message so you can debug. You continue on after the get-message like you will always have a valid message. Obviously that is not the case.

Paul

thanks for the tip Sorry, but I'm really a complete dummie in programming. How exactly do I have to do that, as you said?

Aln_Wlkr:
thanks for the tip
Sorry, but I’m really a complete dummie in programming.
How exactly do I have to do that, as you said?

Your code: // Check if a message was received
if (vw_get_message(buf, &buflen))
{
// Flash a light to show received good message
digitalWrite(led_pin, HIGH);
Serial.print("Got: ");

// Print message
for (int i = 0; i < buflen; i++)
{
Serial.print(char(buf*));*

  • Serial.print(’ ');*
  • }*
  • Serial.println();*
  • digitalWrite(led_pin, LOW);*
  • }*
    Assumes the “if(wv_get_message()” is always true.
    Obviously that is not so, to you need to add:
  • // Check if a message was received*
  • if (vw_get_message(buf, &buflen))*
  • {*
  • // Flash a light to show received good message*
  • digitalWrite(led_pin, HIGH);*
  • Serial.print("Got: ");*
  • // Print message*
  • for (int i = 0; i < buflen; i++)*
  • {*
    _ Serial.print(char(buf*));_
    _
    Serial.print(’ ');_
    _
    }_
    _
    Serial.println();_
    digitalWrite(led_pin, LOW);
    _
    }_
    else
    _
    {_
    do something when false
    _
    }*_
    Paul