RainDance – Sprinkler Controller


I am nearing completion of my first actual brought-to-completion microcontroller project. The application: to control sprinklers and drip hoses in the back yard through a web interface, with multiple timers for each valve and power back-up. This was accomplished by creating a custom electronic platform, along with a dynamic website for the user interface.

Hardware
The hardware consists of a SitePlayer network module, a PIC 18LF2321, a 3V coin cell battery, and glue logic. The valves that control the waterflow are turned on and off with relays that switch 24VAC power. The relays themselves are driven from the PIC I/O pins using driver ICs. Twelve valves in total are in use for this project, the number being limited mainly by the memory of the PIC device selected.

The SitePlayer module implements all the handling of network devices. It includes a flash memory that stores all the web site files. In the files, strings of the form ^foo are replaced by the content of the variable ‘foo’, which is one of a number of data types, automatically when the website is served by the site player. A UART (RS232) link between the PIC and the SitePlayer allows the PIC to read and write the variables in the SitePlayer’s on-board memory.

Additionally, a serial I2C eeprom is available for logging events.

Software & Logical Design
The logical design of the device is as follows: the SitePlayer serves up a website with information regarding the current configuration of the system (current time, day, status of the valves, etc.). Most of the dynamic information is retrieved via AJAX. When the user makes a change to the web interface, a specially formatted string is written to the SitePlayer (again, using AJAX), and the SitePlayer module toggles an I/O pin, raising an interrupt on the PIC. The PIC notices this interrupt, reads the command string out of the SitePlayer, updates its internal parameters, and then updates the SitePlayer’s memory, reflecting the changes. Then, the SitePlayer propagates the changes back to the browser.

Furthermore, the PIC reacts to a timer interrupt generated every 2 seconds, and updates its internal clock. On every minute roll-over, it checks whether any valves need to be turned on or off.

There is a back-up battery, which makes sure all the settings (which are stored in PIC RAM) are preserved across power losses. In battery mode, the valves are not being activated, nor is the SitePlayer running. The PIC wakes up every 2 seconds, updates the internal time, and goes back to sleep, so minimal power is consumed. When power is restored, the SitePlayer is re-initialized with data, and can be accessed via the network again.

2 Responses to “RainDance – Sprinkler Controller”

  1. Uber-bay says:

    Hi,

    Your controller sounds interesting. Can you share some photos and some of your code? I am interested in the operation of the Siteplayer and how you are using AJAX.

    Thanks,

    Steve. UK.

  2. marcelb says:

    Hi Steve,
    thanks for the comment. Photos – none yet available, since the hardware is still in progress.
    The SitePlayer is pretty straightforward. It's basically an 8051 with a proprietary firmware that modifies static files by substituting strings of the form ^foo with whatever the variable foo was defined to be. More info at http://www.netmedia.com/siteplayer/docs/001212/SitePlayer_Software_Manual.pdf .
    The AJAX bit comes into play as follows:

    1. The user modifies, say, the description string of a valve and decides to commit the change.
    2. The javascript on the website turns the whole thing into an AJAX request to URL "http://…/update.spi?cmd=1d17Valve%20Description&cmdlen=21", which makes the SitePlayer update the variables "cmd" and "cmdlen" with the respective values. (1d17 means "update valve #1 description, 17 characters.)
    3. When the SitePlayer's variables are updated, an I/O pin on the device goes high – this is connected to an interrupt pin on the PIC.
    4. The PIC, using serial commands (see the diagram I added to the post) reads out the command written to the SitePlayer.
    5. The PIC updates its internal valve parameters based on the command string
    6. The PIC writes the updated settings back to the SitePlayer.

    I can send you any/all of the code if you want, but it's not documented, so I'm not sure if it'll be helpful. If you have any specific questions, though, I'll gladly answer them.
    – Marcel