Mission
Build this
Build a fixed photoresistor observer that publishes local relative light, marks persistent dawn and dusk, and patrols only in trusted darkness.
Borrowed parts are labelled below and have a fallback. The registered device ID is fixed; sensing and behaviour decisions remain yours.
Bill of materials
Parts
| Source | Part | Fallback |
|---|---|---|
| ● kit | Photoresistor | — |
| ● kit | 10 kΩ resistor | — |
| ● kit | SG90 servo | — |
Disconnect USB before rewiring. Motors, the relay, and the servo need appropriate power and a shared ground. Never drive an actuator from the ESP32 3V3 pin.
Your invitation
Build a patient observer of beginnings and endings
The Night Watchman spends most of its life doing very little. It samples light, waits through clouds and shadows, marks a defensible dusk, patrols after dark, and waits again for dawn.
One bright reading is not sunrise. One shadow is not night. The intellectual work is teaching the device to recognise a transition that persists, then admitting when a restart or missing data makes the day incomplete.
Stillness is part of the behaviour. A watcher that moves all day has stopped explaining the light.
The central idea
Day length is made from two trusted transitions
Patrol slowly while the dark state remains trusted.
Record the time only after brightness persists.
Remain still and keep sampling.
Record the second trusted transition.
Day length is the elapsed time from accepted dawn to accepted dusk. Publish it only after both belong to the same complete observation. The first partial day after startup may not produce a day length at all.
Learn the sensor’s private language
Your percentage is a local scale, not a lux meter
A photoresistor changes resistance with light. Together with the fixed resistor it forms a voltage divider. In this wiring, brighter conditions usually produce a higher ADC reading, but component variation and placement make the exact numbers local to your device.
Temporarily cover the sensor without pressing it.
Record the installed device under a bright daytime scene.
Map between documented references and clamp values beyond them.
The garden contract names it light-level in percent. True illuminance in lux needs a calibrated light instrument and a different claim.
Wiring
Fix the eye before deciding what it sees
Mount the photoresistor where the servo, indoor lamps, and the ESP32’s own indicators cannot flash across it. Prove stable raw readings before adding the night patrol.
The power rule: The complete photoresistor divider uses 3V3 and GPIO 34. The servo uses a separate 5 V supply. Join all grounds.
Bench referenceOpen the exact wiring map
| ESP32 pin | Part | Part marking | Carries |
|---|---|---|---|
3V3 | Photoresistor | one leg | 3V3 power |
GPIO 34 | Photoresistor | other leg | Analog voltage — divider junction |
GPIO 34 | 10 kΩ resistor | one leg | Analog voltage — same divider junction |
GND | 10 kΩ resistor | other leg | Ground |
GPIO 18 | SG90 servo | signal (orange) | PWM to actuator — slow night patrol |
external 5 V | SG90 servo | power (red) | 5V power — separate supply |
GND | SG90 servo | ground (brown) | Ground — join servo and ESP32 grounds |
Never expose an ESP32 analog pin to 5 V and never power the servo from 3V3. Disconnect USB before rewiring and protect greenhouse joints from moisture.
- 3V3 power
- Analog voltage
- Ground
- PWM to actuator
- 5V power
With the photoresistor above the junction and 10 kΩ resistor below it, brighter light normally raises the reading. If your physical divider is reversed, document that brightness runs in the opposite direction.
Give twilight room to be twilight
Use two boundaries and a little patience
Choose a lower boundary for entering night and a higher one for returning to day. Then require the candidate state to persist. Clouds may cross the band without inventing dusk; a nearby lamp may cross it without inventing dawn.
Your team decides:
- Which three candidate boundary pairs will you compare?
- How long must a candidate dawn or dusk persist?
- What delay is acceptable in exchange for fewer false transitions?
- How does the device mark an incomplete day after a reboot?
Your twilight study
Replay one transition, then wait for the sky
- Record raw light through a real or staged transition.
Keep one-minute samples with times. A slowly uncovered lamp can rehearse the method; outdoor data remains the final test.
- Evaluate three candidate boundary pairs.
Run the same record through each pair without changing the data.
- Add persistence.
Count false transitions and measure how many minutes the accepted dawn or dusk is delayed.
- Observe one complete day when possible.
Keep the device fixed. Record missing samples, restarts, nearby lighting, and whether both trusted transitions were captured.
| Rule | Night boundary | Day boundary | Persistence | False transitions | Delay |
|---|---|---|---|---|---|
| A | ___ % | ___ % | ___ min | ___ | ___ min |
| B | ___ % | ___ % | ___ min | ___ | ___ min |
| C | ___ % | ___ % | ___ min | ___ | ___ min |
When night arrives at the wrong hour
Look for shadows, lamps, clocks, and missing memory
A cloud creates an early dusk
The boundary is too close or persistence too short. Compare the recorded dip with your twilight candidates before changing the rule.
A greenhouse lamp creates dawn
The sensor sees local light, not the sun. Reposition or shield it, and document whether the project measures outdoor photoperiod or the greenhouse lighting schedule.
The servo changes the light reading
The patrol arm casts a shadow or moves a reflective surface. Separate the field of view and ignore no data until the physical cause is addressed.
Day length appears immediately after restart
The device is combining an old transition with a new one or inventing a start time. Mark the day incomplete until a valid dawn and dusk pair is observed.
The sensor reaches 0% or 100% for hours
The reference range may be too narrow or the ADC may be saturating. Preserve raw readings and revisit the installed references.
Choose your night question
What kind of watch team will you become?
The twilight judges
Compare candidate boundaries and persistence periods. Make false transitions and delay the centre of the study.
The placement astronomers
Map shadows, artificial light, reflections, and viewing direction to decide which “day” the device actually observes.
The patient historians
Collect several complete days, preserve incomplete ones, and ask whether the measured day length changes beyond ordinary timing uncertainty.
A calm way through the build
Collect four small wins
nw-01says hello.Join the garden before waiting for night.
- Raw light has covered and daylight references.
Fix the sensor and publish a labelled percentage.
- One replay creates one dawn or dusk.
Add two boundaries, persistence, and transition memory.
- The patrol belongs only to trusted darkness.
Add separate servo power, then begin the complete-day observation.
The garden handshake
Share what you found
These names are the rigid part of the project. They let another team find your work without knowing what you called the variables in your code.
Local relative light
garden/greenhouse-2/night-node/nw-01/light-levelUnit: percent
Completed day length
garden/greenhouse-2/night-node/nw-01/day-lengthUnit: minutes
Listen beyond your own device.
garden/greenhouse-1/climate-node/gm-01/temperatureJuliet temperature can provide context for unusual transitions and seasonal change. It does not repair missing light data or decide whether your dawn rule was correct.
Finish line
Ready to introduce to the garden
nw-01 stays online and publishes relative light every minute plus day length only after a complete observation.
The reject feed stays clear after the final code starts.
The device reads Juliet temperature as context without using it to invent light transitions.
The servo remains still in trusted daylight and patrols slowly in trusted darkness without blocking messages.
The build log contains installed references, raw transition data, three boundary pairs, persistence delay, false transitions, missing-data handling, and one placement limitation.
The sensor is fixed and shielded from self-made light or shadow, the servo is safely powered, greenhouse wiring is protected, and the label can be scanned.
The Night Watchman earns its title by waiting well. Its most convincing result is not a dramatic patrol, but a day length built from two transitions it had good reason to trust.