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
}
#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
}
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
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.