Automated plant watering with Arduino

Lead Image © Richard Laschon, 123RF.com

Talking Plants

House plants are fairly self-sufficient, but they do need certain care from people to survive. With a few Arduino sensors and a little programming, you can take the guesswork out of watering your plants.

House plants can provide a little corner of peace and tranquility and give a living space a more cheerful feel. However, after plants are taken from their natural environment, they need certain help to be able to survive and stay healthy: watering, light, nutrients, and so on.

With the goal of keeping your plants from dying because of neglect or simply because you forgot to water them, I'm going to focus in this article on using Arduino to design systems that allow you to understand better what your plants feel and, at the same time, make gardening a simpler task.

Controlling the Timing: RTC

Getting your Arduino to water the plants on time will require some attention to a very important programming topic: time control. With these skills, you won't be able to travel to the past in a DeLorean, but you will be able to control which day and at which time a specific action will be carried out. This setup will allow you to establish a specific schedule for watering your garden.

To accomplish this, I'll turn to a device that lets Arduino know the day and the hour at which the code is being run. Its name is RTC [1], the Real-Time Clock, which is a computer clock that communicates with your Arduino by means of a protocol not used in this project until now. Thanks to a little button battery and a few dollars, your Arduino can keep time even when you haven't powered it on.

As shown in Figure 1, only four wires are needed to connect the Arduino. The I2C is a serial bus communication protocol accessible in Arduino via analog input pins 4 and 5, corresponding to the SCL pins (clock line) and SDA pins (date line). The other pins are supply and ground.

Figure 1: The RTC module supplies the date and time.

Thanks to Arduino's OneWire library, working with the I2C protocol isn't going to be difficult. You don't need to understand it in depth, because it involves a simple serial bus based on the master/slave structure, but when I describe the programming later, you'll see its function in greater detail.

Monitoring the Temperature

For a second example in this article, I'll need to use sensors that provide data about the status of the plants. The temperature and humidity sensors used in other situations, won't work here. Keep in mind that the sensors need to work in special conditions, because I'll be measuring these parameters inside the pot or in the soil. For this, I'm going to use the probe shown in Figure 2: a digital temperature probe [2] specially designed to work in these adverse conditions.

Figure 2: Ground temperature-measuring probe to use with 1-Wire.

The only snag with this sensor is that it doesn't function as a normal digital sensor unless a protocol called 1-Wire is used. The interesting thing about this protocol is that it lets you use multiple sensors connected at the same time to only one digital pin.

I'm going to use only one sensor, which has three pins: supply, signal, and ground. In terms of hardware, I'll connect it as if it's going to interface with another digital sensor, supplying it with 5 volts and with the signal connected to a digital Arduino pin. The only difference is that it's going to be necessary to place a 4k7 pull-up resistor between 5V and signal to power the device correctly.

However, with software, it's a different story. I need to communicate with the sensor in a specific way, and for this I'll use a combination of libraries for Arduino that let me communicate with devices by way of the 1-Wire protocol.

You'll need to download two libraries. The first is called OneWire [3], which permits Arduino to establish communication with devices designed to function with the 1-Wire protocol. The second library is DallasTemperature [4], which makes the exchange of information between devices via the 1-Wire protocol simpler and friendlier to use.

To work with these libraries, you just need to download, extract, and rename them OneWire and DallasTemperature. Once you're ready, you can copy them to the libraries folder that you'll find in Arduino's IDE. Once you've completed this process, you can see upon opening the IDE that the two new libraries have been added.

Listing 1 shows how easily you can call up the temperature on the probe and print the result to the serial monitor. The only thing left is to create a class to work with it in code, as from a servo, using already-defined functions in the library that calls up the data on the sensor.

Listing 1

Measuring Temperature with 1-Wire Protocol

01 // Include the library to establish communication by means of 1-Wire protocol
02 #include <OneWire.h>
03 // Include the library to communicate with the sensors
04 #include <DallasTemperature.h>
05
06 // Define the Arduino pin that will be used with 1-Wire protocol
07 #define ONE_WIRE_BUS 8
08
09 // Create a "oneWire" class to work on the designated pin
10 OneWire oneWire(ONE_WIRE_BUS);
11
12 // Pass the data from the 1-Wire protocol to the Dallas library in a new class
13 DallasTemperature sensors(&oneWire);
14
15 void setup() {
16   // Initialize the serial port
17   Serial.begin(9600);
18   // Start message
19   Serial.println("Temperature request example");
20
21   // Initialize the 1-Wire protocol and the sensor
22   sensors.begin();
23 }
24
25 void loop() {
26   // Query the temperature of the device
27   Serial.print("Requesting temperature...");
28   sensors.requestTemperatures();
29   Serial.println("");
30   // Print the temperature value
31   Serial.print("The plant's temperature is: ");
32   Serial.println(sensors.getTempCByIndex(0));
33 }

Buy this article as PDF

Express-Checkout as PDF

Pages: 6

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content