Nia and the Midnight Watering Mystery
The first clue was a puddle where no puddle ought to be.
At half past seven on Saturday morning, Nia unlocked the community greenhouse with her grandfather, Pops. Warm, leafy air wrapped around them. Tomato vines climbed their strings, beans curled around bamboo poles, and drops of water shone on the glass roof.
But beneath the strawberry table, the floor was wet enough to reflect Nia’s yellow trainers.
"The watering system ran at midnight again," said Pops. He rubbed his grey beard. "That is three nights in a row."
Nia crouched beside the nearest soil sensor. A green wire ran from its two metal prongs to a small computer in a clear box. The computer was called a microcontroller. It read the sensors and switched the water pump on or off.
"Maybe the plants were thirsty," Pops suggested.
Nia pressed one finger into a pot. The compost squelched. "They are not thirsty now."
On Monday, the greenhouse would host its summer open day. The strawberry plants needed care, but another midnight soaking could rot their roots and waste a tankful of rainwater. Nia opened her investigation notebook.
Mystery: Why does the pump run when the soil is already wet?
Suspects: the pump, the sensor, or the code.
She drew three empty boxes beneath the list. "We test one thing at a time," she said. It was something her coding club leader often repeated.
First, Nia tested the pump. Pops disconnected it from the watering tubes and aimed it into a bucket. Nia pressed the manual button.
Whirr. Water rushed into the bucket.
She pressed stop. The water stopped.
"The pump obeys," said Pops.
Nia ticked the first box. Next, she checked the sensor readings on the greenhouse tablet. Most beds showed numbers between 65 and 78 per cent. The strawberries showed 14 per cent.
"Fourteen means dry," said Nia. "But the compost is wet."
Pops fetched a spare sensor. They placed both sensors in the same strawberry pot. The old one reported 14 per cent. The spare reported 72 per cent.
"Caught it!" Pops cried.
Nia nearly ticked the second box, but then she paused. A broken sensor explained why the computer thought the soil was dry. It did not explain why the pump always started at midnight.
"One clue is not the whole answer," she said.
They followed the green wire to the clear computer box. Inside, a tiny amber light blinked like a patient firefly. Nia opened the watering program on the tablet.
The code used a condition:
If the soil reading is below 30 per cent, turn on the pump.
That made sense. A condition lets a program choose what to do. If something is true, the computer follows one path. If it is false, it follows another.
Below it, Nia found a loop:
Every 24 hours, check the soil.
A loop repeats an instruction. This loop had been started when Pops installed the system at midnight on Tuesday. Twenty-four hours later, it checked again at midnight on Wednesday. Then midnight on Thursday.

"So midnight is not magic," said Nia. "It is just the starting time repeating."
"Two clues," said Pops. "Faulty sensor and awkward schedule."
Nia still did not tick the final box.
"Let us prove it," she said.
They replaced the faulty sensor and changed the loop so the system would check every hour. They also added a rule that watering could happen only between six and eight in the morning. Nia saved the program and waited.
At eight o’clock, the pump did not run.
At nine o’clock, it did not run.
At ten o’clock, the strawberry reading suddenly fell from 71 per cent to 9 per cent.
The pump did not run because it was outside the allowed time, but Nia’s stomach gave a worried flip.
"The new sensor cannot have dried in an hour," she said.
She checked the pot. Still damp.
Pops frowned at the green wire. "Could two sensors be broken?"
"Possible," said Nia, "but not likely."
She traced the wire under the table. It passed beside a small ventilation fan. Every time the fan turned, its cable brushed the sensor plug. Nia watched it happen once, twice, three times.
On the third turn, the plug slipped halfway out. The reading dropped to 9 per cent.

"There is our sneakiest suspect," she said.
The sensor was healthy. The loose connection made its message unreliable.
Nia clipped the plug firmly into place and tied the fan cable away from it with a reusable fabric strap. Then she added one more condition to the program:
If a reading changes by more than 40 points in one hour, do not water. Send an alert for a person to check.
"Why not let the computer decide?" Pops asked.
"Because a strange reading could mean dry soil, or a loose plug, or something we have not imagined," said Nia. "The computer only follows the rules we give it."
Pops smiled. "And good rules know when to ask for help."
They tested the program with pretend readings. Nia entered 70, then 55. The system waited. She entered 25 during the morning watering window. The pump ran for two minutes and stopped. Then she entered 72 followed by 9. The pump stayed quiet and an alert appeared.
Please check strawberry sensor.
This time, Nia ticked all three boxes.
On Sunday morning, she returned with Pops to inspect the results. The floor was dry. The water tank was nearly full. The strawberry leaves stood bright and crisp, and every sensor showed a believable reading.
Nia opened the program’s log, which was a record of what the system had done. Each hourly check had a time beside it. At six o’clock, the soil was damp, so the pump stayed off. At seven o’clock, the same. At eight o’clock, the same.
"No mystery watering," said Pops.
"No magic either," Nia replied.
Just then, a ripe strawberry dropped from its stem and landed neatly in her open notebook.
Pops raised his eyebrows. "That looked a little magical."
Nia laughed. "I will allow one unexplained strawberry."
At Monday’s open day, visitors gathered around the clear computer box. Nia showed them the sensor, the pump, and the corrected program. She explained how she had found one problem, kept testing, and discovered another.
"Was the first code bad?" asked a younger boy.
"It did exactly what it was told," Nia said. "But the instructions did not cover a broken connection or a better watering time. Debugging means finding out why something behaves differently from what you expected, then improving it."

She handed him the investigation notebook. The last page held a new checklist:
Observe. Predict. Test. Change one thing. Test again.
Outside, rain began tapping softly on the greenhouse roof. The soil sensors climbed a little at a time, just as Nia expected. She watched the numbers, listened to the rain, and felt the pleasant calm of a mystery properly solved.
Facts from Nia’s investigation
- A sensor measures something in the physical world, such as soil moisture, light or temperature, and sends a reading to a computer.
- A microcontroller is a small computer that can read inputs from sensors and control outputs such as pumps, lights or buzzers.
- A condition tells a program to act only when a statement is true.
- A loop repeats instructions. The timing and starting point of a loop affect when it runs.
- Debugging is the process of finding and fixing the cause of unexpected behaviour.
- One surprising reading is evidence, but it is wise to check the sensor, its connection and the surrounding conditions before acting.