Use of Strings with Arduino causes memory errors and eventually, program crashes. Get rid of them.
To test whether that String-induced errors are responsible for the current problem, write a simple program that just monitors the ADC and prints the result on the serial monitor, without using String objects.
OP's code, posted properly:
#include <Wire.h>
#include <RTClib.h>
#include <SPI.h>
#include <SD.h>
RTC_DS1307 RTC;
#define SELPIN 10 //Selection Pin
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
#define SPICLOCK 13//Clock
#define aref_voltage 5
#define chipSelect 9//CS for Sd card is PB1 or PIN 9
//const int chipSelect = 9; //DIGITAL PIN 9(PB1) AS CHIP SELECT OF SD CARD
float readvalue,voltage0,voltage1,voltage2,voltage3,voltage4,voltage5;
void setup(){
//set pin modes
pinMode(SELPIN, OUTPUT);
pinMode(chipSelect, OUTPUT);
pinMode(DATAOUT, OUTPUT);
pinMode(DATAIN, INPUT);
pinMode(SPICLOCK, OUTPUT);
//pinMode(8,OUTPUT);
//disable device to start with
digitalWrite(SELPIN,HIGH);
digitalWrite(DATAOUT,LOW);
digitalWrite(SPICLOCK,LOW);
Serial.begin(9600);
Wire.begin();
RTC.begin();
// following line sets the RTC to the date & time this sketch was compiled
RTC.adjust(DateTime(__DATE__, __TIME__));
/*
Serial.print("Initializing SD card...");
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect))
{
Serial.println("Card failed, or not present");
// don't do anything more:
while (1);
}
Serial.println("card initialized.");
*/
}
float read_adc(int channel){
int adcvalue = 0;
byte commandbits = B11000000; //command bits - start, mode, chn (3), dont care (3)
//allow channel selection
commandbits|=((channel-1)<<3);
digitalWrite(SELPIN,LOW); //Select adc
// setup bits to be written
for (int i=7; i>=3; i--){
digitalWrite(DATAOUT,commandbits&1<<i);
//cycle clock
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);
}
digitalWrite(SPICLOCK,HIGH); //ignores 2 null bits
digitalWrite(SPICLOCK,LOW);
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);
//read bits from adc
for (int i=11; i>=0; i--){
adcvalue+=digitalRead(DATAIN)<<i;
//cycle clock
digitalWrite(SPICLOCK,HIGH);
digitalWrite(SPICLOCK,LOW);
}
digitalWrite(SELPIN, HIGH); //turn off device
return adcvalue;
}
void(*resetFunc)(void)=0;
void loop() {
DateTime now = RTC.now();
int day = now.day();
int month = now.month();
int year = now.year();
int hour = now.hour();
int minute = now.minute();
int second = now.second();
String slash = "/";
String colon = ":";
String date = day + slash + month + slash + year;
String Time = hour + colon + minute + colon + second;
Serial.println(date);
Serial.println(Time);
readvalue = read_adc(0);
voltage0 = (aref_voltage*readvalue)/4096;
// Serial.println(voltage0);
readvalue = read_adc(1);
voltage1 = (aref_voltage*readvalue)/4096;
// Serial.println(voltage1);
readvalue = read_adc(2);
voltage2 = (aref_voltage*readvalue)/4096;
// Serial.println(voltage2);
readvalue = read_adc(3);
voltage3 = (aref_voltage*readvalue)/4096;
// Serial.println(voltage3);
readvalue = read_adc(4);
voltage4 = (aref_voltage*readvalue)/4096;
//Serial.println(voltage4);
readvalue = read_adc(5);
voltage5 = (aref_voltage*readvalue)/4096;
//Serial.println(voltage5);
// Serial.println(" ");
String dataString ="";
dataString += String(voltage0);
dataString += ",";
dataString += String(voltage1);
dataString += ",";
dataString += String(voltage2);
dataString += ",";
dataString += String(voltage3);
dataString += ",";
dataString += String(voltage4);
dataString += ",";
dataString += String(voltage5);
dataString += ",";
Serial.println(dataString);
SD.begin(chipSelect);
File dataFile = SD.open("FDR.csv", FILE_WRITE);
// if the file is available, write to it:
if (dataFile)
{
dataFile.println(Time);
dataFile.println(date);
dataFile.println(dataString);
dataFile.close();
}
digitalWrite(chipSelect,LOW);
delay(250);
}