My DIY smart garden project for small plants — Arduino script included

Korawich Kavee
6 min readAug 22, 2022

--

I actually posted online on some social network and put the code on my GitHub before. To make sure things I have done can replicated and also just for the sake of documenting myself, this article will guide you, who is either tech geek or just looking for a way to make an automatic plant watering system, from getting the material to wiring and writing a code.

This is my garden current setup which might look a bit different from what I post on LinkedIn or twitter.

Let’s begin with how did I start all this. I got green onion (AKA Spring onion that’s what Australians call it, AKA ต้นหอม in Thai), basil (Sadly, No it’s not Thai basil, but still possible to do Phat kaphrao), and coriander (ผักชี). I found that a youtuber and fellow engineer Grady Hillhouse from Practical Engineering did something similar to what I intend to do (Arduino Garden Controller — Automatic Watering and Data Logging — YouTube). The problem is the scale: his garden is in a backyard outdoor lawn, but mine is small and indoor, and that is where the modification begin. In other words, this project is perfect for you if you just have a flower in a plant pot but often forget to water it.

For the wiring on the breadboard, there are 3 circuit (2 overlapping each other + 1 of I2C), and 2 source of electricity. The first circuit is 12 V for the pump I used, the second circuit is a parallel (not really) of the CdS light sensor (powered by my Arduino 3.3V pin) and a LED to go to a transistor (that is controlling the water pump like a switch from digital pinout) . The I2C is for the soil sensor. You might also notice I have a data logging shield stacking on my Arduino with a SD card.

Here are the list of apparatus for this section.

The circuits in this project — quick hand draft.

I put it separate in a box with lid to prevent water. Speaking of water, I have water source which is just a Starbuck Venti cup raise higher from the plant pots (The higher, the better fluid flow according to Bernoulli Equation). The silicon tube then got split into 4 (which is not necessary if you have just a 1 pot of plant). In fact, I encourage you to do 1 pump to 1 outlet if your have the money, because the water sometimes does not flow thought all outlet as intend due to small push (that’s why I raise the water source as high as possible)

You can also be a plumber and connect clean water pipe with — Plastic Water Solenoid Valve — 12V — 1/2 Nominal : ID 997 : $6.95 : Adafruit Industries, Unique & fun DIY electronics and kits — which is what Grady intend before I modified the plan.

Once everything is assembled, let’s start playing with the code. The full script is here in The “test04” folder of korawichkavee/SmartGardenSmallPlantArduino (github.com). Most of the code are taken from manufacturer tutorial and documents. (Please read the manual!) There are some adjustment you will likely have to make — especially Calibration and conversion

Some of you just want to automate watering without any logging. If this is what you want, just do it without logging shield and delete any logfile print in the code. Also, you might want just the record of time pass not the actual real world clock. You can also do it without any clock hardware. But if you insist on the logging like me, I have some warning and please heed, the delay function may look useless, but without them, the new file might get created more than you intend, like it took sometime to warm up before finishing the first iteration for some reason. This Arduino phenomenon is still a mystery to me. The file is CSV and as nature of CSV, use comma to mark new column. The “println” makes new line.

RTC_PCF8523 rtc; // define the Real Time Clock object
DateTime now;
// for the data logging shield, we use digital pin 10 for the SD cs line
const int chipSelect = 10;
// the logging file
File logfile;

Light sensor datasheet will help you figure how much R you should use for your sunlight exposure. Use your smartphone with some LUX measuring app to do some linear regression.

photocellReading = analogRead(photocellPin);  
sunlight = photocellReading*0.8269-80.846 ; //LUX
delay(20);

Adafruit soil sensor can measure temperate just fine, but I cannot say the same for moisture. If you are doing not for fun but other serious business, get a better soil sensor! I start calibration by poking it into super dry soil, note the reading, then add water a bit, do this until it is full of water like dirt water. Then assign value with 100 as a maximum.

//Collect Variables
float soilTemp = ss.getTemp();
delay(20);

float soilMoisture = ss.touchRead(0)*(-0.0683) + 80.512;
delay(20);

The condition here works for my garden. You can also change the timing to suit your garden and water resource. Think about how many times do you want to water each day? or how much (or how long of the duration) should the system water each time.

if ((soilMoisture < wateringThreshold) && (wateredToday < 3 ) && (sunlight > 150) && (now.hour()- recent_water_h > 4 )) {
digitalWrite(pump,HIGH); //turning on
delay(60000); //milliseconds
digitalWrite(pump,LOW); //turning off
recent_water_h = now.hour();
//record that we're watering
++wateredToday;
}

To wrap up, everything should work out just fine if you can find the material & read some datasheet. If it doesn’t work, reply to this article and I will see if I can help. Follow me on Medium please. I want 200 followers on Medium.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Korawich Kavee
Korawich Kavee

Written by Korawich Kavee

{+Youtube} เขียนเกี่ยวกับคมนาคม การพัฒนาเมือง เมืองอัจฉริยะ ระบบขนส่ง โครงสร้างพื้นฐาน การสัญจรด้วยเท้าและจักรยาน GIS โยธา ผังเมือง เรียน/อยู่/เที่ยวต่างประเทศ

No responses yet

Write a response