«

»

Jan 16

Print this Post

Data logging con Arduino

Yesterday I gave free rein to the imagination and knowledge of Arduino and I mounted my castle to build a data logging shield for Arduino

data logging shield

The project itself is not complex less than familiar with some concepts such as I2C and SPI, In fact, I decided to use a SD Card shield to write my data to an SD Card 64Gb, more than sufficient for some online log in a text file, and a RTC to keep time of acquisition of the log.

Proceed in order starting from the material needed for the project data logging with Arduino:

  • 1 Arduino Uno
  • 1 RTC Shield or another based on DS1307 RTC
  • n.1 SD Card shield
  • n.5 pulsanti n.a. ( normally open )
  • # 5 330ohm resistors
  • n.1 breadboard
  • some cable for connections

Called the material you need to keep in mind that the RTC used as the communication protocol I2C Bus ie the SDA pin ( pin A4 ) e SCL ( pin A5 ) Arduino, Shield few have the opportunity to use the 2 additional pins SDA and SCl present on the Arduino Uno R3, However, these pins are connected, level arduino, ai medesimi pings ed A4 A5, for which the corresponding Analog Inputs are still useable.

The scield SD Card uses the SPI bus consists of the pins:

D13 SD_CLK
D12 SD_OUT
D11 SD_IN
D10 SD_CS

In addition to 3.3v and Gnd, some SD card used as the CS pin pin 4, is the case of the official Ethernet Shield Arduino that in addition to the pins 13,12,11 use the pin 4 come CS.

The circuit data logging with Arduino

To connect the Arduino shield, you should not use it if, as I did, the shield stackable to create your data logging, the only connections to be done regarding the 5 buttons that are connected as always through a pull-down ( verso Gnd ) da 330ohm.

I received 4 buttons you use them to simulate the variation of data on the inputs A0, A1, A2 and A3 and the fifth button will use it to tell the sketch you want to reload the file and read this on the SD Card, I call it READ button, here is a picture of the buttons

data logging

and one of the connections to the analog inputs

data logging valori analogici

while the fifth button ( Read ) You need to connect it to the pin 9 of data logging with arduino

data logging read

Operation of the data logging

The data logging with Arduino is an experiment I decided to use the 4 buttons to simulate the change of values ​​detected by the ADC ( analog to digital converter ) Arduino, consider that each value converted by the ADC sull'Arduino One can vary from 0 a 1023 ( 10bit ) and will 0 when the button is not pressed through a 1023 when you press one of the buttons.

The data logging simultaneously write to the log file and the monitor serial data collected from 4 analog pin in addition to the date and time at which the data was collected.

You can replace each of the 4 buttons with the sensor you see fit, I have deliberately used the analog inputs to allow you to be able to detect 1024 signal levels from each pin, if I had used the digital pins I could only detect the passage was from LOW to HIGH and vice versa.

Important!

You can not use pins A4 and A5 as they are used for communication I2C bus RTC shield.

Download sketch del data logging

You can download the sketch and the RTC library that I used for this project directly from GitHub.

Lo sketch some data logging

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib

#include <Wire.h>
#include "RTClib.h"
#include <SD.h>

#define readButton 9
#define CS 10

RTC_DS1307 RTC;
char buffer[40];

File myFile;

void setup () {
    Serial.begin(57600);
    Serial.print("Initializing SD card...");
    pinMode(CS, OUTPUT);
    pinMode(readButton, INPUT);

    if (!SD.begin(CS)) {
      Serial.println("initialization failed!");
      return;
    }
    Serial.println("initialization done.");

    Wire.begin();
    RTC.begin();
    RTC.sqw(1);		//0 Led off - 1 Freq 1Hz - 2 Freq 4096kHz - 3 Freq 8192kHz - 4 Freq 32768kHz
    hyphae (! RTC.isrunning()) {
      Serial.println("RTC is NOT running!");
      // following line sets the RTC to the date & time this sketch was compiled
      RTC.adjust(DateTime(__DATE__, __TIME__));
    }
}

