Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Spring Time With Arduino

DZone's Guide to

Spring Time With Arduino

Spring is here, which means gardeners are getting to work. Make your life easier by implementing your own moisture sensor and water pump controls.

· IoT Zone
Free Resource

Well, it’s spring, so it must be Arduino in the garden time!

Last year, I rigged up my small outdoor container garden to a bought (off-the-shelf) watering timer and a homemade hydroponics set up.

Update: I’ve posted my latest soil sensor sample code on GitHub here: https://github.com/adamfowleruk/arduinosamples/tree/master/soilsensor

After a bit of experimentation with pipe sizes and water flow, this proved really successful! After final construction, I had no further damage due to poor watering and had bumper crops of strawberries, tomatoes, and herbs – way too much for me to eat!

This year, it's time for an even more scientific approach! I’m going to control one container’s environment to try and give the plant the perfect amount of watering and nutrition. I’ll use another container as the ‘control’ on the standard watering system.

Happily, I have two strawberry containers, each with several plants in them. A number of plants should reduce the error of, say, one plant getting sick. I’ll measure the average number of strawberries per plant. (Measuring weight is a faff. Plus I tend to ‘steal’ strawberries on my way out to work in the morning. Chef’s perks! So no time to weigh them throughout the year.)

My strawberry plants are already prepped, so I need to create a strawberry environment management monitoring system.

So obvious things to monitor:

  • Moistness of the soil
  • Light level hitting the container
  • Temperature

Some less than obvious things we may want to measure eventually:

  • Humidity
  • Salinity of the soil/run off water
  • Measure the water level within the water reservoir (to prevent dry running the motor)
  • Current date/time (probably via a GPS receiver – I’m a cheat!)

Things we may want to do:

  • Turn a water pump on/off
  • Log all the data somewhere (even to the interwebs)
  • Turn a liquid feed pump on/off

First things first. Here’s what I need to build:

  1. Soil moistness sensor
  2. Water pump controlled by an Arduino
  3. All of the above working in a single unit

Phase 1: Moistness Sensor

This should be relatively simple. You can simply use an Arduino’s ADC to monitor the current between two wires places a few mm apart.

There are a couple of tutorials I know about for this. One is at SparkFun with its H20OhNo device, and here's another SparkFun one with their own soil moisture sensor, and one using a garden solar light as a base… Which I can’t seem to find now.

I have a potted plant in my home office (as you do), so I’ll just keep it simple and power the Arduino from my laptop and print the readings every few seconds to the serial on my Mac’s terminal.

I used the second SparkFun code as a base and had it up and running pretty quickly.

Hint: If you see 1023 constantly as your output value, ensure the analog pin (A0 in my code) is the one connected to the transistor’s emitter, and NOT the one connected to the input voltage and resistor!

In my setup, I saw around 450 when moist, and this spiked to 500 after a watering. This reading in my office's sunny windowsill drops every 10 seconds by about 4 as the top layer of soil dries out.

Phase 2: Control a Water Pump

I found a cheap DC submersible pump from Amazon.co.uk for £3.10 (well, from China, so it took a while to get here! But hey, it’s cheap and good!) that is USB-powered. My theory is that I can run it easily enough from a 5V line. Its input voltage is 3.5-9V, and it's rated at 1-3 W. It also tolerates being run dry – good for testing.

I’m hooking this up to two pint glasses (Hey, I’m British, of course it’s pint glasses!), one with the pump and a reservoir, the other empty for filling, connected by my irrigation hose.

This seems to work very well.

Hint: Play with the settings for the valve hidden on the side of the pump. If you can hear the motor strain but no water moves, the valve is shut! Open it fully (move the handle to the right).

In my testing, this thing can pump half a pint in 22 seconds. Not bad! It’s also pretty much silent.

Now to control it from an Arduino. My Arduinos are 3.3V, not 5V (because I’m a tart and was experimenting with a long-term, low-power usage kit) so this may present a challenge. Also, it’s rated at 3W, which, at 5V, is a max draw of 600mA, way more than the 40 mA an Arduino’s digital pin can provide.

This means I’ll have to set up another voltage line at 5V and control it from the Arduino. In the real world, I’m going to power the Arduino via solar energy with a battery backup. This means I can happily set up a SparkFun Sunny Buddy charger with a 5V Li-ion battery.

If you’re wondering how to connect a solar cell, battery, and load, check out this SparkFun tutorial.

After some testing, it appears that although a 5V 1A direct connection to a USB port can power the motor, the same is not true of the 3.7V 2000mAh 1C (Thus max 2A) battery I’m using. I’m going to have to use two batteries in parallel, which means I’ll have to remove the solar charger (as it’s designed for single cell charging only).

This means power usage is a big thing, but thanks to my previous work on minimizing Arduino power usage, I’m well-placed to address this.

I’ve ordered some bits to get my potted plant version working, so keep an eye out and I’ll post my progress!

I’ve had to order some more boards and bits and pieces for testing, so I’ll stick up the final design when I’ve figured it all out…

Topics:
iot devices ,iot development ,iot ,tutorial ,home automation

Published at DZone with permission of Adam Fowler, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}