Hc 12 and sd card module not working together

Hello everyone,

I have two hc 12 module connected to different arduino boards, for transmitting and receiving data. In case any communication loss, an sd card module is connected with the transmitter arduino. But now, it is not sending any data to the receiver, and also unable to store the data in the sd card.

When i made them work seperately, both of them works fine. I don't know what's the problem here.
There is no error in the connections..
I have gone through many sites and articles but found nothing...

Any help would be great..
Thank you..

Don't you think that we might need more information like your code and possibly your wiring diagram (photo of a handdrawn one is fine).

Before posting code, please read How to use this forum - please read. - Installation & Troubleshooting - Arduino Forum (and post specific attention to point #7).

Sorry for delay....

sd_data_logging_ckt.pdf (365 KB)

sd_card_data_logging.ino (2.56 KB)

Receiver_all.ino (430 Bytes)

U can find the code and ckt info above

For the transmitter code, it sends data for the first 10 sec and then stops the communication. Now, it have to store the data inside the sd card (till the end).

For the receiver code it just accepts all the data sent by the transmitter and shows on serial terminal.

Note in advance, I don't have a straight answer. So below some things that I notice.

I would add more debug statements (print to serial monitor) and at a far higher baudrate that the 4800.

In the transmitter code

  if (k == 2) {

I can't find where you declared k.

Guessing that that has to be key, the below repeatedly opens the file (without closing it).

  if (k == 2) {
    myFile = SD.open("alldata.txt", FILE_WRITE);

The file will only be closed if your millis() timing exceeds the 5 milliseconds.

  if (k == 2) {
    myFile = SD.open("alldata.txt", FILE_WRITE);
    if (myFile) {
      if (millis() - timer > 5) {
        ...
        ...
        Serial.println("ok");
        myFile.close();
      }

Repeatedly opening a file without closing it is a recipe for problems with the writing to the card. What possibly saves you here is that your print of "time: " takes more than 5 milliseconds so you might have been lucky.

I would change the sequence

  if (millis() - timer > 5) {
    if (k == 2) {
      myFile = SD.open("alldata.txt", FILE_WRITE);
      if (myFile) {
        ...
        ...
        Serial.println("ok");
        myFile.close();
      }

Further be aware that at 4800 baud, transferring on byte over serial will take 2 milliseconds. With the amount of characters that you print, your millis() based timing seems quite useless.