Cart 0

Developing the Solar Soil Sensor

Posted by Matthew Little on

My houseplants have been dying due to a mixture of over and under watering. So I thought something to help stop that would be good. And even better if it's solar powered.

I've been working with a solar powered ATTiny85 for the Solar 8 Ball and Solar Dice kits and thought I could use the same basic circuit to implement a solar powered moisture sensor.

So I came up with the Solar Soil Sensor. This blog post highlights some of the design decisions and how I implemented everything.

Moisture Sensing

The first this was to figure out a good way of measuring soil moisture.

There are two main camps of simple sensor for this, either resistive or capacitative.

Resistive sensors use the soil as one half of a potential divider. So the resistance of the soil affects the output voltage.

The main problems with this are that the sensor uses a small current all the time, which trickles through the damp soil. This affects energy consumption.

This small current will also cause degradation of the sensor due to a slight electro-chemical reaction. So resistive sensor contacts either need to be made from something relatively inert (like gold) or replaceable or we can control the power to them to reduce the electro-chemical corrosion.

Capacitative sensors look at the variation in capacitance between two electrodes in the soil. This should not cause any electro-chemical effects, so the sensors should last quite a while. The main issue is that the system needs to have a good ground, so that the capacitance value does not vary. This is difficult to do when powered from a small remote circuit, with no connection to the earth of a large power network.

I did try to implement capaciatative sensors, but had way too much variation and noise on the sensors, especially when not connected to the programming computer.

So I implemented restive moisture sensing, but with power control through an additional controlled transistor. So I can totally shut down the restive sensing when I want. This will save energy (which is really needed for this solar circuit) and also protect the electrodes. In code I can now wake up every 2 seconds or so, apply power for around 0.1 seconds then switch off again. So any electrodes should last 20 times longer that electrodes powered continuously.

Inputs and Outputs

The ATTiny85 is limited to just 8 pins, with only 6 IO pins, of which one is tied to the reset, so I try not to use that one.

I needed to have:

  1. Soil resistance measurement (analogue)
  2. Soil resistance power control (digital)
  3. LED (digital)
  4. Buzzer (digital)
  5. Input switch (digital)
  6. Solar voltage measurement (analogue)

This is one more that I can easily have!

So to get around this I decided to implement the switch and the LED on the same digital pin. The switch will pull the pin down (if in input mode) and the LED is between the pin and +5V. The LED will be controlled on/off if in output mode, with High being Off and Low being On.

This worked really well, but we do need to change the input/output modes depending on what we want to do. Also, when the switch is pressed then the LED will be On. This is actually OK, as it gives visual indication of the pin being pressed. I then use the buzzer to feedback different things.

All the other inputs and outputs are implemented as single use pins. Power for the restive soil sensor is through digital control of a simple NPN transistor.

Energy Stored in Capacitor

I am trying to avoid using batteries (either rechargeable or single use) in these kits. Using a rechargeable battery makes sense when the item needs quite a large energy store, but it adds complexity to the circuit, usually requiring a specific charging circuit.

So I am using ultra-capacitors to store small amount of energy. These are capacitors with very high surface areas and hence can store much more than a 'normal' capacitor. I use 0.47 F capacitors (where a Farad, F, is a measure of capacitance). This does not sound like much, but most normal capacitors are around 1-100 micro farads, which is 0.000001 to 0.0001 F.

The energy stored (in Joules) in a capacitor is calculated from the equation:

E = 1/2 C V^2

One Joule is 0.000277778 Wh. I convert to Wh, as this is easier for my electrical energy calculations.

So, say we charge the capacitor to 4 V the 0.47 F capacitor will store 3.76 J or around 0.001 Wh. Not much! But OK for powering simple sensors if we are careful about using it.

Note: We are actually charging to 5 V, but this will drop as the energy is used, so I'm using a lower average.

The ATTiny85 microcontroller can be put into sleep mode where is will consume around 0.5 micro-A, which is around 2.5 micro-W. So if just asleep then the 0.47 F capacitor can power the ATTiny85 for around 400 hours!

If we run a 5mA LED then this value is greatly reduced... The LED uses, at 4V, 0.02W, so the 0.47 F capacitor can only run the LED for 3 minutes!!

We need to use clever tricks, like putting the unit to sleep and flashing the LED briefly, to ensure we use as little energy as possible.

PCB design

I've designed a nice PCB for this and got a few prototypes made. They have come back looking really nice!

I produced the board outline in InkScape and then used the information from this edition of Hackspace Magazine ( to create the component in KiCAD.

ATTiny85 Programming via Arduino

There are many articles and posts about programming the ATTiny85 through the Arduino IDE. These are my notes or what worked for me:

A lot of my original experiments are blogged here:

There are a couple of different ATTiny cores for programming via the Arduino IDE.

I used a couple and found this one gave me the best set of options: 

We include this URL in the Arduino File -> Preferences -> Additional Boards URL.

This was done in May 2020 with Arduino IDE Version1.8.12, so things might be different for you.

Circuit Design

Here is the final circuit design (after a few iterations of prototypes). This is available as a .pdf here.

Source Code

The source code (along with the PCB design and insturctions) is available in this Github repository:

Whats next?

So I have got a few samples of the PCB and put together some kits of parts. These have been sent to five 'beta testers' who are looking at how it goes together and if it works. From their feedback I hope to update and release a product....


Share this post

← Older Post Newer Post →

Leave a comment

Please note, comments must be approved before they are published.