Build it step by step
0 of 6 doneMount the sensor
Fix it 40 cm above the soil, looking straight down at the middle of the pot.
Wire it
Sensor and RTC on A4 and A5, SD on D10 and SPI pins, button on D4.
Set the zero
With bare soil in the pot, press the button. The soil distance is saved.
Test
Hold a ruler or a book at 10 cm under the sensor and check the height in the file.
Run it
Plant a seedling. Leave the rig on. It logs one value a day at noon.
Compare
Make two rigs with different lights, and chart the two files in a spreadsheet.
How do you build a seedling height tracker?
A VL53L0X sensor above a pot measures plant height every day and plots how fast it grows under different lights. You need Arduino Nano, VL53L0X time-of-flight distance sensor, DS3231 RTC module, MicroSD Card Module, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data). It takes 6 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 7
Wiring
| From | To | Why |
|---|---|---|
| VL53L0X VIN and GND | Nano 5V and GND | Sensor supply (the module has a regulator) |
| VL53L0X SDA and SCL | Nano A4 and A5 | I2C, address 0x29 |
| RTC SDA and SCL | Nano A4 and A5 | Shared bus |
| SD module CS | Nano D10 | Chip select |
| SD module MOSI, MISO, SCK | Nano D11, D12, D13 | SPI |
| SD module VCC and GND | Nano 5V and GND | Supply |
| Zero button | Nano D4 and GND | Press with the sensor over bare soil |
Code
Arduino IDE, board "Arduino Nano" (processor ATmega328P, or ATmega328P (Old Bootloader) for clones). Install "Adafruit VL53L0X" and "RTClib". SD and EEPROM come with the IDE. The sensor measures to the nearest part of the plant, so aim it at the top of the main stem and check with a ruler now and then. The sensor reads up to about 1.2 m indoors, but readings get noisy at long range and in bright sun.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Wire.h>
#include <Adafruit_VL53L0X.h>
#include <RTClib.h>
#include <SD.h>
#include <EEPROM.h>
Adafruit_VL53L0X lox;
RTC_DS3231 rtc;
const byte CS = 10, ZERO_BTN = 4;
const byte LOG_HOUR = 12; // measure once a day at noon
int soilMm = 400;
int lastDay = -1;
int readMm() {
VL53L0X_RangingMeasurementData_t m;
long sum = 0; byte n = 0;
for (byte i = 0; i < 10; i++) {
lox.rangingTest(&m, false);
if (m.RangeStatus != 4) { sum += m.RangeMilliMeter; n++; }
delay(60);
}
return n ? sum / n : -1;
}
void setup() {
pinMode(ZERO_BTN, INPUT_PULLUP);
Serial.begin(9600);
lox.begin();
rtc.begin();
if (rtc.lostPower()) rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
SD.begin(CS);
int saved; EEPROM.get(0, saved);
if (saved > 50 && saved < 1200) soilMm = saved;
}
void loop() {
if (digitalRead(ZERO_BTN) == LOW) { // zero point: the distance to the bare soil
int d = readMm();
if (d > 0) { soilMm = d; EEPROM.put(0, soilMm); Serial.print("Soil at "); Serial.println(soilMm); }
delay(500);
}
DateTime t = rtc.now();
if (t.hour() == LOG_HOUR && t.day() != lastDay) {
int d = readMm();
if (d > 0) {
lastDay = t.day();
File f = SD.open("GROWTH.CSV", FILE_WRITE);
if (f) {
if (f.size() == 0) f.println("date,height_mm");
f.print(t.year()); f.print('-'); f.print(t.month()); f.print('-'); f.print(t.day()); f.print(',');
f.println(soilMm - d); // plant height is the soil distance minus the plant distance
f.close();
}
}
}
delay(1000);
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Zero button on bare soil | Saves the distance |
| Object 10 cm above the soil | Logs about 100 mm |
| A day later | Another line in GROWTH.CSV |
| Power cycle | Zero distance restored |
If it does not work
No readings
Sensor not found. Check the I2C wiring and address.
Heights jump around
The sensor sees leaves and the pot rim differently. Aim at the stem tip and average more.
No file
SD card not FAT32 or wrong CS pin.
Wrong date
The RTC lost its time. Re-upload to set it.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the seedling height tracker?
Arduino Nano, VL53L0X time-of-flight distance sensor, DS3231 RTC module, MicroSD Card Module, Tactile push button 6 mm, Jumper wires male to male (40 pcs, 20 cm) and USB A to micro-USB cable (data).
How long does the seedling height tracker take to build?
About 60 minutes for a beginner maker, in 6 steps.
How do I know the seedling height tracker works?
Zero button on bare soil: Saves the distance. Object 10 cm above the soil: Logs about 100 mm. A day later: Another line in GROWTH.CSV.
No readings: what should I check?
Sensor not found. Check the I2C wiring and address.
Heights jump around: what should I check?
The sensor sees leaves and the pot rim differently. Aim at the stem tip and average more.
No file: what should I check?
SD card not FAT32 or wrong CS pin.
Wrong date: what should I check?
The RTC lost its time. Re-upload to set it.
