Arduino Working With Multiple Files (READ/WRITE)

Hello guys

Today I am presenting you Arduino project which works with RTC shield that can stores data. The main task of this project is working with multiple files that are stored on sc card. This project contains code that works with three files which are stored directly on SD card with arduino and RTC shield.
Because this project works with DataLogger shield, that data will also be stored at exactly same time as it is on your PC.

This project is upgraded version of my last project. That project can be found on instructables site by the name Arduino Data Logger Shield Small Project. If you have some problems understanding this project, I suggest you to see easier one first.

The main difference between those two project is that this project uses 3 text files, also this time we read data from two of them. Because we can read data, we can get mid value of humidity and temperature, that are stored on sd card. This will also be shown on the LCD connected to Arduino.

Once again, if you are new to Arduino and this is your first project that uses DataLogger, I suggest to go and check this link https://www.instructables.com/id/Arduino-Data-Logg... and when you get everything on that, come here and have some more fun.
Let's start.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: Parts

As every time that I write projects like this I will start with all of the parts that I used with this project. I will also suggest some of the sensors that can be used and can make this project a little bit different.

Parts:

  • Arduino uno rev3
  • Arduino Data logger shield
  • SD memory card
  • LCD 1602 green display with I2C (you can use any other display)
  • DHT22 (DHT11 works fine as well, but the precision of it is not the same as the dht22)
  • Few jumper cables
  • Breadboard
  • Battery 9v

You can change some parts. Good side of this project is that it can be used to store data from any other sensor. I would try working with smoke sensor, or infrared sensor. It works with any other sensor.
You can also change your Arduino also, but keep in mind that Arduino is the best for suiting Data logger.

Step 2: Connecting All Parts Together

This one is easy to connect. Even the schematic is the same as the easier project. But I would say that you need to watch out which pin you are going to use. Every time check the data sheet of Data logger to see which pins are best for using, because as I recall some pins are already defined and when I tried to use my sensor on one of the defined pins it didn't work.

At the top of this step you can see schematic made with fritzing. Easy thing is that you need to connect your data logger on the top of your arduino. Connect your sd card to data logger, and the last thing you need to do is connect dht sensor and lcd. We use 5V from arduino for + part on the breadboard, GND for - part, and by following those line you connect also + line of sensor and lcd to + line of the bread board. Same goes for - parts, they just go to the line that follows -. Dht sensor is connected to pin 7 this time. LCD is connected to A4 and A5.
Easy, isn't it?

LCD:

  • VCC to 5V(+ part on breadboard)
  • GND to gnd(-part on breadboard)
  • SDA to analog pin A4
  • SCL to analog pin A5

DHT22:

I used dht with board in which there are three pins to be used :

  • + to 5V
  • - to GND
  • out to digital pin 7

Step 3: Codding

This time code is more complex. A good part of it is commented so you can understand it with ease.

I'll explain this code in few short parts.

1.First thing to keep in mind that this code will need few libraries installed on your PC. Those are: Time(TimeLib), Wire, LiquidCrystal, DHT, OneWire, SPI, SD, RTClib. You can probably use some other libraries but this libraries worked for me.
2. After that we are defining everything that is needed for this project. DHT sensor is easy to define, you just need to say the pin that is sensor connected to and type of sensor. After that you need to define some pins that will be used for SD card and RTC pin. And after that you can see variables used for this project.

3. Project uses few methods and all of them are for working with DHT sensor. If you are working on project with this type of sensor you can use it. Those methods are getTemperature(), getMidTemperature(), getHumidity(), getMidHumidity(), readSensorData(), printLcdTemperature(), printHumidity(), printLcdMidTemperature(), printMidHumidity().

4. In setup there are few things that are needed to get done. First of all you need to define time. Because we are using RTC here we want to have proper time when our Arduino saves data from sensor. That part will be commented in code. If you uncomment //RTC.adjust(DateTime(__DATE__, __TIME__)); line you can set time on your project. After you set proper time you can comment that part again, and you can use your arduino without computer. This is cool because you can use your temperature sensor in some other room and keep track of temperature without need of your computer. Second part that is to be done is using your SD card on which there will be data stored. Shield will try to see if there is card and initialize it. If there is not the error message will be shown in the Serial screen on Arduino IDE.

In setup is first step where we work with writing files on memory card. First thing that is written on card is on file datalog.txt. This time we write just the time of logging our device, and we also create a small row of names(variables used to save, and also time)

Last part of the setup is initializing LCD, and dht sensor.

5. Loop part is the main part of the project. Working with sensor this time is very easy because it uses only one method which is read the values that sensor get. LCD part is also very easy.
The next part is one which we need to explain here. This project does something every minute. One minute it stores data to datalog.txt. This data can be read by someone who doesn't even know how to program arduinos.
On the other side. One minute it saves temperature on datalogB.txt and one minute it saves humidity on datalogC.txt.
We need datalogB.txt and dataLogC.txt so we can read from our memory card. So if we continue reading our code you can see also that this code reads mid values of the temperature and humidity and stores them in one row. I wanted to make device that takes only last ten digits on file. So this project runs always through the values from card, and saves the last ten digits.
These digits stored in rows are used so we can get average value of temperature and average value of humidity. Which are also shown on our LCD after some time

Step 4: Using Arduino and SD Card Afterwards

Here you can see what is show on LCD and how the project works.
Also I am putting here pictures of the datalogs i saved.
Datalog.txt is the one that can be used to see how the device store every value.
DatalogB and datalogC are there so you can see how they look. They are written like that so you can use parse method and read data with no problems.

The whole point of this project is manipulation of the files that are on sd card. Sometimes we need devices that can store memory and reading temperature is also one time like that. Good thing is that shield used on this device also has a RTC module, which is the best thing for time. When we can read real time, and store data with our device, that means that it can be portable.

Thank you guys for reading this project. I hope it will help you out.
Thank You.

With all regards
Sebastian

Be the First to Share

    Recommendations

    • Instrument Contest

      Instrument Contest
    • Make it Glow Contest

      Make it Glow Contest
    • STEM Contest

      STEM Contest

    Discussions