Right now i am able to write into the card. However , when i open the text file, it shows that the information written was written in one long line. I want it to go to the next line after each written data so that i am able to copy and paste into an excel file. Thanks!
#include <SD.h>
#include <SPI.h>
File myFile;
int csPin = 7;
const int voltageinputPIN = A4; //select analog input pin for voltage sensor
const int baudRate = 9600; //sets baud rate in bits per second for serial monitor
const int sensorreadDelay = 2500; //sensor read delay in milliseconds
const int maxanalogValue = 1023; //highest integer given at max input voltage
const int sensormaxVoltage = 25; //highest input voltage of sensor being used
float analogVoltage = 0; //to store voltage value at analog pin
void setup() //setup routine runs once when reset or turned on
{
Serial.begin(baudRate); //initializes serial communication
pinMode(csPin, OUTPUT);
// SD Card Initialization
if (SD.begin())
{
Serial.println("SD card is ready to use.");
}
else
{
Serial.println("SD card initialization failed");
return;
}
}
void loop() //loop routine runs over and over again forever
{
analogVoltage = analogRead(voltageinputPIN);
analogVoltage = (analogVoltage/maxanalogValue)*sensormaxVoltage; //conversion equation
Serial.print(analogVoltage); //prints value to serial monitor
Serial.println("V"); //prints label
myFile = SD.open("test.txt", FILE_WRITE);
if (myFile)
{
myFile.print(analogVoltage);
//myFile.print("V");
myFile.close(); // close the file
delay(5000);
}
// if the file didn't open, print an error:
else
{
Serial.println("error opening test.txt");
}
delay(sensorreadDelay); //delay in milliseconds between read values
}