ARDUINO UNO + RTC I2C + Ethernet SHIELD W5100 + Radio Receiver 433MHz DI3

Dear all,
I have an arduino UNO with a shield of ethernet w5100 HanRun, RTC cloc DSs3231 and ordinary Radio receiver 433Mhz. The transmitter unit is a nano with a 433 transmitter. In the ethernet shield I put a micro sd card where I want to write 4 sensors data with timestamp. I have tested the programs piece by piece and they work. But when I add them all, I have most of the time error opening datalog.txt (the file from the card), sometimes I have the value, but never writed in the card.
I have noticed that when I don’t power the transmitter, I always have the error opening datalog.txt.

It looks like the receiver does not receive/synchronise the data. I have attached the error in the serial monitor.
Do you have any clue for this?

Thank you.


I post here the codes:


#include <VirtualWire.h>
#include <VirtualWire_Config.h>
int Sensor1Pin = A1;// The pins were sensor are attached
int Sensor2Pin = A2;
int Sensor3Pin = A3;
int Sensor4Pin = A4;
int ledPin = 13;
int Sensor1Data;// The variable were the data from each sensor
int Sensor2Data;// will be stored
int Sensor3Data;
int Sensor4Data;
char Sensor1CharMsg[21];// The string that we are going to send trought rf

void setup() {

// LED

// Sensor(s)

// VirtualWire setup
// vw_set_ptt_inverted(true); //
vw_set_tx_pin(4);// Set the Tx pin. Default is 12
vw_setup(2000); // Bits per sec


void loop() {

// Read and store Sensor Data
Sensor1Data = analogRead(Sensor1Pin);
Sensor2Data = analogRead(Sensor2Pin);
Sensor3Data = analogRead(Sensor3Pin);
Sensor4Data = analogRead(Sensor4Pin);

sprintf(Sensor1CharMsg, “%d,%d,%d,%d,”, Sensor1Data, Sensor2Data, Sensor3Data, Sensor4Data);

// 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



//HARDWARE: ARDUINO UNO + RTC I2C + Ethernet SHIELD W5100 + Radio Receiver 433MHz DI3

#include <DS3231.h>
#include <SPI.h>
#include <SD.h>
#include <VirtualWire.h>
#include <VirtualWire_Config.h>
const int chipSelect = 4;
// Sensors
int Sensor1Data;
int Sensor2Data;
int Sensor3Data;
int Sensor4Data;

char StringReceived[22];

// Init the DS3231 using the hardware interface
DS3231 rtc(SDA, SCL);

void setup()
// Initialize the rtc object
// The following lines can be uncommented to set the date and time
// rtc.setDOW(THURSDAY); // Set Day-of-Week to SUNDAY
// rtc.setTime(10, 6, 30); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(5, 10, 2017); // Set the date to January 1st, 2014
// initialize serial communication at 9600 bits per second:
Serial.print(“Initializing SD card…”);
// see if the card is present and can be initialized:
if (!SD.begin(4))
Serial.println(“Card failed, or not present”);
// don’t do anything more:
Serial.println(“card initialized.”);
//initialize Radio communication
// Bits per sec
// Start the receiver PLL running

void loop()
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
//Taking the data from the control base
if (vw_get_message(buf, &buflen))
int i;
// Message with a good checksum received, dump it.
for (i = 0; i < buflen; i++)
// Fill Sensor1CharMsg Char array with corresponding chars from buffer.
StringReceived = char(buf*);*
* }*
* sscanf(StringReceived, “%d,%d,%d,%d,%d,%d”,&Sensor1Data, &Sensor2Data,&Sensor3Data,&Sensor4Data); // Converts a string to an array*
* Serial.println(Sensor1Data);*
* //Serial.println(Sensor2Data);*
* //Serial.println(Sensor3Data);*
* //Serial.println(Sensor4Data); *
* }*
* memset( StringReceived, 0, sizeof( StringReceived));// This line is for reset the StringReceived*
* // Disable Ethernet by setting chip select high.*
* // digitalWrite(10, HIGH); *
* // pinMode(10, OUTPUT);*
* // initialize SD here*

// open the file. note that only one file can be open at a time,
* // so you have to close this one before opening another.*

* File dataFile =“datalog.txt”, FILE_WRITE);
// if the file is available, write to it:_
if (dataFile) {_
// dataFile.print(",");_
// dataFile.print(x,2);_
// print to the serial port too:_
// Serial.println(x);_
// if the file isn’t open, pop up an error:_
else {
Serial.println(“error opening datalog.txt”);_