void loop () {
    DateTime now = RTC.now();

    sprintf(buffer,  "%02d/d/%d d:%02d:%02d %d %d %d %d", now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second(), analogRead( A0 ), analogRead( A1 ), analogRead( A2 ), analogRead( A3 ) );
    Serial.println( buffer );

    myFile = SD.open("dati.log", FILE_WRITE);
    if (myFile) {
      myFile.println(buffer);
      myFile.close();
    } else {
      Serial.println("error opening dati.log");
    }

    if ( digitalRead( readButton ) == HIGH ) {
        Serial.println(" ");
        Serial.println("Reading Log Saved ----------- ");
        Serial.println(" ");
        myFile = SD.open("dati.log");
        if (myFile) {
          while (myFile.available()) {
    	    Serial.write(myFile.read());
          }
          myFile.close();
        }
        delay( 5000 );
    }

    delay(1000);
}

the sketch of the data logging includes both classes needed to communicate with the RTC as well as those for using the SD Card shield:

lines 03-04: Include the class and the class Wire RTC to communicate with the DS1307 through the I2C protocol;

line 05: Include the class to read and write to the SD Card with SD SPI protocol;

lines 07-08: define in which pins you have connected the button you will use to re-read the log data logging and the CS pin of your SD Card uses;

line 10: initializes the object RTC;

line 11: define a buffer in which to memorize the time and the detected values. To calculate the length of the buffer, you can count the maximum number of characters that can contain, know that the date is formed by 10 characters ( gg/mm/aaaa ) the e ora da 8 characters ( hh:mm:ss ) and that between the two there is a space, then you know that each value will be separated by a space so you can read them easily and that the maximum value recorded on each pin is 1023 ( 4 characters ) for which the calculation is: 10 + 1 + 8 + 1 + 4 + 1 + 4 + 1 + 4 + 1 +4 = 39 for which you can define the buffer to 40 ( Whereas a margin of 1 value )

lines 16-17: sets the communication to the serial monitor 57600 baud and write the string to the serial monitor “Inizializing SD card …”

lines 18-19: sets the mode of operation for the CS pin and the pin connected to the button reading ( pin 9 );

lines 21-24: initializes the object with the SD method begin and passing the value of the pin CS, if it fails to initialize the SD Card write on the serial monitor “Initialization failed” and exits the setup function using the command return;

lines 27-34: initializes the object and Wire RTC, tax 1 according to the flashing frequency of the SQW LEDs present on the RTC Shield and in the case of time not configured sets the current time of the RTC Pc, for the procedure read the article Tutorial: RTC Shield con DS1307;

line 38: sets an instance of type DateTime as RTC.now();

line 40: compose the line buffer using the command sprintf( buffer, format, VAL1, VAL2 ….valn ) in which the buffer is the variable in which to store the entire string, The format is that of the command C sprintf ( you see manual ), and successive values ​​are the ones you want to buffer;

line 41: write the serial monitor the value of buffer;

line 43: Open the file in write mode “dati.log” on the SD Card data logging

lines 44-46: if the file pointer dati.log there, ie if you are able to open communication with the SD card inserted in the SD Card Shield write the string buffer and close the file;

lines 47-49: in case of failure to open the file dati.log write the string to the serial monitor “error opening dati.log”;

line 51: checks that the value measured on pin buttonRead both HIGH means that the button is connected to this pin is pressed;

lines 52-54: write a blank line on the serial monitor, la stringa “Reading Log Saved ————–” and an additional blank line, only serves to separate the lines written by the normal operation of those read from the SD Card data logging;

line 55: open the file dati.log in reading mode, In fact, you did not specify any parameters as the second argument of the method open;

lines 56-61: If the file has been successfully opened read line by line the log file and write the result of each line on the serial monitor;

line 62: set a delay from 5 seconds ( 5000 milliseconds ) before returning to normal operation log;

line 65: sets a delay of 1 second in a series of the function loop() and the following.

The video data logging with the Arduino

In order to show how the data logging that you just realized you can watch the video that I made in my testing with data logging:

Buon Log !!!

Important!


Kindly DO NOT paste sketch in the comments, Use the info box of the blog that you can find on the contact page.

Warning!


The sketch is distributed free of charge and without any liability.
Reading this article and decided to use the sketch brought you assume all responsibility.

Important!


You have been helpful this article?
Support me by clicking on sponsors, I will be able to continue to acquire material to write articles and help you in your projects.

