Ayuda con Base de Datos!!

Buenos dias a todos!!

Estoy haciendo un base de datos y tengo un problema. Hice un programa para leer los datos de varios sensores, que es el siguiente:

int sensorTPV = A0;
int sensorVPV = A1;
int sensorIPV = A2;

int tiempo=0;
float valorTPV = 0;
float valorVPV = 0;
float valorIPV = 0;

void setup(){
Serial.begin(9600);
}

void loop(){
tiempo =(millis()/1000)+1;
valorTPV = analogRead(sensorTPV);
valorTPV = (5.0 * valorTPV)/1024.0;
valorVPV = analogRead(sensorVPV);
valorVPV = (5.0 * valorVPV)/1024.0;
valorIPV = analogRead(sensorIPV);
valorIPV = (5.0 * valorIPV)/1024.0;
Serial.print (tiempo);
Serial.print (" TPV = ");
Serial.print (valorTPV,8);
Serial.print (" VPV = ");
Serial.print (valorVPV,8);
Serial.print (" IPV = ");
Serial.print (valorVPV,8);
Serial.print (" ");
Serial.println ();
delay(10000);
}

El problema es el siguiente: Ahora le e puesto una tarjeta SD para que guarde los datos y he sacado el programa de los ejemplos y no se como unirlos para que haga el programa que yo quiero y guarde los datos en la tarjeta. El programa para que lea la SD es la siguiente:

#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;

void setup()
{
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

Serial.print("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
pinMode(53, OUTPUT);

// 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:
return;
}
Serial.println("card initialized.");
}

void loop()
{
// make a string for assembling the data to log:
String dataString = "";

// read three sensors and append to the string:
for (int analogPin = 0; analogPin < 3; analogPin++) {
int sensor = analogRead(analogPin);
dataString += String(sensor);
if (analogPin < 2) {
dataString += ",";
}
}

// 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 = SD.open("datalog.txt", FILE_WRITE);

// if the file is available, write to it:
if (dataFile) {
dataFile.println(dataString);
dataFile.close();
// print to the serial port too:
Serial.println(dataString);
}
// if the file isn't open, pop up an error:
else {
Serial.println("error opening datalog.txt");
}
}

Gracias de antemano!!

No lo he probado pero sería algo así.

#include <SD.h>

// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
const int chipSelect = 4;

int sensorTPV = A0;
int sensorVPV = A1;
int sensorIPV = A2;

int tiempo=0;
float valorTPV = 0;
float valorVPV = 0;
float valorIPV = 0;

void setup(){
  Serial.begin(9600);
 Serial.print("Initializing SD card...");
  // make sure that the default chip select pin is set to
  // output, even if you don't use it:
  pinMode(53, OUTPUT);  //-------------Aquí debes cambiarlo si es necesario
  
  // 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:
    return;
  }
  Serial.println("card initialized.");
}

void loop(){
  tiempo =(millis()/1000)+1;
  valorTPV = analogRead(sensorTPV);
  valorTPV = (5.0 * valorTPV)/1024.0;
  valorVPV = analogRead(sensorVPV);
  valorVPV = (5.0 * valorVPV)/1024.0;
  valorIPV = analogRead(sensorIPV);
  valorIPV = (5.0 * valorIPV)/1024.0;
  Serial.print (tiempo);        
  Serial.print ("  TPV = ");
  Serial.print (valorTPV,8); 
  Serial.print ("    VPV = ");
  Serial.print (valorVPV,8);
  Serial.print ("    IPV = ");
  Serial.print (valorVPV,8);
  Serial.print (" ");
  Serial.println ();

  // 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 = SD.open("datalog.txt", FILE_WRITE);

  // if the file is available, write to it:
  if (dataFile) {
  dataFile.print (tiempo);        
  dataFile.print ("  TPV = ");
  dataFile.print (valorTPV,8); 
  dataFile.print ("    VPV = ");
  dataFile.print (valorVPV,8);
  dataFile.print ("    IPV = ");
  dataFile.print (valorVPV,8);
  dataFile.print (" ");
  dataFile.println ();
  dataFile.close();
    // print to the serial port too:
    
  }  
  // if the file isn't open, pop up an error:
  else {
    Serial.println("error opening datalog.txt");
  } 
  delay(10000);
}

Deberás adecuar los pines que conectan la tarjeta a tu diseño.

muchas gracias!!