☀ How to Build an Arduino Data Logger ☀ About Us A data logger is a device that records sensor information at regular intervals over a period of time so that information can be examined later for an understanding of phenomenon that are hard to observe directly.
Now that we’ve got all that downloaded and installed, let’s start with the Arduino part.
Here’s a basic template I created that will display the time in column A and your sensor measurements in column B.
Of course, this is just a basic template, which is pretty straight forward and you can tweak it to suit your needs.
![Arduino serial data logger software Arduino serial data logger software](https://circuit.rocks/image/cache/product/AC039/data-logger-shield-for-arduino-a23428-500x500.jpg)
- ☀ How to Build an Arduino Data Logger ☀ A data logger is a device that records sensor information at regular intervals over a period of time so that information can be examined later for an understanding of phenomenon that are hard to observe directly.
- This Arduino project shows how to build a temperature data logger using SD card, DS18B20 digital temperature sensor and DS3231 real time clock board. The Arduino reads temperature from the DS18B20 sensor and saves them (with date and time) to a text file stored on the SD card. The DS3231 real time clock chip is used to get time and date.
- Addendum 2017-02-20: This post is the second in a series of online tutorials that I've been developing to help teachers bootstrap their own Arduino based curriculum. The full set are listed at How to Build an Arduino Data Logger which walks you through the most recent versions in a more or less logical progression.
I’ve added explanations in the Arduino code so you (and I, after not working with it for a while) know which part of the code does what.
Here’s the sketch:
//always starts in line 0 and writes the thing written next to LABEL
void setup() {
Serial.begin(9600); // the bigger number the better
Serial.println('CLEARDATA'); //clears up any data left from previous projects
Serial.println('LABEL,Acolumn,Bcolumn,..'); //always write LABEL, so excel knows the next things will be the names of the columns (instead of Acolumn you could write Time for instance)
Serial.println('RESETTIMER'); //resets timer to 0
}
void loop() {
Serial.print('DATA,TIME,TIMER,'); //writes the time in the first column A and the time since the measurements started in column B
Serial.print(Adata);
Serial.print(Bdata);
Serial.println(..); //be sure to add println to the last command so it knows to go into the next row on the second run
Play yahtzee free unlimited. delay(100); //add a delay
}
Obviously if you upload this code, it won’t work on it’s own!
You need to add a formula for Adata, Bdata and … . This template is just for reference so you know how to use the program. Just add Serial.read() function, name it Adata, Bdata and … and it should work.
Using the SD library to log data
This example shows how to use the SD card Library to log data from three analog sensors to a SD card. Please click here for more information on the SD library.
Hardware Required
- Arduino or Genuino board
- Ethernet Shield (or other board with an SD slot)
- 3 10k ohm potentiometers
- hook-up wires
- breadboard
- Formatted SD card
![Logger Logger](/uploads/1/2/4/8/124858009/987827363.jpg)
Circuit
image developed using Fritzing. For more circuit examples, see the Fritzing project page Windows autostart disable.
The Arduino or Genuino board has to be connected to the Ethernet Shield. The three potentiometers may be substituted with other analog sensors, to be wired according to their interfacing techniques.
Schematics
image developed using Fritzing. For more circuit examples, see the Fritzing project page
Code
Microsoft autorun download. The code below is configured for use with an Ethernet shield, which has an onboard SD slot. In the
setup()
, call SD.begin()
, naming pin 4 as the CS pin. This pin varies depending on the make of shield or board.Arduino Serial Data Logging
In the
loop()
, a String is created to hold the information from three analog sensors. The code iterates through the sensors, adding their data to the string.Next, the file on the SD card is opened by calling
SD.open()
. Once available, the data is written to the card when dataFile.println()
is used. The file must be closed with dataFile.close()
to save the information./*
SD card datalogger
This example shows how to log data from three analog sensors
to an SD card using the SD library.
The circuit:
analog sensors on analog ins 0, 1, and 2
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created 24 Nov 2010
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
const int chipSelect =4;
voidsetup(){
// Open serial communications and wait for port to open:
Serial.begin(9600);
while(!Serial){
;// wait for serial port to connect. Needed for native USB port only
}
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.');
}
voidloop(){
// 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');
}
}
SD card datalogger
This example shows how to log data from three analog sensors
to an SD card using the SD library.
The circuit:
analog sensors on analog ins 0, 1, and 2
SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN)
created 24 Nov 2010
modified 9 Apr 2012
by Tom Igoe
This example code is in the public domain.
*/
#include <SPI.h>
#include <SD.h>
const int chipSelect =4;
voidsetup(){
// Open serial communications and wait for port to open:
Serial.begin(9600);
while(!Serial){
;// wait for serial port to connect. Needed for native USB port only
}
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.');
}
voidloop(){
// 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');
}
}
See Also
- SD library - Your reference for the SD Card library.
- Notes on using SD cards – What you need to know when you use SD cards
Openlog Serial Data Logger Arduino
- CardInfo - Get info about your SD card.
- DumpFile - How to read a file from the SD card.
- Files - How to create and destroy an SD card file.
- Listfiles - How print out the files in a directory on a SD card.
- ReadWrite - How to read and write data to and from an SD card.
Arduino Sd Logger
Last revision 2015/08/17 by SM