Just one click a day.

Be Sociable, Share!

Related posts

Permanent link to this article: http://www.mauroalfieri.it/elettronica/data-logging-with-arduino.html

61 comments

7 pings

Skip to comment form

  1. Jay

    Great demo. How would you recommend uploading this data to an FTP site so that it could be graphed in a web page?

    1. Mauro Alfieri

      Thank you,
      i suggest you use an Ethernet connection.

      Mauro

  2. Enrico

    Kudos to the tutorial, reading it you gave me the inspiration and would like to make a one r3 arduino data logging with recording data (text strings) coming through serial rs232 to a GPS and a depth sounder on the sd card.
    By connecting the GPS (baudrate 9600) and the sounding (baudrate 4800) to the serial port of the PC with hyperterminal I see the text strings.
    For now I am recording the data with a laptop and a data logging software but rather, as a matter of size and portability, use a solution with arduino.
    Do you think that using the shield Assembled Adafruit Data Logging and two Serial Interface RS232-TTL 3-5,5V be able easily or will I need a different hardware configuration?

    Enrico

    1. Mauro Alfieri

      Hello Henry,
      thanks for the compliments.
      The shield Assembled Adafruit Data Logging has an internal shield both the SD Card is the RTC, might be a good solution, I never tried because I do not own one and I can not tell if it's easier or more difficult to achieve the DataLogging.

      You know that Arduino has one serial port, and that already use to load the sketch, Surely you can use it for the data logger when it is separated from the computer, two 2 Serial-to-read, at different speed, you can try simulating the serial with the library SoftwareSerial.h (you can find tutorials on the blog ) or use an Arduino Mega which has 4 independent serial.

      Mauro

  3. rise

    i want generate arduino data logging based bar code scanner. do have a link?

    1. Mauro Alfieri

      Do not, I do not have links to suggest

      Mauro

  4. Paul Furley

    Neat project and great write-up, thanks for the detail. I imagine this could be quite a disruptive application as commercial data loggers don’t come cheap. Might be fun to do a radiation level logger with the Geiger counter shield :)

    Paul

    1. Mauro Alfieri

      Hi Paul,
      you can try a project if you have a counter Gaiger available.

      Mauro

  5. Danny

    Please check line 50. Seems incorrect. Should be:

    if(digitalRead(readButton) == HIGH){

    Good tutorial. Appreciate that you are sharing with us.

    Thanks!

    1. Mauro Alfieri

      Thanks for your report, I see no difference between line.

      Mauro

  6. Francesco

    Hello,

    Thanks to your information I was able to assemble the various components such as LCD, RTC, SD module and temperature sensors. It works to perfection, but I wanted to make a change to the data logger, I would like the file with the recorded data is created every day with a different name, maybe with the day's date of registration (is. 03_05_2013.txt). Can you kindly help me out?
    Thank you
    Francesco

    1. Mauro Alfieri

      Hello Francesco,
      is a modification of some’ challenging but not impossible.
      You can work with the narrows and set a different file name for each day.

      Remember to check that the file exists before writing the values, this arrangement prevents the passage of midnight the new file is not present so you should always check that the file exists and you want to write to create it in case there is already

      Mauro

  7. MRSS

    Hi there,
    I would like to know your recommendation (since I am very new to Arduino), if I want to log some data, say it I sample it every 1 sec, and when it reaches 60 sec, it will average the 60 data, and log it to the SD card for every 1minute, how am I going to do that? I am very confuse now.

    I manage to log the data every sec. It means in my SD card, every sec of data has been logged. But the problem is now, I only want to log data for every 1 min after averaged all the 60 sec data. Meaning that in my SD card only has data for every 1 minute. Do you understand me? Thank you in advance for your quick response. I am very looking forward for it. Thank you!

    1. Mauro Alfieri

      hello najwa,
      i understand your project.
      You store values ​​into a variable 60 times per minute and average:

      for( int i=0;i<=60;i++) {
      int val=analogRead( your_pin );
      valTotal = val;
      delay( 1000 );
      }
      valTotal = ( valTotal / 60 );

      then write valTotal to the SD card.

      Mauro

      1. MRSS

        thank you mauro!
        now i got the idea! thanks!

        Mrss

  8. Apprentice

    Salve,
    recently i am using arduino. My intention was to use the RFID technology. I bought one r3 arduino, a reader ID20 of innovations and OpenLog the SparkFun. I managed to run the RFID reader with Arduino, I therefore write to the serial ID read from the reader.
    Now I switched to the second block of my little project: I want to transfer this data to openlog in order to save on microsd. I have read the tips SparkFun, but I still can not store the data that I want.
    Since I am a beginner could you give me some help?
    Thank you
    Hello

    1. Mauro Alfieri

      Hello Apprentice,
      Your project is interesting.
      Your name is not Apprentice, that's right?

      I do not know that you're using the OpenLog, I usually use in my rejection of the normal SD card, However, I read the Wiki Sparkfun and it seems to me that the work on the serial communication simulated thanks to SoftSerial.h with commands sent via Serial.println( command );

      What a mistake by you?

      Mauro

      1. Apprentice

        Hello Mauro,
        Thank you for having responded. I was able to run these days OpenLog with Arduino to write on serial command Serial.println(). Use OpenLog first in listening mode and then in command mode to write on microSD. My problem now is figure out how to send the data from the reader to OpenLog. I do not understand a thing: agrees that memorize the data outgoing from the player before the memory dell'Atmega and then pitch them on OpenLog, or I can directly record to OpenLog defining the Arduino pin? Sorry if the question may seem stupid, but I am stuck here and I do not know how to continue.
        Thank you for your help

        1. Mauro Alfieri

          Hello Apprentice,
          I'd love to know your real name .. it's weird to contact a passionate / a with a pseudonym.
          Your questions are not stupid at all, Unfortunately I have never tried the shield OpenLog why I rely only on reading the description of the manufacturer.
          To decide which mode it is necessary to write you assess the sampling time, ie the interval between one value and the next you want to store and the time of writing on OpenLog.

          For example, if you need to write on OpenLog 1 and second samples 100 milliseconds with an interval of 10 seconds each 100 readings you should certainly use an array to 100 locations to store the data every 100 milliseconds and write OpenLog only once in the break 10 seconds.

          Mauro

          1. Apprentice

            Hello Mauro,
            I tried to record with OpenLog: There are successful, I'd rather just do one thing if I can.
            The reader sends via serial to the Arduino tag that reads; I would like to be able to save such an ID in RAM dell'ATmega. I only saw arduino tutorial on writing and reading EEPROM. The problem is that I can write one cell at a time and I would like to write the entire ID? Do you have any advice? I thought of two pointers one for the ID code and one to scroll the cells of the EEPROM: too cumbersome… You can not write on the ram?

            Thank you,

            Paola

          2. Mauro Alfieri

            Hello Paola,
            I published an article on the management of EEPROM written by a fan and shared with all.
            It is important for you to know the size of the ID domain in terms of numerical, you will understand by reading the article.

            Mauro

        2. Apprentice

          I just saw you yesterday published a tutorial, Thank you :-), I see a little bit of hacking . let you know if I have problems.

          1. Mauro Alfieri

            Very well.

            Mauro

          2. Apprentice

            Hello Mauro,
            ho a problem with the EEPROM. I'll explain what I want to do.
            I saw how you store the ID on EEPROM.Se except for a number n of ID,
            how can I print all? I have to use a pointer to get the block in all cells stored and printed?

            Thank you,
            Paola

          3. Mauro Alfieri

            Hello Paola,
            Yes it is, I would do a loop that reads the cells and prints it on another monitor or a serial communication channel that is convenient you.

            Mauro

          4. Apprentice

            Hello Mauro,
            I have resolved to do everything I can now.
            Thanks for the help and the availability
            Hello
            Paola

  9. Jon Persson

    Hi,

    Interesting and inspiring project! How is it with energy consumption for this datalogger. I’m looking for a solution that can work autonomous for at least weeks without out needing a huge battery, and logg signals on minute basis.

    //Jon

    1. Mauro Alfieri

      Hello Jon,
      the power consumption depends on the sensor and the frequency of writing on the card, every minute is a good engagement of energy.
      You can measure the current consumed by your project after assembly and determine the type of power source required.

      Mauro

  10. Paul

    Hello Mauro, I can confirm that the sketch of the example works well with the microSdCard of’ Ethernet Shield (replacing the CS pin from 10 the 4, however, indicate how you) e l’ RTC DS1307 … I had errors all'SdCard using file names greater than 8 characters , I confirm that this limit? … suspected to have arrived at the limit of RAM because adding or removing only the 'Serial.print’ I have the success / non-success of the writing on sdcard , sometimes appear even strange characters or the sketch restarts independently, etc.… … can be a problem of employment RAM? There is a simple way to be able to verify?

    1. Paul

      … I was able to read the occupation in RAM memory using the command 'avr-size.exe’ , mi dà :

      Program : 22402 bytes
      Data : 1796 bytes

      If I'm not mistaken the limits of 'Atmega328 Arduino UNO are 32 kB di Flash (Program) and 2 kB of RAM (Data) … considering that during the execution of the program the occupation of Ram salt, I seem to be on the verge of Ram and perhaps have explained so many different errors and occasional program …

      can actually be so? how would you rate the comando'avr-size.exe '?

      1. Mauro Alfieri

        Hello Paul,
        carry-over concerns that the data flash memory arduino, then that which resides on the sketch compiled.
        32K = 32768 Bytes that if you subtract the 2048 Bytes ( 2K ) get 30720 Bytes.
        These dimensions are the same as that in the IDE Arduino should read at the end of a compilation.

        Mauro

    2. Mauro Alfieri

      Hello Paul,
      the limit on the length of names to 8 character is due to the fact that you have formatted the SD Card in FAT, This filesystem has a limit of which I speak. Try the Fat32 arduino.cc indicates that the site as supported by the library SD.
      By removing the Serial.print from your sketch you decrease the size occupied by the sketch once filled, let's talk about that in flash memory arduino one is 32K, has no influence on the development of the sketch.

      Mauro

      1. Paul

        … I just reformatted (in fast mode) gives the MicroSD Card 4 GB in FAT32 con 32 kilobytes of allocation units and, using a sketch base for writing to sdcard (so as to avoid any problems of memory), writing works well until the eighth character of the filename, from the ninth character on the writing fails … anyway thanks, for the moment rest under the 8 characters, and I can tell better formatting

        To be fair I am giving you the link to the site from which I have drawn information on the memory of Arduino :

        http://www.leonardomiliani.com/2012/come-sapere-loccupazione-di-ram-del-proprio-sketch/

        I do not know the author and see if tù then delete this link … it is from this article that I am convinced of the possibility that only a few Serial.print can lead to saturate the RAM …

        Thanks dela availability …

        1. Mauro Alfieri

          Hello Paul,
          supports the FAT32 file whose name is longer than the 8 characters, could be a limit of the library SDFat.
          The link you sent me is a very good programmer and passionate arduino, Leonardo Milani, with whom I exchanged some emails a few months ago and of which I have great respect.

          His article, I read carefully, specifies that the command avr-size.exe deals to give you an assessment of the occupation of Flash evaluating the file compiled by the IDE Arduino.
          To get a true assessment of the RAM used at run-time ( ie while it's running sketch ) you should use the method suggested by Leonardo MemoryFree.

          Mauro

          1. Paul

            ok, the upper limit of 8 characters of the file should be a limit library, I currently use the SD.h

            I tried the method MemoryFree and effectively to a value of 450 (suppongo Bytes) the file is successfully opened the sdcard, Serial.print add some plain text, and the value drops to 350 continuing to successfully open the file, but when I add another couple of Serial.print and the value of MemoryFree drops below 300 I get an error opening the file to SD … At this point I really think are the Serial.print that I occupy the Ram up to disallow opening the file … I'll be more thrifty with Serial.print and indeed I will evaluate whether to move in flash memory …

            Thanks again Mauro

          2. Mauro Alfieri

            Great Paul, Your analysis is very detailed, and the library MemoryFree seems good for these tests.

            Mauro

  11. Nicola

    Salve Mauro.
    Following the instructions in this guide His excellent ono succeeded in measuring the values ​​of temperature and humidity and save the data on a SD.
    the upgrade I want to do is to carry out such measurements not every few seconds, with the wait command,
    but will automatically, for example, at the stroke of each hour.
    Could you please suggest me how to proceed?

    1. Mauro Alfieri

      Hello Nicola,
      the idea is very cute, I invite you to read the articles on sentralina irrigation which has similar concepts.
      Compared to your need, the irrigation control triggers a relay to a date now set, you do not need to do is write to the SD Card instead of exciting a relay.

      Mauro

      1. Nicola

        Salve.
        First of all, thank you very much for the prompt reply.
        But it perplessità: the example of the unit is great, but I see it more suitable for those activities that require some adjustment, because you can easily change the intervals of operation.
        In my case, instead, should establish 24 intervals, every hour of the day, am I right?
        Can not quite, with more comfort, to use a command like the wait,
        but that is not influenced by the time of reading and writing data?

  12. carmine

    hello,
    I tried your code but the sprintf (riga 41-42-43) does not work.
    To you it works ?

    1. Mauro Alfieri

      Hello Carmine,
      I text all my sketch before publishing, there may be an error to copy and paste that I missed or that replication is bad code to video, that error will be?

      Mauro

  13. daniel

    hello mauro,
    I found the following code to store the date and time using the ethernet shield WITHOUT RTC.
    but this sketch as you will see on the door using the protocolloUDPNTP 8888, but the project on which I will have to implement it instead uses port 80.
    I should put my project in what is using the port 8888?
    this is the code:

    /*

    Udp NTP Client

    Get the time from a Network Time Protocol (NTP) time server
    Demonstrates use of UDP sendPacket and ReceivePacket
    For more on NTP time servers and the messages needed to communicate with them,
    see http://en.wikipedia.org/wiki/Network_Time_Protocol

    Warning: NTP Servers are subject to temporary failure or IP address change.
    Plese check

    http://tf.nist.gov/tf-cgi/servers.cgi

    if the time server used in the example didn't work.

    created 4 Sep 2010
    by Michael Margolis
    modified 9 Apr 2012
    by Tom Igoe

    This code is in the public domain.

    */

    #include
    #include
    #include

    // Enter a MAC address for your controller below.
    // Newer Ethernet shields have a MAC address printed on a sticker on the shield
    byte mac[] = {
    0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

    unsigned int localPort = 8888; // local port to listen for UDP packets

    IPAddress timeServer(132, 163, 4, 101); // time-a.timefreq.bldrdoc.gov NTP server
    // IPAddress timeServer(132, 163, 4, 102); // time-b.timefreq.bldrdoc.gov NTP server
    // IPAddress timeServer(132, 163, 4, 103); // time-c.timefreq.bldrdoc.gov NTP server

    const int NTP_PACKET_SIZE= 48; // NTP time stamp is in the first 48 bytes of the message

    byte packetBuffer[ NTP_PACKET_SIZE]; //buffer to hold incoming and outgoing packets

    // A UDP instance to let us send and receive packets over UDP
    EthernetUDP Udp;

    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
    }

    // start Ethernet and UDP
    if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    for(;;)
    ;
    }
    Udp.begin(localPort);
    }

    void loop()
    {
    sendNTPpacket(timeServer); // send an NTP packet to a time server

    // wait to see if a reply is available
    delay(1000);
    if ( Udp.parsePacket() ) {
    // We've received a packet, read the data from it
    Udp.read(packetBuffer,NTP_PACKET_SIZE); // read the packet into the buffer

    //the timestamp starts at byte 40 of the received packet and is four bytes,
    // or two words, long. First, esxtract the two words:

    unsigned long highWord = word(packetBuffer[40], packetBuffer[41]);
    unsigned long lowWord = word(packetBuffer[42], packetBuffer[43]);
    // combine the four bytes (two words) into a long integer
    // this is NTP time (seconds since Jan 1 1900):
    unsigned long secsSince1900 = highWord << 16 | lowWord;
    Serial.print("Seconds since Jan 1 1900 = " );
    Serial.println(secsSince1900);

    // now convert NTP time into everyday time:
    Serial.print("Unix time = ");
    // Unix time starts on Jan 1 1970. In seconds, that's 2208988800:
    const unsigned long seventyYears = 2208988800UL;
    // subtract seventy years:
    unsigned long epoch = secsSince1900 - seventyYears;
    // print Unix time:
    Serial.println(epoch);

    // print the hour, minute and second:
    Serial.print("The UTC time is "); // UTC is the time at Greenwich Meridian (GMT)
    Serial.print((epoch % 86400L) / 3600); // print the hour (86400 equals secs per day)
    Serial.print(':');
    if ( ((epoch % 3600) / 60) < 10 ) {
    // In the first 10 minutes of each hour, we'll want a leading '0'
    Serial.print('0');
    }
    Serial.print((epoch % 3600) / 60); // print the minute (3600 equals secs per minute)
    Serial.print(':');
    if ( (epoch % 60) < 10 ) {
    // In the first 10 seconds of each minute, we'll want a leading '0'
    Serial.print('0');
    }
    Serial.println(epoch %60); // print the second
    }
    // wait ten seconds before asking for the time again
    delay(10000);
    }

    // send an NTP request to the time server at the given address
    unsigned long sendNTPpacket(IPAddress& address)
    {
    // set all bytes in the buffer to 0
    memset(packetBuffer, 0, NTP_PACKET_SIZE);
    // Initialize values needed to form NTP request
    // (see URL above for details on the packets)
    packetBuffer[0] = 0b11100011; // LI, Version, Mode
    packetBuffer[1] = 0; // Stratum, or type of clock
    packetBuffer[2] = 6; // Polling Interval
    packetBuffer[3] = 0xEC; // Peer Clock Precision
    // 8 bytes of zero for Root Delay & Root Dispersion
    packetBuffer[12] = 49;
    packetBuffer[13] = 0x4E;
    packetBuffer[14] = 49;
    packetBuffer[15] = 52;

    // all NTP fields have been given values, now
    // you can send a packet requesting a timestamp:
    Udp.beginPacket(address, 123); //NTP requests are to port 123
    Udp.write(packetBuffer,NTP_PACKET_SIZE);
    Udp.endPacket();
    }

    1. Mauro Alfieri

      Ciao Daniel,
      maybe you did not read the end of each article of mine is not shown because it arrives paste code unreadable.

      For your project, in addition to, I do not know how to help you because I did not understand what you want to achieve, because they do not want to use a RTC and what does the recovery time will Anto with the door 80 with whom I do not know what you want us.

      I suggest you write to the author of the sketch that you can certainly clarify what is his sketch and that this solution presents limitations.

      Mauro

  14. daniel

    sorry to have not read :D no, however I wanted to see the time in my client but I do not have the RTC and I've read that the code allows you to use the time with only the use of the ethernet shield

    1. Mauro Alfieri

      The Daniel,
      this method, as far as I can read and I hope you understand, using an NTP server to synchronize the time.

      Mauro

  15. David

    Salve,

    but a datalogger of this type can I use it to monitor a photovoltaic system with a 14kW inverter brand AURORA? E’ You can have a guide to get started with Arduino and understand things I have to buy to put into practice all that written in the tutorial?

    Thank you very much

    David

    1. Mauro Alfieri

      Hello David,
      a data logger measures and records everything you tell him to measure.
      These days I have published a comprehensive article on a datalogger capable of measuring temperature and umiditò that is for sale on the site robot-domestici.it, if you order it ask the new vesion :-)

      For the photovoltaic system are not shod but if you can find the probes compatible with arduino you can undoubtedly use this project to your datalogging.

      If you want a step by step guide for arduino I suggest you read my free online course or attend one of the courses in the classroom.

      Mauro

  16. gianni

    Hello Mauro,

    in your code de wanted to append to a string buffer to be saved in order to have as well as data from sensors even a text string

    20/04/2014 00:24:33 15 15 16 15 59 40 38 99 Relay1 ON – Relay2 OFF

    I tried:

    sprintf(buffer, “%02d/d/%d d:%02d:%02d %d %d %d %d %d %d %d %d “, now.day(), now.month(), now.year(), now.hour(), now.minute(), now.second(), Tmedia, t1, t2, t3, Hmedia, h1, h2, h3 );
    textlog = buffer + info;

    but a row writes correctly but the other adds some strange characters and sometimes rather not write anything.

    Thank you

    1. Mauro Alfieri

      Hello Gianni,
      to add the other info you need to enter in the sprintf(…) adding both the correct pointer% d,%s ( depends on what you'd like to add ) and at the end of your string parameters.
      In other articles are used as the command you need, alternatively you can check the syntax of the command sprintf() roll a su Arduino reference a manual C.

      1. gianni

        Thanks Mauro,

        I had already tried other methods, what you say is to add

        sprintf(buffer, “%02d ……,%s”, now.day(),………, info)

        but I get this error:

        warning: format ‘%s’ expects argument of type ‘char*’, but argument 17 has type ‘String’ [-Wformat]

        I also tried

        if (myFile) {
        myFile.print(buffer);
        myfile.println(info);
        myFile.close();
        }

        but writes strange characters at the end of the line on the SD file or does not write anything

        1. Mauro Alfieri

          Hello Gianni,
          the first method is the one I would use.
          If you use the% s your text must be of type char that is, between “” and not between ”

          1. gianni

            so if I have to pass text between “” but I want to pass a String, do you have any solution?

            Thank you

          2. Mauro Alfieri

            Hello Gianni,
            check the manual sprintf if there is an option to pass a String or convert String to char.

          3. gianni

            Hello Mauro,
            I do not understand why it is becoming so difficult, I thought it was a trivial, and what's more I can not even work around the problem, Cmq so I also returns error

            String info;
            char was[100];

            info.toCharArray(you have, 100);
            sprintf(buffer, “d ……,%s”, now.day(),………, info);

            I no longer have any idea.

          4. Mauro Alfieri

            Hello Gianni,
            eye seems to me the wrong conversion from String to char.
            Try to follow one of my articles.

            It remains unknown why you want to pass a String, not a char.

          5. gianni

            excuse does not return error…….. just do not write anything

            while if the mold you see everything on the serial……grrrrrrrrrrrrrrr

          6. Mauro Alfieri

            Hello Gianni, see previous answer.

          7. gianni

            Mauro Thanks for your patience :-)

            the fact that I want to pass an object of type String is because they can not build the message with char, is:

            String info=””;
            if (Analog.read(A0) < 20) info = " Relay 1 ON";
            if (Analog.read(A1) < 10) info = " Relay 2 ON";
            ……………………

            I can not do this with Char

          8. Mauro Alfieri

            Hello Gianni,
            try to read this article: http://www.mauroalfieri.it/elettronica/tutorial-arduino-e-le-stringhe.html

            Mauro

  17. stefano

    hello
    I wanted to know if you can read the log file, to make graphs with Excel, directly, without removing the SD arduino

    Thank you

    1. Mauro Alfieri

      Hello Stefano, if you want you can do it.
      You must write one or more functions at the touch of a button or receiving u serial command to read the file and I will send to your computer via serial or other method of sending.

  1. Arduino Blog » Blog Archive » Data-logging made simple with Arduino

    [...] translate ideas into physical artifact, as practically demonstrated by Mauro, which shows on his blog how to build a simple data-logger by properly combining different shields. By using few additional [...]

  2. Data-logging made simple with Arduino | Linux-Support.com

    [...] translate ideas into physical artifact, as practically demonstrated by Mauro, which shows on his blog how to build a simple data-logger by properly combining different shields. By using few additional [...]

  3. Revue de presse - 28 January 2013 |

    [...] complete description of a datalogger based on Arduino. It is rare to see such a stack of shields! The program, simple, allows [...]

  4. Arduino project where to start - Mauro Alfieri Electronics Robotics

    [...] and his blink you'll probably need at least a shield arduino, an example is the datalogger to make it happen you need, in addition to arduino, la RTC shield e la SD shield. The same goes for a [...]

  5. Arduino temperature humidity data logger - Mauro Alfieri Home Automation Robot

    […] two projects that you can read on this blog Datalogging with Arduino DHT11 sensor and can carry out the project: Arduino datalogger and temperaura […]

  6. Data-logging made simple with Arduino -Use Arduino for Projects

    […] translate ideas into physical artifact, as practically demonstrated by Mauro, which shows on his blog how to build a simple data-logger by properly combining different […]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>