Arduino-Based Automatic Watering System
Smart Greenhouse – Arduino-Based Automatic Watering System
With vacation time approaching, a decision needs to be made: either arrange for the neighbors to take care of your plants by giving them your house keys, or quickly come up with and build something akin to a “smart home.” More precisely, a “smart greenhouse” since we’re talking about plants. I’ll say right away that the neighbor option doesn’t appeal to me for several reasons, so I decided to dive into construction and modeling again. Like my previous DIY project, this one will be based on a cheap Arduino board, which I’ll program and connect to various peripherals.
After some online research, I quickly found several different watering system schemes. But honestly, I didn’t like any of them. They all seemed suboptimal to me, without going into detailed criticism. So, I decided not to copy existing solutions but to experiment and sketch my own concept. In general, it’s very simple: there’s a pump that turns on by a timer and supplies water to a flow divider. Each branch has its own valve, allowing you to regulate the water flow to individual plants or groups of them. That’s basically it. Ready-made watering timers for installation on pipes are quite expensive. My version, a customizable single-channel timer, will cost about as much as a meal at McDonald’s, and the firmware for the microcontroller is very simple. However, there is a small problem. The circuit is simple, but… it doesn’t interest me. Neither creatively nor functionally. It would be much more interesting and practical to set up a multi-channel watering system. Imagine, for example, that you have several greenhouses at your summer cottage for different types of crops, or one large greenhouse with several beds. The first bed has cucumbers, the second tomatoes, the third watermelons, strawberries, kiwi, or something else delicious. And all these plants require different watering regimes. Therefore, we need an irrigation system capable of scaling (I think from 1 to 15 pumps would be enough) with easy centralized control of each channel. Many people will find this useful for their country houses.
**Schematic Diagram of a Multi-Channel Automatic Watering System Using 5V Pumps**
**Wiring Diagram for 14 Relays Controlling the Pumps, Connected to an Arduino Board**
Having formulated the task, I set out to implement it. First, I bought several of the cheapest pumps operating at 5V. It would have been reasonable to use MOSFETs for power control, but that would require soldering an entire array of them—which anyone who has worked with such devices would know. To simplify things, I decided to use relays. Relays are great because you can power both the smallest pump (or a medium one, which, by the way, can be a windshield washer pump from an auto parts store) and a large pump running on 220V from the mains. You could, for example, install it in a well or borehole and pump water into the greenhouse.
For system setup, I used a character display and an encoder—an electromechanical device that converts the rotational movement of a shaft into pulses, allowing you to determine the direction and angle of rotation. The most common example of an encoder in everyday life is the volume control knob of a modern car stereo with digital control. And, of course, the “brain” of the device will be the Arduino board. All these components can be inexpensively purchased on AliExpress. Tip: order from one seller—your items will arrive in one package, plus you might get a discount, which is always nice.
**HOW TO UPLOAD THE FIRMWARE TO THE ARDUINO BOARD**
1. Download the archive with the necessary materials.
2. Install the libraries (Libraries folder) in C:\ProgramFiles\Arduino\LibrariesV.
3. Connect the Arduino to your computer using a data cable.
4. Open the desired firmware file (firmware files .ino are located in the respective folders of the archive).
5. Configure the Arduino IDE (specify the COM port where the board is connected and the Arduino model).
6. Optionally make additional settings in the firmware, and click “Upload.”
**PROJECT “AUTOMATIC WATERING” SETTINGS IN THE ARDUINO FIRMWARE**
“`cpp
#define DRIVERJVERSION 0 // 0—Display driver marking ends in 4AT, 1—ends in 4T
#define PUMP_AMOUNT 8 // Number of pumps connected via relay or MOSFET
#define START_PIN 3 // Starting from pin number…
#define SWITCH_LEVEL 0 // relay: 1—high level (or MOSFET), 0—low level
#define PARALLEL 0 // 1—parallel watering, 0—sequential watering
#define TIMER_START 0 // 1—period starts from pump OFF, 0—from pump ON
#define PERIOD 0 // 1—period in hours, 0—in minutes
#define PUMPING 1 // 1—pump runtime in seconds, 0—in minutes
#define DROP_ICON 1 // 1—show drop icon, 0—display letter ‘t’ (time)
“`
Let’s move on to the firmware—this was the most interesting part for me. It was technically challenging to “link” the operation of several independent timers and pumps, as well as to have the ability to add the required number of channels if necessary. As a result, the code turned out very clean: all system parameters are stored in arrays and looped through, and the settings we change are saved in non-volatile memory and don’t reset after a reboot.
Now let’s assemble a prototype of our device. Connect the encoder as shown in the provided diagrams, attach the display board to the I2C bus, and then, in order, connect the signal wires to the relays (as in my case) or transistors. This step is crucial since the Arduino firmware specifies the first pin for the pumps, and the others are automatically set according to their quantity.
Upload the firmware to the board and check how the relay contact groups click. After installing the libraries, open the firmware file and review the settings. Chinese manufacturers sometimes send displays with different drivers, so make sure you know which one you have and note it in the settings. Next, specify how many relays you’re using and make other personal adjustments. Important: before uploading the firmware, disconnect pins 0 and 1 from the encoder, or turn the knob to a position where the two LEDs on the board are not lit. Otherwise, the firmware won’t upload because these pins are used in the process, and the encoder will interfere.
Once the firmware is successfully uploaded, the system is ready for operation. I’ll explain how to use it. By turning the encoder knob, you move the selection arrow on the screen. Note that the pump runtime setting is located further to the right “off-screen,” so you need to scroll the arrow to the right to activate it. To change a selected parameter, hold down the encoder knob while turning it. This allows you to set the pump runtime in hours:minutes:seconds format.
Pump names can be manually programmed into the firmware code, even in Russian, which is very convenient. This means we have a fully customizable watering controller for any situation and any greenhouse. By default, it’s set to 1 minute and 1 second, with pumps turning on sequentially for the specified time. The sequence is controlled by a setting that prevents multiple pumps from turning on simultaneously to avoid overloading the power line. If you don’t use this mode, the pumps will turn on simultaneously. But keep in mind that one relay consumes 60mA when active, and a small pump can require up to 500mA.
**Smart Greenhouse – Arduino-Based Automatic Watering System**
Another important point: once you switch to pump selection, all settings are saved in non-volatile memory. Therefore, after a reboot or power-off, they will remain as they were. If you need to reset them, you can do so by turning on the system with the encoder button held down. I included this feature in the program just in case—it might come in handy. It would also be nice to save the current timer values in memory, but that’s another story—I’ll probably tackle it in the next version of the controller, designed for a large greenhouse.
There’s also a sketch in the archive called auto-pumps_valve, which is intended for a “one pump and several valves” setup. In this case, the first connected relay (pin D5 according to the diagram) controls the pump, and all others control the valves. As soon as any valve opens according to the timer, the main pump starts working.
I’m not sure if something like this is commercially available, but if it is, it probably costs a fortune. My automatic watering system costs around 1,000 rubles or a bit more, depending on the number of pumps connected. In this version, up to 15 channels can be used simultaneously. The device can be installed on a windowsill, balcony, or in a greenhouse, and it will water your plants by itself. Whether they are flowers, vegetables, or fruits. Moreover, you can quickly adjust the watering mode for any channel by assessing the soil condition at any time. And assembling and setting up such a “robot” is within the capabilities of even 13-year-old schoolchildren—I know some who can do it!