Data Logger

$10 Data-logger using Arduino Micro-controller

A data-logger is a valuable tool needed by anyone wanting to do experimentation. The automated collection of data reveals far more than manual observations alone tend to provide.  In this configuration, not only can data be automatically collected, sequences of events can be planned and implemented automatically.

Enclosed: All the Arduino data-logger code, parts list, and vendor information; followed by video tutorials that lead 15 activities.

What is the significance of coding?

The economics of learning to teach yourself coding:

Protect your Brain and Build Relationships of Mutual Respect

What is a Data-logger

A data-logger is an instrument that records signal levels from sensors to record what happens without a human needing to be present.  Examples include:

  • Long duration changes that make being present impractical, such as monitoring the change in temperature (house, vehicle, body during exercise…) every 5 minutes for a week and then analyzing what actually happens versus what we perceive.
  • Short duration changes where events happen too quickly to record manually, such as monitoring static voltage build up on a metal surface during a rocket launch, the different lap times during a race as contestants cross the finish line at almost the same time, and other short time intervals.
  • Monitoring changes in hazardous conditions like the pressure and temperature at a deep place under the ocean, or near an active volcano…

The enclosed data-logger is self-contained and is small enough to launch in a large hobby type Estes Rocket called the Leviathan or other 3″ diameter rocket with a G80 rocket engine.  The rocket with payload will go out of sight, so adjust for the wind so the rocket returns closer to but adjacent to the launch site (compensating for parachute drift). This provides the students with the opportunity to repeatedly conceive, model, design, build, implement, test, and analyze projects in teams of three. Students design a rocket sensor experiment and cardboard mount for the Arduino, launch the rocket, analyze results, suggest improvements.  These are practiced core skills that engineers and scientists get paid to do from day to day. NASA provides some funding to schools who desire to participate in a NASA launch program. Teachers can also request to participate in a program where teachers, parents, students, and clubs develop local business connections to fund the course materials of math and science teachers, and develop local internships for eligible students.

The same Data-logger Payload can be built and launched in robotic land based vehicles.

As an example, if monitoring a single signal like pressure ten times a second, a 1 Gbyte SD card could record continuously for about 3.17 years; so an 8 Gbyte x 3.17 years/1 Gbyte = about 25 years.  If you are monitoring 10 data points, the Arduino takes time to process the extra points, so if the maximum speed is 10 samples per second (arbitrary numbers used here for simplification), it will take one second per set of data, and the same number of years of recording are available, but sampling the data set is 10 times slower.  So there is no need to worry about when to start recording.  The data is output in a form compatible with importing into Excel spreadsheets.  The trick is finding where the useful information begins and ends.  Having the process start and stop collection, creating a spike to flag the beginning and end so they can be searched for …

1 billion samples/1 Gbyte SD Card x sec/10 samples x hour/3600 sec x day/24 hours x year/365 days =

years/1 Gbyte SD Card = 3.17 years

The SIPI Mars Yard is a program that provides High School students in science and math courses with actual robots in a simulated Mars Environment where the students can manipulate the robots from their classroom; in a manner very similar to how NASA controls the actual Mars Rovers.  Practiced experience in learning to code the Arduino, provides logical tools to learn how to program the robots.  Additionally, students can design mechanisms (sensors, grippers, laser tag actuators, sample systems …) with Arduino controllers in their classroom, or in a school robotics & rocketry club, that will be mounted on the actual Mars Yard Rovers.  This allows students to test their designs in a somewhat realistic Mars environment, and also to participate in competitions with other schools in games like laser tag, hide and seek, geo caching, duplicating actual Mars missions…

