Go Down

Topic: How to extract specific information from the SD card and show in the LCD (Read 602 times) previous topic - next topic


Hello guys!

I'm new in programming and I'm working in a garden automation project. I irrigate automatically my garden twice a day in specifics times (morning: 06:00 am to 07:00 am and evening 05:00 pm to 06:00 pm ) depending on the soil moisture and I show in a LCD screen if it has irrigated or not. My problem is that every time that I reset the Arduino or if the energy interrupts, my LCD will show that it didn't irrigate.

I have a micro SD card that stores all the information that I need in a .txt file separate by commas ",". I'm wondering if is possible to read the information of the day (doesn't need to check all the data in the SD card) and check if it has irrigated or not. This needs to be done just once when the arduino starts. An example of how I store my data is:

day(dd/mm/yyyy), time(0 - 24), temperature (ÂșC), air humidity (%), soil moisture (raw data: 0-1023), luminosity (lux), irrigation in the morning(Yes or empty), irrigation in the evening(Yes or empty), irrigation manually (Yes or empty)

03/03/2017,07:05,19,88,512,775.74, yes, ,   
03/03/2017,14:26,21,90,528,775.74, , ,
03/03/2017,17:16,23,75,472,162.24, ,yes ,

So basically, I just need to check the 1st, 7th, 8th and 9th column of the current day. Any suggestions or ideas? My code has almost 400 lines but if is necessary I can post here.

Thanks guys!


I'm wondering if is possible to read the information of the day (doesn't need to check all the data in the SD card)
Your program will need to read each line from the file, and parse the data to at least get the date. Then, it will need to determine if that date is today's date.

If so, it will need to parse the rest of the data to get the information you are looking for.

If not, it will need to keep reading.

The art of getting good answers lies in asking good questions.


Thanks Paul! I tried your tips and worked fine for me in C++ but when I try to adapt to "arduino language" (I don't know if is correct to say like this) it doesn't work properly. So my sketch in C++ is:

Code: [Select]
#include <iostream>
#include <fstream>
#include <string>
#include <cstdio>
using namespace std;

int main()
 int i = 0;
 string line;
 string day =  "15/02/2017";  // just as an example to read the data of a specific day
 string morning = "Yes_m";   // I've changed my data to Yes_m to be easier to find that has irrigated in the morning
 string afternoon = "Yes_a"; // same as above
 string solenoid = "Yes_s";  // same as above

 ifstream myfile ("DATA.txt"); //opens the file

 while(!myfile.eof())             //read until the end of the file
 getline(myfile, line); // get the line
 size_t found0 = line.find(day);
 if ( found0 != string::npos)
 size_t found1 = line.find(morning);
 if (found1 != string::npos )
 irrigation_morning = true;

 size_t found2 = line.find(afternoon);
 if (found2 != string::npos )
 irrigation_afternoon = true;;

 size_t found3 = line.find(solenoid);
 if (found3 != string::npos )
 ++i; // the solenoid could be used more than one time a day, so I used a counter

 printf("Irrigated %d times manually",i) ;
return 0;


Apparently, there are no getline and .find() for string in arduino and I didn't find a easy way to read from the last line to the top. I generate too much data and it was taking long time to read everything. After searching solutions I ended up using EEPROM library. It works fine for what I want. I've read that this method is just reliable for 100,000 times in a specific position of the memory. I write two times a day at max which gives me 50,000 reliable days  :) .

Go Up