Day and Night
Record a plant for 24 hours and find its internal clock in the data — with a Fourier analysis that turns a jittery curve into a clear frequency.
In a nutshell
What: You let your sensor record a plant for a whole day — overnight, unattended. The next day you search the data with a Fourier transform (FFT) for recurring rhythms. If a 24-hour beat appears, you are seeing the plant's internal clock.
You need: the sensor from 11.1, an SD-card module or a permanently connected laptop, a plant at a window (natural day–night cycle) and, for the analysis, a bit of Python — runs straight in the browser, nothing to install.
What it's about
Almost every living thing carries an internal clock — the circadian rhythm. It beats with about 24 hours and keeps running even when the light stays constant. Plants are masters of it: they open and close leaves, shift their metabolism, prepare for sunrise before it comes. Part of this also shows in the bioelectric voltage you measure.
The problem: in the raw curve over 24 hours you mostly see noise and chance. The 24-hour beat is in there, but overlaid. Exactly for this there is the Fourier transform — a mathematical prism that splits a tangled curve into its individual oscillations. Where a bar sticks out at "one cycle per day" in the result, that is where the clock ticks.
Before you start
A 24-hour measurement must not be interrupted. Ensure a safe power supply (laptop on mains or a power bank), place the sensor so no one knocks it, and leave the plant at the window so it experiences the real day–night cycle. Stick the electrode on especially carefully — a contact that falls off after two hours ruins the whole night.
A little background
What the FFT does. Imagine a chord: several notes at once. Your ear hears mush, a good program splits it into the individual notes. The FFT does the same with your measurement curve. It asks: "which regular oscillations is this curve made of?" and returns a strength for each possible period (12 h, 24 h, 6 h …). A high value at 24 h means: there is a daily rhythm in there.
Why the sampling rate matters. For Activity 11.1 you measured 50 times a second — for 24 hours that would be a gigantic mountain of data and completely unnecessary. For slow daily rhythms one reading every few seconds is enough. The sketch below averages many fast measurements into one calm value every 5 seconds — that smooths the noise and keeps the file small.
Recording
- Load the logging sketch. Flash the sketch from the appendix. It measures on as usual, but writes only one averaged value every 5 seconds — with a timestamp — to the SD card (or to the Serial Monitor, if the laptop runs through the night).
- Secure the contact. Stick the electrode on carefully, fix the cable with tape, check for five minutes that the values run calmly. Only then let it run overnight.
- Note the start. Write down the exact time of the start — you need it to find day and night again in the curve later.
- Collect the next day. Stop after 24 hours of recording. Copy the file (e.g.
PLANT.CSV) to the laptop — two columns: time in seconds and reading.
Analysing with Python
The analysis runs straight in the browser (Pyodide) — load your CSV, and the code first plots the 24-hour curve and then the FFT spectrum. Where a bar sticks out at "1 cycle / 24 h", you have found the circadian rhythm. The full code is also on GitHub.
import numpy as np
import matplotlib.pyplot as plt
# ---- load the data: two columns (seconds, reading) ----
time, value = np.loadtxt("PLANT.CSV", delimiter=",", unpack=True)
hours = time / 3600.0
# ---- 1) the raw curve over 24 hours ----
plt.figure(); plt.plot(hours, value)
plt.xlabel("Hours"); plt.ylabel("Signal"); plt.title("24-hour recording")
# ---- 2) subtract the trend so the FFT can see the rhythms ----
value = value - np.polyval(np.polyfit(hours, value, 1), hours)
# ---- 3) Fourier transform ----
dt = np.median(np.diff(time)) # seconds between two measurements
freq = np.fft.rfftfreq(len(value), d=dt) # in cycles per second
strength = np.abs(np.fft.rfft(value))
period_h = 1.0 / (freq * 3600.0 + 1e-12) # period in hours
# only look at rhythms between 2 and 48 hours
m = (period_h > 2) & (period_h < 48)
plt.figure(); plt.plot(period_h[m], strength[m])
plt.xlabel("Period (hours)"); plt.ylabel("Strength")
plt.title("Where does the plant tick?"); plt.axvline(24, ls="--")
print("Strongest rhythm at",
round(period_h[m][np.argmax(strength[m])], 1), "hours")
plt.show()
What you should see
In the raw curve often a gentle rise and fall over the day. In the spectrum, ideally a clear peak near 24 hours — sometimes an additional one at 12 hours (a "half" rhythm). If you find no peak, that is also a result: perhaps the contact was too restless, or this plant doesn't show it in the electrical signal.
Worksheet
Reading your internal clock
- At which period is the strongest peak in your spectrum? How close to 24 hours is it?
- Why do we subtract the slow trend before the FFT (the line with
polyfit)? What would happen if we didn't? - Can you find, in the raw curve, the place where it got dark in the evening? Describe how.
- A neighbouring group measures the same plant species but finds no 24-hour peak. Name two technical reasons before you conclude "the plant has no clock".
- The circadian rhythm keeps running even under constant light. How could you test that (roughly) with your setup?
Show solution
1. Individual. A value between about 22 and 26 hours counts as "circadian" — a biological clock is never exactly 24.0 hours.
2. Over 24 hours the baseline often drifts slowly (the contact dries, the temperature changes). This trend is itself a very slow "oscillation" and would outshine the spectrum at large periods. Subtracting it makes the real 24-h beat visible.
3. Usually a kink or a shift of the baseline at the known evening time — that is exactly why you noted the start time. That way you anchor the curve in real time.
4. For example: electrode contact lost overnight, too few/too noisy data, the plant wasn't at the window (no real light change), or the trend wasn't cleanly subtracted. Only once the technique and control are right is the biological statement allowed.
5. You would let the plant run a second 24-h round under constantly equal light (curtain drawn, constant lamp). If the ~24-h beat persists anyway, it is really "internal" and not just a direct response to daylight.
When it sticks
| Problem | Likely cause & fix |
|---|---|
| Curve breaks off in the middle of the night / goes flat | Electrode contact lost or power gone. Press the gel pad on better, fix the cable, secure the power supply, and repeat the night. |
| Spectrum shows only one peak far to the left (very long period) | The trend wasn't subtracted — the slow drift outshines everything. Check the polyfit line. |
| Many peaks, none clearly at 24 h | Too much noise. Average over more readings, extend the recording over several days (more cycles = a clearer peak). |
| CSV won't load | Check the separator (comma vs. semicolon), remove the header row, adjust delimiter. |
Food for thought
- The FFT is a fine example of mathematics helping you see: a rhythm the eye never spots in the jittery raw curve becomes visible as a clear bar. Tools extend our perception — that is the heart of AI and data analysis at once.
- Here too the control question holds: a peak at 24 h could also come from something in the room that fluctuates on a daily beat — temperature, mains voltage, vibration from the day's routine. Only the experiment under constant light (question 5) separates a real internal clock from mere surroundings.
- That plants have an internal clock is well established — this experiment is among the most reliable in the whole workbook. It is a good counterweight to the more open questions from 11.4: not everything about plants is speculation, some of it is solidly measurable.
Extension
- Multi-day measurement: record for three to four days. The more cycles, the sharper the 24-h peak — and you see whether the beat stays stable.
- Constant light: actually carry out the control from question 5. If the rhythm persists without a day–night cycle, you have measured "free-running" circadian rhythms — the heart of chronobiology.
- Compare two plants: record two species at once. Do they tick on the same beat? Is one more "punctual" than the other? That turns a measurement into a small research project.
Appendix: the logging sketch
Averages fast measurements into one calm value every 5 seconds and writes it with a timestamp. Here is the Serial-Monitor variant (laptop runs through); the SD-card variant is on GitHub.
/* 24-hour logger - Hidden Signals, Activity 13.1
Averages ~250 measurements into one value every 5 seconds.
Output: "seconds,value" - have the Serial Monitor record it
or (SD variant on GitHub) straight to the card. */
const int SIGNAL_PIN = 34;
const unsigned long INTERVAL = 5000; // 5 seconds
void setup() {
Serial.begin(115200);
analogReadResolution(12);
Serial.println("seconds,value");
}
void loop() {
long sum = 0; int n = 0;
// measure and average for the whole 5 seconds
unsigned long start = millis();
while (millis() - start < INTERVAL) {
sum += analogRead(SIGNAL_PIN);
n++;
delay(20);
}
int mean = sum / n;
unsigned long sec = millis() / 1000;
Serial.print(sec); Serial.print(","); Serial.println(mean);
}