Arduino fails occasionally to start executing script

Hi all,

Problem described in the title.

I do data logging and it's extremely frustrating when I set everything up for a weekend of measuring and when I come back, I see nothing has been logged. Everything seems to be ok visually (LEDs on). There is nothing indicating that something could be wrong. I know that I should probably add some kind of debugging LED just to see that the script is running, but still I'm a bit bitter.

Anyone else experienced anything similar? Could It be a psu related problem (using regulated 8vdc atm.)? Most of the time everything works fine, but every now and then I get these weird mishaps.

(deleted)

spycatcher2k:
I think its the green wire OR line 74 of your code.

See the issue with your question yet :slight_smile:

So you got your crystal ball back from repair SC...Working great eh !

Sry guys, forgot to post the code.

#include "Wire.h"
#include <RTClib.h>
RTC_DS1307 RTC;

const int chipSelect = 10; // Adafruit 10 - Arduino 4
#include <SPI.h>
#include <SD.h>

int dp_count = 100;
float dp_val = 0;

float val_TMP = 0;

int pin = 2;

int time = 30000;

void setup() {
  
  Wire.begin();
  RTC.begin();
  
  pinMode(10,OUTPUT);
  pinMode(2,OUTPUT);
  
  if (!SD.begin(chipSelect)) {
    return;}
    
  File dataFile = SD.open("data.txt", FILE_WRITE);
    if (dataFile){
      dataFile.close();}
  
  checkStatus();
}

void loop() {
  
  differentialPressure();
  checkStatus();
  delay(500);
  TMP36();
  checkStatus();
  delay(500);
  saveSD();
  delay(500);
  blinkStatus();
  delay(time);
  

}



/////////////////////////////////////////////////////////////////////////
void TMP36(){
  val_TMP = ((analogRead(A1) * 0.004882814) - 0.5) * 100.0;
  }
  
void differentialPressure() {
  dp_val = 0;
  for(int i=0; i<dp_count; i++){
    dp_val = dp_val + analogRead(A0);
    delay(5);}
  dp_val = dp_val / dp_count;}
  
void checkStatus(){
   float starttime = millis();
   while ((millis()-starttime) < 1500){
    digitalWrite(pin, HIGH);
    delay(20);
    digitalWrite(pin, LOW);
    delay(20);}
  }
  
void blinkStatus(){
  for (int i=0; i<3; i++){
    digitalWrite(pin, HIGH);
    delay(800);
    digitalWrite(pin, LOW);
    delay(800);}
  }
  
void saveSD(){
  DateTime now = RTC.now();  
  File data = SD.open("data.txt", FILE_WRITE);
  if (data){
    data.print(now.month(), DEC);
    data.print('/');
    data.print(now.day(), DEC);
    data.print('/');
    data.print(now.year(), DEC);
    data.print(' ');
    data.print(now.hour(), DEC);
    data.print(':');
    data.print(now.minute(), DEC);
    data.print(':');
    data.print(now.second(), DEC);
    data.print(" ");
    data.print("\t"); 
    data.print(dp_val);
    data.print("\t");
    data.println(val_TMP);    
    data.close();}
  }

I’m a bit sceptical that the problem is in the code. As I said, everything works fine at lab. All wiring has been tested and proved also.

E: btw. can a long delay() (i.e. >5min) have a negative impact on reliability?

Just a note:
You might want to rethink not using comments in your sketches.
Stop using delay()s they stop every thing for that time.
Put { and } on a line by themselves.