What are the advantages to build this DIY data logger?
To make it as easy as possible for you to build this data logger we used only off-the-shelf parts for the basic setup. This reduces the labour work to a minimum and makes reproducing easy and fast. We found that the most flexible solution for this task would be the Maker family from Arduino (external link: https://store.arduino.cc/collections/mkr-family). Those might not be the cheapest solution, but due to the same footprint they can be swapped on the main carrier board which allows quick development. There are even enviromental boards available which might cover your basic sensor needs.
Advantages
- off-the-shelf parts (can be easily sourced)
- customable program
- flexible design
Disadvantages
- Not power efficient
- Not the cheapest solution
Required parts
- Microcontroller Board: Arduino MKR Zero (external link)
- Prototyping Board: Arduino MKR Relay (external link)
- Solar charger, 12V Lead acid battery: For off grid systems (external link)
- Computer: with the latest Arduino IDE
- Programming Cable: USB mini cable
- Basic Hand Tools: Solder iron, screw driver
Optional part list
- Enclosure (Optional): Consider housing your data logger in an enclosure to safeguard it against environmental factors, enhancing durability and longevity
- Additional Components: Depending on project complexity, additional components like resistors, capacitors, LEDs, or relays may be necessary for specific functionalities
Capabilities of the data logger
- Switching up to 4 devices up to 1 ampere (12 Volt, 5 Volt or 3.3 Volt)
- storing data onto a SD-card
- accessing I2C devices
- accessing 4 analog signals
Connecting the parts
The above listed parts can be connected with some wires and connectors.
Line up the Controller boarb with the Relay board and make sure all power sources are disconnected.
We recommend using the listed solar charger or similar to have a stable 5V output for the Controller board. You can either use an USB cable to connet the two boards or use the 5V output and wires to power the VIN pin. Soldering a wire to the Relay board has the advantage that you can program the Board while using an external power.
After those steps you can already start programming your board and test out some basic stuff like switchin small pumps or so using the relais.
Base Code
Make sure you have installed the Arduino IDE on your computer. You can download it from Arduino directly (external link).
Make sure you have selected the correct board and port of your connected Arduino. If needed use the board manager under “Tools” to search for missing ones.
It is always a good idea to comment your code while writing it. If you might switch boards down the track it is also a good idea to use “#define” for defining your used pins. This way you don’t have to search for those pins later in your code if you would like to change them.
The below code example just shows how to switch the relais on and off while also writing to the SD card.
#include <SPI.h> #include <SdFat.h> #define chipSelect SDCARD_SS_PIN #define RELAY1 1 #define RELAY2 2 SdFat32 sd; File32 file; #define dataLog "datalog.txt" void InitializeSD() { Serial.print("Initializing SD card..."); // see if the card is present and can be initialized: if (!sd.begin(chipSelect)) { //sd.initErrorHalt(&Serial); Serial.println("Card failed, or not present"); // don't do anything more: } Serial.println("card initialized."); } void WriteToSD(String _fileName,String _dataString) { file = sd.open(_fileName, FILE_WRITE); // if the file is available, write to it: if (file) { file.println(_dataString); file.close(); } // if the file isn't open, pop up an error: else { Serial.println("error opening datalog.txt"); } } void setup() { Serial.begin(9600); InitializeSD(); pinMode(RELAY1, OUTPUT); pinMode(RELAY2, OUTPUT); digitalWrite(RELAY1,LOW); digitalWrite(RELAY2,HIGH); } void loop() { Serial.println("Switch Relais 1"); digitalWrite(RELAY1,!digitalRead(RELAY1)); //reads the state of relais 1 and inverts it WriteToSD(dataLog,"Switch Relais 1"); delay(2000); Serial.println("Switch Relais 2"); digitalWrite(RELAY2,!digitalRead(RELAY2)); //reads the state of relais 1 and inverts it WriteToSD(dataLog,"Switch Relais 2"); delay(2000); }