Other areas of interest like chemistry, environmental science, and even auto mechanics, can use the Arduino to design and build most automation needs to make possible the relatively complex interactions and/or manipulation over long times.  The Arduino should not be considered for use in an industrial application because it is not “hardened” against electrical noise, power spikes from large motors and relay induction surges in voltage, high humidity, conductive dirt, corrosive gases, and other industry specific equipment hazards.  For industrial applications, use an industry hardened Programmable Logic Controller (PLC).  The coding is similar and provides a much more durable solution.  The Arduino is 1/10th the cost, but is only for research, education, or non-commercial purposes (home alarm system, lawn sprinklers, rain capture and use, vehicle bling lights …).

Scientists and Engineers often use similar tools like a data-logger to perform their activities more effectively. Like the data-logger as a physical tool, “coding software” is similarly a common computing tool used.  Coding provides a means of telling a computing system the who, what, when, where, why, and how, associated with signals, data, and actuators to be manipulated, to provide useful results not otherwise easily attainable.

For instance, a $5 Arduino and an LED driver can sense a turn signal switch in a car, and then flash 10 LED lights in complex patterns to grab the attention of the driver behind them.  With a little experience in coding, this can be programmed in less than 30 minutes with multiple patterns to choose from.  To make a mechanical or relay system to do the same effort would be bulky, less reliable, would take longer to install, would cost more, and the sequence of LEDs turning on and off could not be selected or changed as easily.

The same skills learned to teach yourself coding to produce projects using an Arduino, can be used with additional “persistence” to produce Apps for a cell phone (example: a home automation system, remote laboratory apparatus monitor/controller, start and stop your car remotely …).

The same skills learned to teach yourself coding to produce physical projects, and Mars Missions, can be used to teach yourself Career Planning so that you can realistically predict the best path and choose your support network.  The purpose of career planning is to create a step-by-step procedure to follow, obtain an interesting career, that has real local opportunities, that pays well, and that can support your local community.  By 8th grade each student and their parents should start career planning, because selecting useful classes is important as stepping stones for getting practice in identifying problems, planning choices of solutions, and solving problems.

Learn to Efficiently Teach Yourself

Build a Career Pathway

Building Self-Respect

Learning to Teach Common Sense

Arduino Parts List

Note:  If your Arduino Uno data-logger works fine on USB power, but fails when on battery or external power, change the value of R12 from 1k to 10k.  A known feedback condition may be corrupting the initialization process.  Schematic

Parts Required:

  • Arduino UNO
  • Update (3/10/2016) Complete Data-logger Arduino Shield now available
    • The coding is a little different, but is overall a more easily implemented solution
    • Where to Buy (about $3)
      • Sample Code
      • SD Card sample datasheet 
      • Real time clock (RTC) keeps the time going even when the Arduino is unplugged. The battery backup lasts for years.
      • For some data-loggers sold on eBay, they include libraries and example code for both SD and RTC.  This means you can get running quickly. Prototyping area for soldered connectors, circuitry, or sensors.
      • Works with Arduino UNO, Duemilanove, Diecimila, Leonardo or ADK/Mega R3 or higher.  ADK/Mega R2 or lower are not supported.
      • Size:68x53x23mm(approx)
  • 9v Battery & Arduino connectors
    • Arduino takes 5.5 mm outside / 2.1 mm inside barrel connector
    • The other end depends upon individual applications
    • Where to Buy Arduino Power Connector
    • Where to Buy 9v Battery Clips and parts
  • USB programming cable (comes with many Arduino purchases)
  • Whatever sensors/actuators selected
  • Book:  “Make: Sensors: A Hands-On Primer for Monitoring the Real World with Arduino and Raspberry Pi”

______ Once you have the data-logger hardware built _______


As instructors, you can choose whether to teach coding, just assemble the data-logger and use the provided code, or some combination.

Recommendation if teaching coding: teach how to set up small amounts of code and check usefulness, save incremental versions, and add tested code in pieces.  Back up incremental accomplishments.  That way one problem is being solved at a time, and not working on 10 simultaneous problems; usually syntax errors or not understanding the format provided when libraries are included.

Use // to comment out code that is working, to debug code

