Receiver write data on sdcard

Hi,

I have a project with this code but isntead of "IR sensor pin" I would like to replace for a XY-MK-5V RX.
When the RX receives a signal he write on sdcard. It is possible?

Thank you for your help

#include <SD.h>  // SD card libray
#include <Wire.h>  // I2C
#include <Time.h>  // Time Manipulation
#include <DS1307RTC.h>  // DS1307 RTC
int irpin = 2;  // IR sensor pin
char timedatebuf[65];  // Time and Date string buffer
int year4digit;  // 4 digit year
void setup()
{
  Serial.begin(9600);  // Serial monitor used for testing
  pinMode (irpin, INPUT);
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
  if (!SD.begin(10)) {  // check if card is installed
    Serial.println("No SD Card present in module");
    return;
  }
  Serial.println("SD Card Ready");
}
void loop()
{
  tmElements_t tm;
  if (digitalRead (irpin) == LOW) // IR detected
  {
    if (RTC.read(tm)) {  // Get Time/Date from RTC1307
      year4digit = tm.Year + 1970;  // 4 digit year variable
      // Format Time & Date string in timedatebuf
      sprintf(timedatebuf, "Time: %02d:%02d:%02d   Date:  %02d/%02d/%02d   ---->INTRUDER DETECTED!!!", tm.Hour, tm.Minute, tm.Second, tm.Day, tm.Month, year4digit);
      File dataFile = SD.open("intruder.txt", FILE_WRITE);  // Open or Create file
      if (dataFile) {  // Check if file exist on SD Card
        dataFile.println(timedatebuf);
        dataFile.close();  // Close file
        Serial.println(timedatebuf);
      }
      else {
        Serial.println("error opening intruder.txt"); // if file not on SD Card
      }
    }
  }
  while (digitalRead (irpin) == LOW) {  // wait until IR is HIGH again
  }
  delay(100); // delay to give time for IR to reset
}

Please use the auto format in the Arduino IDE before posting code. It is very good at correctly indenting code without scrambling it.

I see no reason why your scheme would not work. An analog input may be more appropriate for that radio.

Hi,

This circuit is working. All I need is to print the data when a signal is received by XY-MK-5V Rx

This circuit is working.

If it is, it is because there is some code on the Arduino that can read data from the radio. Where IS that code?

Opening a file on the SD card, writing data to the file, and closing the file is almost trivial. What part are you having problems with?

The code is on the first post:

#include <SD.h>  // SD card libray
#include <Wire.h>  // I2C
#include <Time.h>  // Time Manipulation
#include <DS1307RTC.h>  // DS1307 RTC
int irpin = 2;  // IR sensor pin
char timedatebuf[65];  // Time and Date string buffer
int year4digit;  // 4 digit year
void setup()
{
  Serial.begin(9600);  // Serial monitor used for testing
  pinMode (irpin, INPUT);
  Serial.print("Initializing SD card...");
  pinMode(10, OUTPUT);
  if (!SD.begin(10)) {  // check if card is installed
    Serial.println("No SD Card present in module");
    return;
  }
  Serial.println("SD Card Ready");
}
void loop()
{
  tmElements_t tm;
  if (digitalRead (irpin) == LOW) // IR detected
  {
    if (RTC.read(tm)) {  // Get Time/Date from RTC1307
      year4digit = tm.Year + 1970;  // 4 digit year variable
      // Format Time & Date string in timedatebuf
      sprintf(timedatebuf, "Time: %02d:%02d:%02d   Date:  %02d/%02d/%02d   ---->INTRUDER DETECTED!!!", tm.Hour, tm.Minute, tm.Second, tm.Day, tm.Month, year4digit);
      File dataFile = SD.open("intruder.txt", FILE_WRITE);  // Open or Create file
      if (dataFile) {  // Check if file exist on SD Card
        dataFile.println(timedatebuf);
        dataFile.close();  // Close file
        Serial.println(timedatebuf);
      }
      else {
        Serial.println("error opening intruder.txt"); // if file not on SD Card
      }
    }
  }
  while (digitalRead (irpin) == LOW) {  // wait until IR is HIGH again
  }
  delay(100); // delay to give time for IR to reset
}

The code is on the first post:

That code is, you said, for an IR sensor. That does NOT read data from the radio.

The pir is not activated and I have:

The pir is not activated and I have:

What PIR? The radio is not a PIR.

I have a modified PIR with a FS100A TX to send the signal to a XY-MK-5V RX.
I only need to know when the XY-MK-5V RX receive data from the PIR and write in the SD card the time of the activated PIR

You made a statement:

This circuit is working.

The only way that you can possibly know that it to have code that reads from the radio. If you have such code, you need to post it. If you don't, then you have no idea whether the circuit works, or not.

Try to find an example of using this exact radio and copy that code. The first example I found used an analog pin.