Simple logging with time on multiple inputs.

I am looking to log multiple water meters x6. They pulse every 10L used, so a slow pulse of more than 4 secs in between each. The data I am looking for is. TIME with RTC and witch input caused the log. Then to write a line on a csv file on a sd card. I can access all the components individually but bringing all the code together is constantly causing errors.

I'm using a arduino uno r3 with a sd shield that incorporates a DS1307 RTC Chip. All needs to work standalone The data should look like

Time. / pin1/pin2/ pin3/ pin4/ pin5/ pin6/ 1230.23. 0. 0. 1. 0. 0. 0 1230.35. 0. 0. 1. 0. 0. 0 1230.38. 0. 0. 0. 1. 0. 0

And so on..... Thank you for any input Alun

Hi shapesforyou! I don't understand what is your problem. Have you already done anything, or your problem is starting? If you have done anything can you post the code?


Luisilva, I have tried to take bits from the data log example and the RTC example and pin state. It's a mess and probably contributing to the problems I am having, I'm not shore how to get all the bits I need as described previously.

Thank you Alun

Alun, I still don't understand. You are trying to read the csv file and you are not able to do it, or you cant "collect" the right data to write the csv?


I can't collect the data the way I requested. To read it I will just remove the card and read direct from it.

Thank you for your help Alun

In my realtime Arduino to Excel logger, I examine the digital pin state and concatenate a string to represent the state.... Walking pin by pin for each input that interests me. At the end of the collection, I simply output the string, wait 5 seconds, repeat.

String sOut;
//............ Setup() & loop() ............
sOut = "DIGITAL ";
    if (digitalRead(3) == HIGH){
      sOut.concat("3H ");
    } else {
        sOut.concat("3L ");
    if (digitalRead(6) == HIGH){
      sOut.concat("6H ");
    } else {
        sOut.concat("6L ");
    if (digitalRead(7) == HIGH){
      sOut.concat("7H ");
    } else {
        sOut.concat("7L ");

If you need commas in the SDF format, just add them in the .concat function.


Added: of course, you could use a Leonardo to export to the PC in realtime over USB using HID keyboard. The above link contains an Excel document that parses using formulas, no VBA required. Great use of an old XP notebook which is forever stuck in non-upgrade limbo! If you set Excel to auto save, you do not even need the SD card, except maybe audits.

I never work with SD cards, but one way to collect the data is using ‘if’ and then write the result to one string that is the line that you will write to the csv file or use sprintf function or use even other way. BTW, I don’t know if you know about it, csv means ‘comma separated values’, so, any values must be separated by a comma or a semicolon. Something like:

#include <Wire.h>                  
#include <DS1307new.h>
#include <string.h>

int pushButton1 = 50;
int pushButton2 = 48;
int pushButton3 = 46;

void setup() {


  pinMode(pushButton1, INPUT);
  pinMode(pushButton2, INPUT);
  pinMode(pushButton3, INPUT);

void loop() {

  int button1State;
  int button2State;
  int button3State;
  char line[80];

  button1State = digitalRead(pushButton1);
  button2State = digitalRead(pushButton2);
  button3State = digitalRead(pushButton3);

  sprintf(line, "%.2d/%.2d/%.4d; %.2d:%.2d:%.2d; %d; %d; %d;  ",, RTC.month, RTC.year, RTC.hour, RTC.minute, RTC.second, button1State, button2State, button3State);

The code is only one example that is writing to the serial port, but you can adjust this to write to a csv file.