Light Log (using Arduino + sdCard)

I want to create a week log of my light exposure. To do so, I will use an Arduino Duemilanove and the SD card module by Seedstudio. Interfacing the Arduino board with the SD card module is not too difficult but it took me days to get it working. I downloaded lots of different libraries until I found one that is really helpful: sdfatlib by Bill Greiman []. This library is illustrated with lots of examples and it makes it very easy to start working.

What I had to do was to modify one of the examples slightly so that the board saves the analogReadings on the Sd card. That’s done using file.println(analogRead(1)). I used the Append example. I’m sure I could clean it much more, there are probably lots of things that I don’t need but as you might have guessed I’m nothing like a programmer. This is the code I used:


* Append Example
* This sketch shows how to use open for append and the Arduino Print class
* with SdFat.
#include <SdFat.h>
#include <SdFatUtil.h> // use functions to print strings from flash memory

Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;

// store error strings in flash to save RAM
#define error(s) error_P(PSTR(s))
void error_P(const char *str)
PgmPrint(“error: “);
if (card.errorCode()) {
PgmPrint(“SD error: “);
Serial.print(card.errorCode(), HEX);
Serial.println(card.errorData(), HEX);

void setup(void)
//  PgmPrintln(“Type any character to start”);
// while (!Serial.available());

// initialize the SD card
if (!card.init()) error(“card.init”);

// initialize a FAT volume
if (!volume.init(card)) error(“volume.init”);

// open the root directory
if (!root.openRoot(volume)) error(“openRoot”);


void loop(void){

char name[] = “WRITE01.TXT”; // create file with this name
PgmPrint(“Appending to: “);

// clear write error
file.writeError = false;

for (uint8_t i = 0; i < 100; i++) {
// O_CREAT – create the file if it does not exist
// O_APPEND – seek to the end of the file prior to each write
// O_WRITE – open for write
if (!, name, O_CREAT | O_APPEND | O_WRITE)) error(“open”);

// write values to the file

if (!file.close() || file.writeError) error(“close/write”);
if (i > 0 && i%25 == 0)Serial.println();




Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

  • Contact Me

    olga [AT]
  • Bio

    Olga carries practical and theoretical research in the field of media arts. She works as a co-editor with while she pursues a practice-based PhD at Goldsmiths. Her research project looks into assemblages of sunlight, human bodies and machines. She is particularly interested on subtle modes of communication across bodies of radically different nature. She looks at the ways in which electronic circuits, computational systems, endocrine processes and neurological happenings intermingle. The tools she develops are speculations about the undercurrents of body communication.
%d bloggers like this: