Projects / CO2 and light monitor for a grow tent

CO2 and light monitor for a grow tent

Intermediate2 hGuided buildReviewed

Build it step by step

0 of 7 done
  1. ESP32

    Test each sensor

    Print values on serial.

  2. ESP32DS323118:08

    Set the clock

    DS3231 example.

  3. ESP32MICROS

    Log to the card

    One CSV line each five minutes.

  4. ESP32BH1750496 lux

    Add the light total

    Daily light integral.

  5. ESP32

    Place the sensors

    At plant height.

  6. ESP32

    Run for a week

    Check the CSV.

  7. ESP32SCD40BH1750498 lux

    Plot the days

    CO2 and light against time.

In short

How do you build a CO2 and light monitor for a grow tent?

An SCD40 and a light sensor in a grow tent log CO2, temperature, humidity and light hours to see what plants are getting. You need ESP32 DevKit V1, SCD40 CO2 sensor, BH1750 light sensor, MicroSD Card Module and DS3231 RTC module. It takes 7 steps and about 120 minutes.

Level
Intermediate
Time
About 120 min
Parts
5

Parts list

Tick what you already own. It saves to My Garage, so “Build with what I have” knows.

Wiring

FromToWhy
SCD40, BH1750 and RTC SDAESP32 GPIO21Shared I2C data
SCD40, BH1750 and RTC SCLESP32 GPIO22Shared I2C clock
Sensors and RTC VCC and GNDESP32 3V3 and GNDPower
SD module CSESP32 GPIO5Chip select
SD module SCK, MISO, MOSIESP32 GPIO18, GPIO19, GPIO23SPI
SD module VCCESP32 5V (VIN)Module power

Code

The SCD40 measures real CO2 with a photoacoustic sensor, so it is more trustworthy than cheaper sensors that only guess. All three sensors share two wires because each has its own I2C address. Every five minutes the sketch writes a line to the card with the time, CO2, temperature, humidity and lux, and adds the light to a running total called the daily light integral, in moles per square metre, which is what plants really care about, such as 12 to 17 for lettuce; the lux-to-PPFD factor is a rough one for white LED lights, so treat the DLI as an estimate. Open the CSV in a spreadsheet to see CO2 fall when the lights come on and plants take it up, and rise at night. Place the CO2 sensor at plant height, away from the exhaust fan. Library names differ by version, so use the Library Manager to install the current Sensirion SCD4x one and adjust the class name if needed. Arduino IDE with the ESP32 boards package 2.0.x, board "ESP32 Dev Module". Do not add CO2 enrichment from bottles or burners without proper ventilation and a safety monitor, since high CO2 is dangerous.

Runs on a virtual ESP32 Dev Module 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).

// Grow tent logger: CO2, temperature, humidity, light and a daily light integral estimate. Board: ESP32 Dev Module.
// Libraries: Sensirion I2C SCD4x, BH1750, RTClib, SD.
#include <Wire.h>
#include <SensirionI2cScd4x.h>
#include <BH1750.h>
#include <RTClib.h>
#include <SD.h>
SensirionI2cScd4x scd;
BH1750 lux;
RTC_DS3231 rtc;
const float LUX_TO_PPFD = 0.0185;                   // rough factor for white LED grow lights; use a quantum meter for accuracy
float dli = 0;                                      // mol per square metre, running total today
int lastDay = -1;
void setup() {
  Serial.begin(115200);
  Wire.begin(21, 22);
  scd.begin(Wire, 0x62);
  scd.stopPeriodicMeasurement(); delay(500);
  scd.startPeriodicMeasurement();
  lux.begin(); rtc.begin(); SD.begin(5);
}
void loop() {
  uint16_t co2 = 0; float t = 0, rh = 0;
  delay(5500);                                      // the SCD40 produces a reading every five seconds
  if (scd.readMeasurement(co2, t, rh) == 0 && co2 > 0) {
    float l = lux.readLightLevel();
    DateTime now = rtc.now();
    if (now.day() != lastDay) { dli = 0; lastDay = now.day(); }
    dli += l * LUX_TO_PPFD * 300.0 / 1e6;           // five minutes of light, converted to mol per square metre
    File f = SD.open("/tent.csv", FILE_APPEND);
    if (f) {
      f.printf("%04d-%02d-%02d %02d:%02d,%u,%.1f,%.0f,%.0f,%.2f\n", now.year(), now.month(), now.day(), now.hour(), now.minute(), co2, t, rh, l, dli);
      f.close();
    }
    Serial.printf("CO2 %u ppm  %.1f C  %.0f %%  %.0f lux  DLI %.2f\n", co2, t, rh, l, dli);
  }
  delay(294500);                                    // log every five minutes
}

Test checklist

What you should see at each check. If a reading is far off, stop and use the troubleshooting list.

CheckExpected
Lights onCO2 falls slowly
Lights offCO2 rises
DLIGrows through the day and resets at midnight
CardOne new line every five minutes

If it does not work

CO2 reads zero

Wait the first 30 seconds after power on.

SD fails

Format FAT32 and check the 5V supply to the module.

DLI too high

Use a quantum meter to correct the factor.

I2C errors

Check the shared wiring and addresses.

Still stuck? Find the fault step by step with your multimeter →

Ask Lark AI

Common questions

What parts do I need for the CO2 and light monitor for a grow tent?

ESP32 DevKit V1, SCD40 CO2 sensor, BH1750 light sensor, MicroSD Card Module and DS3231 RTC module.

How long does the CO2 and light monitor for a grow tent take to build?

About 120 minutes for a intermediate maker, in 7 steps.

How do I know the CO2 and light monitor for a grow tent works?

Lights on: CO2 falls slowly. Lights off: CO2 rises. DLI: Grows through the day and resets at midnight.

CO2 reads zero: what should I check?

Wait the first 30 seconds after power on.

SD fails: what should I check?

Format FAT32 and check the 5V supply to the module.

DLI too high: what should I check?

Use a quantum meter to correct the factor.

I2C errors: what should I check?

Check the shared wiring and addresses.