The datalogger is a particular mounting which can register values coming from sensors on a support (like an SD card).
This system can be used in many projects that need a periodical measurement (such as probes ;-)).
This probe collects values from sensors and registers them into the SD card of the datalogging shield.
When you plug your SD card into your computer, you will see an excel file with sensors values onto.
Code/ ! \ First Code ---> That initialize the RTC to makes it synchronize with the probe values
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <ds3231.h>
struct ts t;
const char* filename = "Probe.csv";
File file;
void setup() {
Wire.begin();
DS3231_init(DS3231_INTCN);
/*----------------------------------------------------------------------------
In order to synchronise your clock module, insert timetable values below !
----------------------------------------------------------------------------*/
t.hour=20;
t.min=30;
t.sec=0;
t.mday=25;
t.mon=01;
t.year=2020;
DS3231_set(t);
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
for (;;);
}
file = SD.open(filename, FILE_WRITE);
if (file.size() == 0) {
file.println("Time; Light; Temp; Wat.lev");
file.flush();
}
}
void loop() {
DS3231_get(&t);
measure();
delay(1000);
}
void measure() {
int val1 = analogRead(A0);
int val2 = analogRead(A1);
int val3 = analogRead(A2);
file.print(t.mon);
file.print("/");
file.print(t.mday);
file.print("|");
file.print(t.hour);
file.print(":");
file.print(t.min);
file.print(":");
file.print(t.sec);
file.print("; ");
file.print(val1);
file.print("; ");
file.print(val2);
file.print("; ");
file.println(val3);
file.flush();
}
/ ! \ Second Code ---> The same code without the part of initializing the RTC
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <ds3231.h>
struct ts t;
const char* filename = "Probe.csv";
File file;
void setup() {
Wire.begin();
DS3231_init(DS3231_INTCN);
DS3231_set(t);
pinMode(10, OUTPUT);
if (!SD.begin(10)) {
for (;;);
}
file = SD.open(filename, FILE_WRITE);
if (file.size() == 0) {
file.println("Time; Light; Temp; Wat.lev");
file.flush();
}
}
void loop() {
DS3231_get(&t);
measure();
delay(1000);
}
void measure() {
int val1 = analogRead(A0);
int val2 = analogRead(A1);
int val3 = analogRead(A2);
file.print(t.mon);
file.print("/");
file.print(t.mday);
file.print("|");
file.print(t.hour);
file.print(":");
file.print(t.min);
file.print(":");
file.print(t.sec);
file.print("; ");
file.print(val1);
file.print("; ");
file.print(val2);
file.print("; ");
file.println(val3);
file.flush();
}
LibraryFor this project you will need the DS3231 library:
https://github.com/rodan/ds3231.
SchematicsConnections between sensors and the datalogger shield are the same that connections shown on schematics. You just have to plug the datalogger shield on the arduino before doing connections.
Values are display on 4 columns: Time (provided by the RTC), light, temperature and water level.
Comments