Saturday, September 19, 2015

Daylight Logger for Gardening

While I don't much like to garden personally, a certain someone really wanted to improve my landscaping as well as grow a variety of vegetables and herbs and whatnot.  As we shopped for various plants and seeds I took note of the sunlight requirements listed on each.  Generally it was a qualitative statement such as "Full Sun" or "Partial Shade".....  Well what does that really even mean?   Being the engineery kind of guy that I am I needed something more quantitative.  So a quick internet search while at the store yielded answers as such:

Full Sun = 6 or more hours of direct sunlight daily
Partial Sun/Partial Shade = Between 3 and 6 hours of direct sunlight daily
Full Shade = Less than 2 hours of direct sunlight daily

However, the more reading you do on certain plants you find that while six hours may constitute the minimum requirement if you will, many plants will do better with even more sunlight.  And all of this kind of begs more questions: what about the variations in amount of shade?    Are these aggregate amounts of sun daily? (and from what I've figured out, yes)  Is sunlight at certain times better than others?  But most importantly, what kind of sun do I get in my yard?

I live in a neighborhood with many old and massive oaks.  While the neighborhood is by no means new, when built they did a good job of leaving many of the existing trees.  So areas of the yard that may be next to the sidewalk and nowhere near a tree might get lots of morning shade due to the oaks behind the neighbor across the street.  Then late morning and afternoon sun.  Then late afternoon shade.  Then early evening sun.  Just from observation working outside or mowing the lawn I've noticed that the amount of sun can swing both directions several times throughout the day.  It'd be interesting to find out how much.....  Especially if I want optimize my planting (and yes, normal people don't "optimize" their gardens, nor is the effort likely worth it).

The Project:
Where to start.  Basically, we need to measure the sunlight a bunch of times over an interval, say one complete day.  We then must store those measurements and then be able to recall them for consumption later.  This will also have to run off of batteries and be resilient to weather.  That should pretty much cover it.
Sunlight Detection:
Measuring the sunlight won't be all that much different than the IR detector used in the Virtual Whammy Bar.  Instead of a narrow spectrum detector though, we'll use an ambient light sensor.  This is more or less the same idea as an IR photo sensor except its response resembles our ability to see light.  I believe such devices are used to automatically turn on the head lights in newer cars when it gets dark.
That's the fundamental circuit.  It'll have to evolve going forward, but functionally it will remain the same.  I probably could do away with the buffer on this one,  Our ambient light sensor sources quite a bit of current.

Memory:
The memory chip will be a Microchip 24AA08.  Why?  Because I had a couple.  It's a whopping 1KB, though marketed as 8Kb (B = bytes, b = bits).  At least the 1K actually equals 1,024.  I had larger memory, but it was SRAM instead of EEPROM.  It does have a 1uA standby current, which is convenient for our battery powered circuit.  The I2C interface is handy too as I have to manually bit-bang the protocol.

ADC/Microcontroller:
We'll actually be using the internal ADC of the microcontroller, which is a Microchip PIC12F1572.  I showed it separately only be cause it needs a little consideration.  Since our circuit will be battery powered, the circuit voltage will vary over the life of the batteries, which means we can't use our circuit power as the ADC's positive voltage reference.  Fortunately the micro contains a fixed voltage reference module.  By manipulating the appropriate registers you can get a 2.048V reference, which can also be connected to the ADC module.  I'm taking a guess that the light sensor is less dependent on the applied voltage as it is to the applied light, as its response is to allow current flow.  Truthfully, I don't know the actual part number of the ambient light sensor, but some datasheets I've looked into support my conclusion.  But regardless of the voltage from the batteries, the ADC will always measure the incoming light based on a 0 to 2.048V scale.

Our microcontroller does all of our grunt work.  It will schedule when to take light measurements, store the results in the memory, and communicates via a serial port with a PC.  It'll perform a few other functions we'll discuss later, but these are it's core responsibilities.

In the next post I'll show the resulting circuit and discuss more details of the design.