Simple Irrigation System

by nikakis30 in Circuits > Arduino

81 Views, 0 Favorites, 0 Comments

Simple Irrigation System

59948011_10218927184552741_3572161790852726784_n (1).jpg
59764274_10218927185032753_6285605180801024000_n.jpg

There are plenty of irrigation systems with numerous functions and capabilities. However, if the garden belongs to your mother, the system must be simple enough for anyone to operate. Additionally, if the water supply pressure is not enough, the system must be designed accordingly with separate watering lines, each having different timing. Last but not least, the water supply should come from a single point. This program is designed to manage a system with multiple relays, allowing you to water as many lines as you want in the garden at a low cost and from a single tap. It also includes an RTC (Real-Time Clock) and a user interface consisting of buttons and LEDs.

One button runs the watering program immediately when pressed, bypassing the scheduled time. The other button switches between the intervals for watering, dividing the system's watering schedule by 1-day spacing. Additionally, in the case of a power loss, the system stores the last interval state. The states are indicated by LEDs, representing "Water Now," intervals of one to three days, and a "No Water" state.

Supplies

Here is a detailed description of the main components:

  • Arduino Nano
  • Expansion Board
  • Board with 8Xrelays
  • 2 Buttons
  • Led's
  • Real time clock DS1302

A Detailed Description of the Functionalities of the Program

Key Components:

RTC (DS1302RTC)

  • The DS1302RTC library is used to interact with the RTC module, allowing for timekeeping functionalities.
  • The RTC is initialized and its state is checked to ensure it is running correctly.

Eventually Library

  • This library is used for event-driven programming. It manages various event listeners, including time-based and pin-based events.

Event Listeners

  • Pin Listeners: These listeners detect button presses.
  • Time Listeners: These listeners are used to trigger events at specified intervals.

EEPROM

  • The EEPROM is used to save the state of the system, including the scheduled time for the next relay sequence and the current state of the system.

Relays

  • The system controls multiple relays, each associated with a specific pin and interval.

Main Functionalities:

Setup and Initialization

  • Initializes the serial connection, RTC, and sets up the relays.
  • Configures the initial state by reading from the EEPROM and sets up event listeners for buttons and timed events.

Button Callbacks

  • Start/Stop Button: Toggles the running state of the program. When pressed, it starts or stops the relay sequence.
  • Toggle Program Button: Cycles through the saved states (no program, one-day interval, two-day interval, three-day interval).

Time-Based Actions

  • A periodic check (every 10 seconds) to see if the current time matches the scheduled run time for the relay sequence. If it does, it starts the relay sequence and reschedules the next run time.

Relay Sequence Management

  • Manages the relay sequence, turning relays on and off at specified intervals.
  • When the sequence is finished, it updates the state and stops the program.

State Management

  • The program uses a state machine to manage different modes:
  • NOT_RUNNING: The system is idle.
  • RUNNING: The relay sequence is active.
  • Saved states determine the interval for the next run (none, one day, two days, three days).

LED Indicators

  • LEDs indicate the current saved state and whether the system is running or idle.

RTC Functions

  • Functions to activate the RTC, read the current time, and print the time to the serial monitor.

EEPROM Functions

  • Functions to save and retrieve the state and scheduled time from the EEPROM.

Code Structure:

  • setup(): Initializes the hardware and sets up the initial state.
  • loop(): Managed by the Eventually library to handle events.
  • Callback Functions: Handle button presses and timed events.
  • Helper Functions: Manage the state, schedule the next run, and handle relay sequences.

How the System Works:

Initialization:

  • On startup, the system reads the saved state from the EEPROM and initializes the RTC and relays.
  • Sets up event listeners for the buttons and periodic time checks.

Button Interaction:

  • When the start/stop button is pressed, it toggles the running state, either starting or stopping the relay sequence.
  • When the toggle program button is pressed, it cycles through the saved states (none, one day, two days, three days) and updates the LEDs accordingly.

Relay Sequence:

  • When the system is running, it activates relays sequentially based on the configured intervals.
  • When the sequence completes, it updates the state and prepares for the next scheduled run.

Time Check:

  • Periodically checks the current time against the next scheduled run time.
  • If the current time matches the scheduled run time, it starts the relay sequence and schedules the next run.

This program is a robust system for managing timed relay sequences with user interaction through buttons and visual feedback via LEDs, making it suitable for applications like irrigation systems, timed lighting, or other automated processes.

Caution Points and Code

This program has been running for over five years. There are some points that need extra caution to prevent issues. Firstly, a central control valve must be installed to prevent the system from watering continuously due to a faulty valve left open. Secondly, it needs a monitoring system to ensure the system works properly and meets our needs. In fact, a second program could control the main valve to prevent watering on rainy days. I made a second Arduino IoT device that handles several requirements and presents data on a TFT screen but you must have WiFi nearby.

Follow the link for the code:

https://www.dropbox.com/scl/fo/i4eyt5jt9wkcnex1uhij9/AP5S4uoAQt7yxWPEFUyJInA?rlkey=5yerccbbdlz4pxk2l69gdng7i&st=nxfcicd7&dl=0

Follow the link for libraries:

https://www.dropbox.com/scl/fo/w91xk7g9odm71my1rgho8/AFN1FXpChsG2wM016cMgusk?rlkey=5aj0wl2j0kjozgjxpl590muj5&st=nufpkbo0&dl=0

Warning:Eventually.h is custom made library!

Follow the link for the Iot program with TFT screen:

https://www.instructables.com/Visualzing-Weather-Conditions/

Pin Connections and Circuit Design

nano.jpg

Pin Connections:

RTC Module (DS1302)

  • CE -> RTC_CE (A0)
  • IO -> RTC_IO (A1)
  • CLK -> RTC_CLK (A2)

Buttons

  • Start/Stop Button -> START_STOP_BTN (D12)
  • Toggle Saved Program Button -> TOGGLE_SAVED_PROGRAMM_BTN (D13)

LED

  • Connected to 1 DAY STATE (D9)
  • Connected to 2 DAY STATE (D10)
  • Connected to 3 DAY STATE (D11)
  • Connected to 1 Sec Led (D18)
  • Connected to 1 Manual STATE (D8)

Relay's

  • Connected to D2 UP TO D7

Note:A=Analog and D=Digital

Circuit Design:

The circuit design made with circuito.io program. You must use a different source for the relays or to add a capacitor in your current source in order to avoid voltage drops when the relays are switching. The buttons also need a pull up resistor. Finally the relays are going to drive solenoid valves and in my project I use 220v from old washing machine. So be aware for high voltages, there is danger;

Update

There is one major change in the code: an additional valve has been added to prevent any other valves from being left open. This central valve inhibits the system from watering, as it is controllable via the ESP. The code is as follows:NanoArchanes