Data Logging and Solar Power

Hi! Complete beginner here- I'm creating a soil temperature sensor, which I would like it to track soil temp in a greenhouse over the course of a few days and I can take the data out afterwards and graph it. Am I on the right track by looking to purchase a DS3231 Timer Module, SD Card Module with a Micro SD Card 8GB?

Also, it would be great to have it be solar powered- can anyone point me to tutorials and components I would need to make it so and how it would retain energy during the night?

Here is my wiring currently- temperature readings are working!

Include a push button switch to tell your program to close the SD card file and stop the program so you can remove the card!

thank you! Could unplugging the arduino also just turn it off so I can remove the card?

Assume your sketch opens the file when it starts up, and writes to it at intervals. How does your sketch know its hardware is being turned off and that it's time to close the file on the SD card? @Paul_KD7HB has pointed out one solution to that.

I would use the onboard LED to determine when you are writing to the SD.

Turn on the LED, wait a couple seconds, open, write, and close the file, turn off the LED.

Don't turn off the Arduino when the LED is lit.

You would need a photovoltaic cell, a charge controller, and a battery.

Perhaps later.

Unless your program closes the data file so the file system is updated, you will loose all the data. Your choice!

I have done this with data collectors that I can't guarantee will have uninterrupted power... meaning ALL OF THEM....

Write the record, close the file, open the file, repeat.

If there's a lot of writing then close and open every so often after a write, let it go as long as you don't care the last bit to be lost.

Perhaps every hour, close one file and open a new one with the hour at the end of the name, or make a new file per day.

I 'just unplugged' an Uno one time and lost a 20x4 LCD display. Don't be sure you won't corrupt the SD card, have a clean power-off where it is not being fed data.

Power the greenhouse and draw for the collector from that? Reason being you might do that completely off-the-shelf.

Thank you for the warning!

An advanced tinkerer would use a WiFi enabled board, running a web server.
Then you don't need a RTC or SD card and you can see the temp data directly (data or graph) on a smartphone or laptop. An ESP(32) board has enough internal storage for months (years) of data. Some ESP boards even have a battery connector and built-in charger. So you can connect a 5volt solar panel directly to the board.
I don't know where to find complete working examples like that.
The fun of this hobby is that you first learn the individual building blocks and then string them together.

Many years ago I built a website/temp logger with an ESP8266. (see last page).
Worked, but is very outdated. I would now use a Seeed XIAO-C3 instead.

Wow, necessity met in the marketplace!

In 2016 I helped a project that used GSM to post data online, WIFI might be better?

Depends on how far the setup is from the home router.

You can always set up an access point on the ESP if out of range, but then you loose the ability to get internet time.

Because this will be an agriculture sensor I don't think it will be in range of a router- are there ways to get IoT capabilities without WiFi nearby?

There is LoraWAN, but I don't have any experience there.

...

GSM lets you communicate with satellites.

I have implemented a river level monitor with temperature and humidity sensors using a Heltec WiFi32 LoRa V3 which has a ESP32-S3 (with WiFi and BLE) with onboard SX1262 LoRa and OLED modules
it uses BMP280 temperature/pressure sensor, a SR04M ultrasonic transducer and a DS18B20 DallasTemperature sensor uploading data over LoRaWAN to the ThingsBoard desktop, e.g.


it can be seen the river is tidal (about 10cm ride and fall)

in addition the river level is transmitted over ESP-NOW to a local CYD display

the advantage of use a module such as the Heltec LoRa V3 with onboard LoRa module and OLED is it reduces the module interconnection wiring which is a source of poor connections and intermittent problems

looking to add a Heltec Solar Kit for Dev-board, Waterproof Enclosure for Outdoor

to use LoRaWAN you would require a a LoRaWAN gateway in range - maybe a problem in remote areas
for local communication you could use LoRa point-to-point communicating between a pair of LoRa modules

i would start by checking the heatmaps for The Things Network and Helium. If your location is in range of a public gateway, congrats, you have access to a free, secure, time-stamped way to get your data on the net, using LoRaWAN.

If you're not in range, it's possible to set up your own gateway but this is definitely not a beginner level exercise. Instead, as already mentioned, point to point LoRa (not LoRaWAN) is a very effective and quite simple alternative.

You need two Arduino / ESP32 devices, one in the field, one back at base where it can access both LoRa and wifi. Here's an example I built, using an Arduino MKRWAN 1310 in the field and a Heltec LoRa V3 Wifi for the base station.

The field end is now solar powered although the photo is earlier than that. The MKRWAN 1310 can accept a 5V solar panel plugged into Vin without the need for a separate battery charger chip - it has one onboard.

Several years ago I worked on a river monitor project. Many locations did not have WiFi coverage so we used an ESP-01 (ESP8266) in Access Point (AP) mode as the interface to the system. In this mode the ESP-01 module acts as the connection point for WiFi so no router or internet required. An ATMEGA1284 did the data collection and storage. The ESP-01 implemented a web server to connect to a browser (phone or laptop) on one side and a serial interface to the ATMEGA1284 for maintenance and data download.

Since there was no internet connection we used a DS3231 RTC for timestamps. We used the alarm functions to generate interrupts for the data collection and WiFi on times.

We used an SD card for data storage and generated a new file each week to keep the files to a manageable size. The web server could download a file to the browser using the browser file download function. An advantage of the web server interface is that only a browser was needed on the reading device.

If I were doing the project today I would use something like an ESP32-S3 and put all the functions in one module. I would still use the DS3231 for timing. Depending on the data collection rate I would use the onboard flash or an SD card. The onboard flash memory has a limited number of write/erase cycles so I would do the calculation to see if that would be a problem.

We used solar power to run the system. We powered off the sensors between readings and only powered on the WiFi at specific times. The WiFi was the biggest power user and by limiting the on time and only running it during the day it was powered by the solar cells and didn't deplete the battery (but did slow down charging while it was on).

When using solar power be aware that solar panel output and battery capacity specs are optimistic, fantasy or outright lies. Multiply your expected power needs by 2 or 3 the get a reasonable value for the solar panel and battery.