Use /*   and the mating */ to comment out an entire section of multiple lines of code
When starting from scratch, there are four layers of coding:

  1. Details, objectives, correlations, description of sequences, anticipated restrictions, and risks all written in English;
  2. Flow Chart (when starting from a default state) and/or State Diagram (when starting from a previous state) to reflect written English;
  3. Pseudo-code (ends up representing comments in code); &
  4. Syntax Correct code (often typed on next line after //pseudo code)

followed by:

  • entering code
  • testing, and
  • debugging


All tutorials are added for completeness.  But the main tutorials for the data-logger are: start with 11, then 1, 3, 6, 7, 8, & repeat 11

In one class period (or homework assignment) the students can read through everything needed to make a data-logger.  With 10% expected uptake.  Hands-on practiced experience is needed to correlate the conveyed information effectively.

Notice the Actual Code provided below deviates somewhat from that in the tutorials.  The code below works as-is, so no learning occurs related to coding.

An important aspect is to as much as practical, have the students learn “how” to solve their own problems.  The act of getting practiced experience in problem solving better prepares them for actual life experiences.
The students can then at your option write and implement code based upon tutorials, or just build the data-logger and explore other class efforts.
For explanations:
SD.h library reference       (serial interface with SD card)
Wire.h library reference  (I2C temp sensors)

Tutorials at times use a software called “Processing”.  The more advanced code editor for Arduino; free from
select “no donation” to download

“Processing” code (Arduino code is based on Processing code) uses .pde file extensions and contains the code in text format.  In most cases, if not all, the Arduino user interface is more reliable and easier to use.

Each of the Video tutorials has a related download page for the related code, to minimize making typos.

“Arduino” automatically includes libraries, while “Processing” requires “Import” of every library used.
Arduino Free Software Downloads: ; all parts can be purchased on eBay (<$15 total)


Tutorial 01 for Arduino: Getting Acquainted with Arduino

Tutorial 02 for Arduino: Buttons, PWM, and Functions

Tutorial 03 for Arduino: Electrical Engineering Basics

Tutorial 04 for Arduino: Analog Inputs

Tutorial 05 for Arduino: Motors and Transistors

Tutorial 06 for Arduino: Serial Communication and Processing


Tutorial 07 for Arduino: I2C Communication and Processing

Tutorial 08 for Arduino: SPI Interfaces

Tutorial 09 for Arduino: Wireless Communication

Tutorial 10 for Arduino: Interrupts and Hardware Debouncing

Tutorial 11 for Arduino: SD Cards and Data-logging

Tutorial 12 for Arduino: RFID Card Reading

Tutorial 13 for Arduino: Liquid Crystal Displays (LCDs)

Tutorial 14 for Arduino: Holiday Lights and Sounds Spectacular!

Tutorial 15 for Arduino: GPS Tracking

Optional Arduino Video Tutorials related to Smart Lighting

Tutorial 16 for Arduino: Making a DMX controlled application (stage and DJ lighting – plus)

Tutorial 17 for Arduino: Decoding DMX part 2

Tutorial 18 for Arduino: Decoding DMX part 3

Building your own data-logger board

This is to replace the $3 data-logger board you can buy directly from eBay (cited above).  The purpose is to learn the related skills in project building.

  • micro-SD Memory Card Circuit Adapter
  • Micro-SD Flash
    • Data collection produces small files of much less than 1 Gbyte
    • Where to Buy
    • SD-Flash Adapter for use with computers without a micro-SD card slot
  • Arduino Proto Shield

The following is the wiring diagram for connecting the SD Card Board to the Arduino

Enclosed below are video tutorials that allow for understanding the code to create a data-logger.  Many micro-SD card shields exist for as little as about $1.00 (USD).  The video tutorial uses a different version.  The exact code follows below for the SD card used here.  SD card shields (circuit boards) and SD memory cards.

Actual Code to Use with specified build it yourself Catalex SD Card Adapter

Arduino to SD Card Adapter wiring connections

//Program by Jeremy Blum
//SD Card Demonstration
//Some code from public domain work by Tom Igoe
//Code modified by James Dunn

//  excessive Serial Monitor statements included so user can follow code execution; this slows down operations

//  modify this code with Serial Monitor statements removed to record data much faster


#include <SD.h>         //SD Card Library

#include <Wire.h>       //I2C Library

//SPI SD Card Pins

//MOSI = Pin 11

//MISO = Pin 12

//SCLK = PIN 13

int CS_pin = 10;

int pow_pin = 8;

//I2C Temperature Pins

//SDA = Analog Pin 4

//SCL = Analog Pin 5

//IR Distance Sensor Pins

int IR1_pin = 2;

int IR2_pin = 3;

//Light Sensor Pins

int light_pin = 1;

float refresh_rate = 0.0;  //Dataloger Refresh Rate

int temp_address = 72;     //Address of the I2C Temp Sensor

long id = 1;                //Use this to store the id # of our reading.

void setup()




Serial.println(“serial set at 9600 baud”);

//CS Pin is an output

pinMode(CS_pin, OUTPUT);

Serial.println(“CS_pin set as OUTPUT”);

//SD Card will Draw Power from Pin 8, so set it high

pinMode(pow_pin, OUTPUT);

digitalWrite(pow_pin, HIGH);

Serial.println(“pow-pin 8 set as OUTPUT and HIGH”);

//Initialize SD Card with CS_pin = 10

if (!SD.begin(CS_pin))


Serial.println(“Card Failure – CS_pin 10 no signal”);



Serial.println(“Card Ready – Signal on CS_pin 10”);


//Create configuration file COMMANDS.txt

File commandFile =“COMMANDS.txt”, FILE_WRITE);



