The Seedling Light Exposure Tracker

SS 1 Arduino Uno Simulation first Time-Series Integration
Simulation lab
Board: ♾️ Arduino Uno
Open in Wokwi ↗
Simulator preview
ARDUINO UNO

Press the pushbutton to test the interactive circuit in real time.

>_ Serial monitor
Ready — press the button.
📦 Components ▴
  • Arduino Uno microcontroller board
  • LED indicator (green)
  • 220 ohm current-limiting resistor
  • Tactile pushbutton switch
  • Jumper wires (male-male)

🔧 Build Your DLI Exposure Tracker

1 Calibrate an analog photoresistor (LDR) voltage divider into physical Lux units (0 to 100,000 Lux).
2 Sample illumination and calculate delta time: 'dt = (millis() - last_time) / 1000.0'.
3 Execute numerical Riemann sum integration: 'cumulative_light += lux * dt'.
4 Trigger automated shade cloth servo actuators when target Daily Light Integral (DLI) is satisfied!
🧩 Block plan / Starter code ▴
const int LDR_PIN = A0;
const int SHADE_ACTUATOR = 9;
const float TARGET_EXPOSURE = 200.0; // Target in kiloLux-seconds

unsigned long lastSampleTime = 0;
float totalExposure = 0.0; // Accumulated kiloLux-seconds

void setup() {
  pinMode(SHADE_ACTUATOR, OUTPUT);
  Serial.begin(9600);
  lastSampleTime = millis();
}

void loop() {
  unsigned long now = millis();
  float dt = (now - lastSampleTime) / 1000.0; // elapsed seconds
  lastSampleTime = now;

  int rawADC = analogRead(LDR_PIN);
  float lux = (rawADC / 1023.0) * 100.0; // Calibrated Lux scale

  // Numerical Integration (Euler Riemann sum)
  totalExposure += (lux * dt) / 1000.0; // Accumulate kLux-s

  Serial.print("Lux: "); Serial.print(lux);
  Serial.print(" | Accumulated DLI: "); Serial.println(totalExposure);

  if (totalExposure >= TARGET_EXPOSURE) {
    digitalWrite(SHADE_ACTUATOR, HIGH); // Deploy protective shade cloth
    Serial.println("Daily Light Quota Met! Shade Deployed.");
  }
  delay(1000);
}

Numerical time integration accumulates instantaneous rate into total consumed quantity over time.

⚗️ Test your model

Test Condition / ActionExpected Result
Dark Room (Lux = 2)totalExposure accumulator stays nearly stationary
Bright Lamp (Lux = 80)totalExposure climbs smoothly in proportion to Lux * time
Exposure >= 200 kLux-sShade cloth actuator energizes immediately; logs quota event
⚑ Try a challenge

Implement an automated midnight reset algorithm that saves the daily total to internal EEPROM before zeroing the accumulator!

❓ Quick check
What mathematical operation is used in agronomy to calculate total cumulative light exposure from instantaneous lux measurements over time?

📖 Our Story & Concepts

In greenhouse agronomy, plants do not grow from instantaneous light intensity; they grow from the total quantity of photons absorbed throughout the entire day. This biological metric is called Daily Light Integral (DLI), measured in moles of light per square meter per day.

In mathematics and physics, finding the total quantity accumulated by a changing rate is called integration. By multiplying instantaneous sensor intensity by elapsed time intervals (dt) and summing the rectangles, an embedded microcontroller performs real-time numerical calculus.

</> Full Annotated Code Walkthrough

// Complete Time-Series Trapezoidal Integrator with Daily Archive
const int LDR_PIN = A0;
const int RELAY_SHADE = 9;

unsigned long prevTime = 0;
float prevLux = 0;
float totalDLI = 0;

void setup() {
  pinMode(RELAY_SHADE, OUTPUT);
  Serial.begin(115200);
  prevTime = millis();
  prevLux = (analogRead(LDR_PIN) / 1023.0) * 100.0;
}

void loop() {
  unsigned long now = millis();
  float dt = (now - prevTime) / 1000.0;
  prevTime = now;

  float currentLux = (analogRead(LDR_PIN) / 1023.0) * 100.0;

  // Trapezoidal Integration Rule: ((y1 + y2) / 2) * dt
  float trapezoidArea = ((prevLux + currentLux) / 2.0) * dt;
  totalDLI += (trapezoidArea / 1000.0);
  prevLux = currentLux;

  Serial.print("CurrentLux:"); Serial.print(currentLux);
  Serial.print(",CumulativeDLI:"); Serial.println(totalDLI);

  if (totalDLI >= 250.0) {
    digitalWrite(RELAY_SHADE, HIGH);
  }
  delay(1000);
}

Numerical time integration accumulates instantaneous rate into total consumed quantity over time.

▷ Expected Results & Troubleshooting

Test Condition / ActionExpected Result
Dark Room (Lux = 2)totalExposure accumulator stays nearly stationary
Bright Lamp (Lux = 80)totalExposure climbs smoothly in proportion to Lux * time
Exposure >= 200 kLux-sShade cloth actuator energizes immediately; logs quota event

⚑ Extension Challenges & Blueprints

⚑ Extension Challenges
  • Level 1: Compare Euler rectangular integration with Trapezoidal integration accuracy.
  • Level 2: Add a real-time clock (RTC) module to log light accumulation hour-by-hour.
  • Level 3: Apply the integration engine to a flow meter to compute total cubic meters of water dispensed.

❓ Check Your Understanding

Question 1: What mathematical operation is used in agronomy to calculate total cumulative light exposure from instantaneous lux measurements over time?

Question 2: Why is 'millis()' preferred over 'delay(1000)' for timing periodic sensor integration in Arduino C++?

Question 3: If an agronomy nursery seedling receives 20,000 Lux steadily for 3 hours, what is its total light exposure in Lux-Hours?

Question 4: What happens in agricultural greenhouses when delicate cocoa or tomato seedlings receive excessive cumulative light exposure beyond their biological limit?

Feedback appears after you check your answer.