//Read the Configuration information (COMMANDS.txt)

commandFile =“COMMANDS.txt”, FILE_READ);

if (commandFile)


Serial.println(“Read from COMMANDS File”);

float decade = pow(10, (commandFile.available() – 1));



float temp = ( – ‘0’);

refresh_rate = temp*decade+refresh_rate;

decade = decade/10;


Serial.print(“Refresh Rate = “);






Serial.println(“Could not read command file.”);




Serial.println(“close command file”);

//Write Log File Header

File logFile =“LOG.csv”, FILE_WRITE);

Serial.println(“opened LOG.csv file”);

if (logFile)


logFile.println(“, , , ,”); //Just a leading blank line, in-case there is previous data

String header = “ID, Light, Temp, IR1, IR2”;


Serial.println(“wrote this header to LOG.csv: “);





Serial.println(“Couldn’t open LOG.csv file”);



void loop()


//Check Light Level

int light_level = analogRead(light_pin);

/* uncomment this section if using related temperature IC chips

//Read Temperature

Wire.beginTransmission(temp_address); //Start talking

Wire.write(0);//Ask for Register zero

Wire.endTransmission(); //Complete Transmission

Wire.requestFrom(temp_address, 1); //Request 1 Byte

while(Wire.available() == 0); //wait for response

int temp_c =; // Get the temp

int temp_f = round(temp_c*9.0/5.0 +32.0);  //Convert from Celcius to Fahrenheit


int temp_f = round(32.0); // delete this line if using related temperature IC chips

//Read Distances

int IR1_val = analogRead(IR1_pin);

int IR2_val = analogRead(IR2_pin);

//Create Data string for storing to SD card

//using CSV Format

String dataString = String(id) + “, ” + String(light_level) + “, ” + String(temp_f) + “, ” + String(IR1_val) + “, ” + String(IR2_val);

//Open a file to write to

//Only one file can be open at a time

File logFile =“LOG.csv”, FILE_WRITE);

if (logFile)







Serial.println(“Couldn’t open log file”);



//Increment ID number





You must be logged in to post a comment.