Showing posts with label Automated Aquaponics. Show all posts
Showing posts with label Automated Aquaponics. Show all posts

Grow Bed Controller Coming to Tracker

You asked and we delivered - the first of the new distributed controllers is coming to Tracker:  the Grow Bed Controller.  Unlike the Aquaponics Controller, where the grow beds needed to be above the fish tank, the new Tank Controller and Grow Bed Controllers are intended for distributed systems, where the grow beds are a distance away.


Arduino Aquaponics: Grow Bed Controller
Grow Bed Shield.

A number of enhancements have been made.
  • The new ambient light sensor can calculate LUX to a high degree of accuracy with functions to prevent sensor saturation.
  • A new Ethernet board has been integrated to reduce costs and footprint of the original Ethernet Shield.  It uses the same chip as the Arduino Ethernet Shield means you can use the standard Ethernet library, thus no software change.
  • The on-board real-time clock now uses a bigger battery that can last around 20 years.
In addition, the kit itself has changed.  This will be a shield kit only (it comes with all sensors); you will need to provide your own Arduino Mega/ Mega equivalent - a highly demanded feature considering the price difference between official Megas vs SainSmarts and others.  Additionally, there will not be any mains electrical wiring & outlet combo for the 20-amp relay, in order to both extend to international client requirements and to not limit your wiring options (15-amp vs 20-amp wiring and outlets).

Grow Bed Controller features:

  • Tracker key
  • Ethernet
  • Grow Light control, 20-amp relay
  • Ambient Light (LUX)
  • Air Temperature
  • Relative Humidity
  • Waterproof Root Temperature
  • On-board real-time-clock (RTC) with battery backup to keep time if power is lost.






Tracker Update

The first two public modules for Tracker, water quality and grow beds, are online and you can sign up for free here.

Water quality allows you to upload results from the API Freshwater Master Test Kit, and track that over time.  You can see the screenshot below.  Adding a note and image to a water quality reading is a feature that will be turned on this week.




Grow beds are easily the feature we are the most excited about with regards to integrating environmental and water quality monitoring to analyze the health of a plant.  Speaking of plants, each plant has an associated seed packet, which you can grab from the shared community list, or upload and share your own.  Similar to water quality readings, you will be able to add notes to your seed packets to record things like germination rates, which you can refer back to anytime.



Beta testers, the ADACS modules are being kept separate for the time being while each of these new modules are put online and tested, after which we will integrate the controllers one at a time.  You can find more information in your message box.

Real-Time Clock - Part II: Grow Light Controller

In Part I of this tutorial, you learned how to set up the ChronoDot  with the Arduino and use it to track time.  Part II continues the discussion by creating a timer that can be used to control grow lights.

In a previous post we talked about the importance of light for plants and the role grow lights play in Controlled Environment Agriculture either by monitoring current light levels and providing supplemental light, or by providing all of the light for a fixed time every day.  Part II focuses on the latter, creating a timer which toggles a light on at a certain time of day, toggles it off at another and uses the ChronoDot to track the time.


Parts List
1 x Arduino Uno R3 (IDE 1.0.3)
1 x ChronoDot
1 x PowerSwitch Tail II Relay
6 x Jumper wires


Fritzing Diagram


Figure 1.  Grow Light Timer diagram.

Arduino Libraries
In addition to the libraries from Part I, you will need two new libraries for this sketch:  Time and TimeAlarms.  The Time library is used to set the Arduino's system time as well as to compare times during the initial setup.

TimeAlarms is used to create two alarms, one for the time each day the light is turned on, and a second alarm for the time of day the light is turned off.

Download both zip files, extract them and move a copy into your Arduino's libraries directory.


Arduino Sketch
This sketch takes two times, given as hour, minute and second and creates an alarm for each.  When you first launch the script, the start time and end time are compared to the current time.  If the current time is between the two times, the relay is toggled ON.

During each operational loop, the current time is retrieved from the ChronoDot, the system time is reset and the current time is displayed.


Real-Time Clock - Part I

A fundamental necessity of any controls system is the ability to track time.  As far as we are aware, the Arduino has three methods it can employ:
  1. Serial.  Repeatedly get the time over the Serial connection.
  2. External Hardware.  Real-time clocks, like the ChronoDot from Macetech, establish a base time when the Arduino sketch is compiled.  When you request the current time in the sketch you actually receive a time based on the time that has elapsed since compilation.
  3. Ethernet.  Access time using the internet NTP service.
This tutorial set focuses on option 2.  In Part I we explain the basics of getting the ChronoDot set up and displaying the current time over serial.

The ChronoDot

The ChronoDot is a high precision real-time-clock (RTC) and boasts a number of features needed for Aquaponics. The V2.1 release introduced the DS3231SN chip, which has an industrial temperature range of -40C to +85C and outputs a temperature compensated time - important for aquaponic control systems that reside outdoors in the heat and direct sun.  
Figure 1.  The ChronoDot V2.1, credit Macetech.

The ChronoDot includes an onboard battery cell for a CR1632 battery, allowing the clock to keep track of time should the Arduino lose power, regain power and restart. Anyone in aquaponics can appreciate the ability of a control system to automatically reboot and resume operation in the event of a power glitch. The disadvantage of the ChronoDot, and RTCs in general is the inability to handle Daylight Savings Time.

The Environment DAQ can be configured with the ChronoDot using the prototyping area, which is exactly wide enough to handle the RTC (coincidence?). If mounting to the shield, you can access the pins from the bottom.
Figure 2.  Environment DAQ Shield with ChronoDot.

Parts List
1 x ChronoDot
1 x Arduino Uno R3
4 x Jumper Wires

Mounting the ChronoDot
The Fritzing diagram below shows how to connect the ChronoDot to the Arduino. Note that the RTC connections are on the right-hand side - the pins on the other side are not used.


Figure 2.  Connecting the ChronoDot.

Arduino Library
The ChronoDot requires two libraries
  1. Wire.h - Included with the Arduino
  2. RTClib.h - Download here.
Download the zip file and extract it. If necessary, rename the extracted folder "RTClib", and then move a copy into your Arduino libraries directory.

Arduino Sketch
Part I of this tutorial simply outputs the current time from the RTC to Serial; part two shows how to set create a toggle time.


Environment DAQ Update 2.2

Version 2.2 brings the new overview container as well as some updates to the CSS files for Firefox.


You can download Version 2.2 here.

First Batch of Environmental Shields

Update: 6/5/2013
For those who emailed about purchasing the blank PCBs, you can find them above:  Blank PCBs.

The new Arduino Environment Shields came in today.  The major improvements are the use of screw terminals, which allow for the replacement of parts, a new prototyping area for customization and a new connection for a relay bi-color LED indicator.

Arduino Aquaponics Environment Shield.
More significantly, the new layout takes the two old boards (DAQ and Controller) and combines them into a single board - you may start out only interested in data acquisition and decide to add the control components later.


Environmental Controller mid assembly.

Obviously, hardware wasn't the only area we expanded upon, in fact, the software improvements are where the real changes can be seen.

The new timezone module streamlines the handling of time transitions and comparisons as well as Daylight Savings Time.

The real-time data visualizations in the cloud application now include context by plotting data against preferences, specifically minimum and maximum values for parameters.  Below is a gauge of the current temperature.  Instead of hard-coding red/green/yellow ranges, the ranges are set by user preferences and can be changed on the fly in the Settings tab.

Preference Range:  65 to  95 degrees Fahrenheit. 

The Environment Shield can be set to one of seven different modes: one for data acquisition only and then six for controlling grow lights, foggers, dehumidifiers, portable heaters, fans, etc.  All seven modes feature the data acquisition.  Changing modes is as easy as pressing a button and plugging in your device.

Memory cache has been implemented reducing datastore requests to one-third the original number and increasing service speeds.

The final two upgrades are perhaps the most important.  First, we have implemented Responsive Web Design, giving you an optimized interface across any device and screen size.  No more pinch-to-zoom on your mobile smartphone or tablet, the visualizations and layouts dynamically adjust.  The visualizations themselves are SVGs and built using AJAX; by including RWD practices we have removed the platform barriers separating iPhone, Android, Blackberry and Windows.

Lastly (but most exciting) the new cloud applications for the Environmental Controllers can sync with Aquaponics Tracker, providing a means of interfacing multiple controllers across a number of systems into a single screen with water quality and grow bed tracking.

Arduino Aquaponics Multi-Controller UI Overhaul

A new feature we are rolling into the Aquaponics Multi-Controller UI is graphing data with on-demand thresholds - in other words, if you change the minimum or maximum threshold for air temperature, the data is re-plotted against the new thresholds; the gauges will also reflect the thresholds.  




You can see the change in the line chart above.  And no, the data controls and quick alert icons haven't moved, we just removed them here for testing.

Aquaponics: Arduino Email & Text Messaging

Background
With all of the lauded benefits of aquaponics, there are a number of drawbacks and they primarily lie in the need for electricity.  Typically there is at least one pump, but if you also use grow lights, water heaters and other electronics, you'll inevitably increase possible points of failure.  Wouldn't it be nice if you knew right away when pumps fail, grow lights burn out or don't come on, water heaters die, water temp plummets, a grow bed or fish tank springs a leak or overflows, humidity gets too high/low or the summer sun roasts your greenhouse?

Automation can immediately act to correct some of these conditions but sometimes you don't have a backup pump, grow light or stock tank heater.  Leaks, especially in basement systems, can ruin property if it's not addressed quickly.

What you want is a way to know what's going on as it happens and a very good way of doing that is through text message or email.  That's what this guide is all about and it's not unique to aquaponics or hydroponics - it can be used any time the Arduino needs to alert you of a sensor reading.

The Arduino Data Acquisition and Control System (ADACS) projects in Automating Aquaponics with Arduino use the mail API to notify owners of failed/blocked pumps, when environmental conditions move outside of user-defined ranges, and when grow lights fail or don't turn on.  Additionally, you'll be notified when the Arduino has failed to connect to the webapp for a set period of time to indicate a potential power loss or loss of an internet connection.  Knowledge of what is happening in your system is the most powerful tool of all and when you combine the Arduino in your aquaponics or hydroponics system, you get an inexpensive means of acquiring that knowledge.

How It Works
Like all of our web-based projects we'll use Google's cloud infrastructure, App Engine.  We'll set up an Arduino Uno with two push buttons, which, when pressed, will send a web request to App Engine and prompt either an email or a text message.  The client consists of a very basic form to collect the designated email address and text address.

Hardware
1 x Arduino Uno R3
1 x Arduino Ethernet Shield R3
2 x Momentary button or switch
2 x 10k ohm resistor
1 x Small breadboard
Breadboard jumper wires

Software
Arduino-1.0.3 IDE
Google App Engine Python SDK: 1.7.4
Python 2.7
Ubuntu 12.04*

*These instructions are probably very easy to translate for Windows or Mac, but as we have neither I can't help you there.

Step 1:  Create a New App Engine Application
The first step will be to create a new application on App Engine.  As all of our web application use App Engine, we've created a standalone tutorial to cover it: Creating a New Application.

Step 2:  App Engine - Configure app.yaml
  • The email alerts reside in a file called alerts.py.  We need to add that file to our app.yaml file, Fig 1.
Fig 1.  Add alerts to app.yaml
Step 3:  App Engine - models.py
  • In the typical MVC (Model, View, Controller) pattern, we need to create a model of our data, which resides in models.py and is imported to the files that need to access it.
  • We have one class to create, the UserPrefs class, which has three properties
    1. Time zone offset - not used in this tutorial
    2. Email Address - string property
    3. Text Address - string property
Fig 2.  models.py
 Step 4:  App Engine - main.py and Templates
  • Open main.py and add the import statements, Fig 3.
Fig 3.  main.py import statements
  • The first three imports are used to display the templates and run the application.  The users import is used to get the email address of you (the email address you used to create the application).
  • models is used is the file containing the UserPrefs data, which we covered in step 3.
  • main.py consists of just two classes: MainPage and SaveAddress. You can see MainPage in Fig 4.  
Fig 4.  MainPage class.
  • The title of the page is sent to the header template, which you can see in Fig 5.  This is how data can be passed into generic templates, reducing redundant programming.
Fig 5.  The first part of header.html
  •  In order to send emails or text messages you'll need to provide an address, so we add a very simple form to header.html.  You can see the complete file in Fig 6.  The form consists of two text fields and two buttons.  Each button is given a JavaScript onclick handler discussed in the next step.
Fig 6.  Full header.html file
  •  footer.html is a truly uninspiring file and only consists of closing tags
</body>
</html>
Step 5:  Email & Text Messages
A word on email addresses.  The email address you put as the sender must be an email address associated with the account you used to make the webapp.  You can also invite other Gmail addresses to be admins.  The email address you are sending to can be any valid email address.
Text messages can be sent through an email client such as Gmail given you format the address correctly.  Here is a link on the different formats carriers use for SMS and MMS.  We have only confirmed the Sprint format so I will use that as the example.

Sprint's SMS email format looks like this:
<your phone number>@messaging.sprintpcs.com
Example:
 
1234567890@messaging.sprintpcs.com
A Sprint user would substitute their phone number in and use this for the text message box.

Step 6: JavaScript and Form Processing
  • With our template and form in place, we will use JavaScript to send an asynchronous request to the server to process the form.  I've separated the JavaScript into two separate files.  The first is utils.js, Fig 7, and contains the function to create a request.  Looking back at Fig 6, you'll see utils.js is loaded before our second JavaScript file, main.js
Fig 7 - utils.js
  • Next, main.js contains the two onclickhandlers we referenced in the form.  I created them separately for readability in this tutorial, we could have easily created a single button to do this work. When a save button is clicked, a series of events takes place and you can read that in the comments.
Fig 8.  main.js
  • The webapp code to process the JavaScript requests is the second class in main.py, SaveAddress.
Fig 9.  SaveAddress in main.py
  • The JavaScript request is parsed and the UserPrefs entity with the email address you used to create the app used as the key_name.  If the entity exists, you will update the emailAddress or textAddress properties, otherwise a new entity is created.  Finally, the entity is put into the datastore and a response is made.
Step 7:  App Engine - alerts.py
  • alerts.py has one class, Alert, used to handle the Arduino request.  There is also one function, SendAlert used to send an email or text message.  First we list our imports
Fig 10.  alerts.py import statements
  • The Alert request handler parses the request from the Arduino to determine the type of alert you want, email or text, Fig 11.
Fig 11.  Alert request handler
  • The request handler for the Arduino parses the request to find out which type of alert you want, text or email.  Then it calls the SendAlert function passing in the type of alert and a message.  This makes the alert function generic and reusable.
Fig 12.  SendAlert
Step 8: Arduino - Fritzing Diagram
  • The circuit for this tutorial is very straight forward and consists of two push buttons.  One push button is used to request an email, the other a text alert.
Fig 13.  Fritzing Diagram
  • In Fig 13 you see a tiny breadboad sitting on an Arduino Uno R3.  In reality, the breadboard resides on an Ethernet Shield, or better yet, a proto shield on an ethernet shield on an Arduino R3.
Step 9: Arduino - Code
  • Start by setting up the Arduino with your assignments
Fig 14.  Arduino assignments and imports
  • The setup loop begins the serial output and the Ethernet.  It sets the pin mode for the pushbuttons to INPUT and finally notifies the user that setup is complete.
Fig 15.  Arduino setup loop.
  • The operating loop monitors digital pins two and three to see if the push buttons have been pressed.  If they have, we call the sendAlert function with the type of alert we want.
Fig 16.  Operating loop
  • sendAlert outputs via serial the type of alert being requested.  Then it creates a GET request to the Arduino and finally outputs the response to the screen.
Fig 17.  sendAlert Arduino function
  • The final two functions in the Arduino program are our normal response parsing and httpRequest functions.
Fig 18.  HTTP response parsing and request functions
And there you have it - two buttons to send either a text message or an email.  While the button format may seem useless think about this - the Arduino read the state of a pin before making the request and the GET request was generalized to allow either button to request the same function.

By extension, the Arduino can read the state of any input pin, analyze the reading via conditionals and send an alert if it needs to.  The Arduino Aquaponics code in the ADACS is rather large, so rather than apply conditionals on the Arduino, the values were automatically sent to App Engine and App Engine applied the conditionals to decide if an alert was needed.  This freed up valuable programming space and extended the number of conditionals that could be applied.

Online Relay Control


Intro
The most exciting thing for someone new to monitoring, control and automation over the internet, is being able to manually turn something on or off using your computer, tablet or phone, from anywhere. 

Inevitably, the next step is to automate the control.  Some automation examples include toggling the relay based on environmental conditions, sensor reports, time, GPS coordinates, motion detection or some combination of these.

We break down the uses of the Arduino in aquaponics to three main categories
  1. Monitoring.  Using sensors to monitor the environment be it air or water temperature, relative humidity, light levels, etc.
  2. Control.  Manually prompting an action, turning a pump on/off, grow light on/off, opening/closing windows, etc.
  3. Automation.  Combines steps one and two to use sensor readings to implement controls, without your input.
What kind of automation projects can the Arduino solve for aquaponics? Actually, there are many, but here are a few.
  • Pump timer
  • Backup pump triggered when primary pump died (true story).
  • Automatically increase/decrease pump cycles on consecutively cloudy/sunny days
  • Grow lights based on time of day, cloudy/sunny conditions
  • Light shades on bright days
  • Open/close greenhouse windows based on climate forecast
  • Toggle Portable heaters or air conditioners
  • Toggle light on when you enter greenhouse/basement/garage
No matter what intelligence you want to implement, it all starts with getting the relay talking to the internet and that is what this project is all about.  For an advanced version, see the Pump Controller project.


How it works
The technique we are going to use is polling and is analogous to a child sitting in the backseat on a long road trip asking "Are we there yet?" every twenty seconds.  An Arduino will make a GET request to App Engine, which will query the datastore for the relay entity and return the relay's state property.  The Arduino will parse the response and trigger the relay pin HIGH/LOW.

The webapp is a simple image, whose class changes based on the the current state.  Click the power button image and it will toggle the class, create an AJAX request to the server which in turn will toggle the state property of the relay entity in the datastore.

Fig 1.  On/Off Button.
Parts List
1 x Arduino Uno R3
1 x Arduino Ethernet Shield, R3
1 x Powerswitch Tail II
2 x breadboard male/male jumper wires
1 x Arduino wall wart (optional, for better power)

Software Versions
Arduino IDE 1.0.3
Google App Engine, Python SDK 1.7.4
Ubuntu 12.04
Python 2.7


Step 0 - Create a New Webapp on App Engine
This step has it's own short tutorial.

Step 1 - Download Project Code
  • Download the project source code here.
  • Extract the tar file to the directory of your choosing.  The following instructions assume it's in your home directory, so amend the instructions with whatever directory you put the code in.
  • The extracted folder is called IAquaponics_Relay and inside are two folders, myapsystem containing the GAE webapp and arduino.
  • The first thing you will need to do is open app.yaml inside of myapsystem.  The first line is the application name and needs to be changed to reflect the new application identifier you created in Step 0.
Fig 2.  app.yaml.  Replace the highlighted name with your project name.
  • Take note of the bottom.  The main page of our webapp is listed last because it will catch all url requests not listed above it.  In fact, this webapp only has two pages: adacs and main.  The former is used by the Arduino and the latter is the visible interface you will see with the web browser (client).
  • Finally, under main.app, you will see login: admin.  This app uses Google Accounts as you saw in Step 2, but we are restricting application to the webapp to just you.

Step 2 - Launch the AppEngine SDK with Your Project
  • Open a terminal and launch the AppEngine SDK and your project.
python2.7 AppEngine/dev_appserver.py IAquaponics_Relay/myapsystem
  • If all went well, the terminal will tell you the project is located at
http://localhost:8080/
  • So fire up a web browser and point it to that url.  Because we have restricted access to admin, you will need to login as admin.  The login name is irrelevant, but beneath the email input box you need to check the box that says "Sign in as Administrator".  Then login.
Fig 3.  Login as Administrator.
  • At this point, you should see Fig 4.
Fig 4.  On/Off Button.
  • With your terminal in view, click the button.  It will change to green and in your terminal you will see the request made to the server, Fig 5. 
Fig 5.  Terminal output on class change.
  • The button's class has now changed and the request to the server makes the Relay entity's state property change to reflect the class.  Open a new tab in your browser and go to your admin page.
http://localhost:8080/_ah/admin
  • This should load the datastore viewer pane.  The only entity is Relay.  Click List Entities and it will load the properties for Relay, Fig 6.  You can see the state property is set to On now.
Fig 6.  Relay entity with state property set to 'on'.

Step 3 - Upload the Webapp to App Engine
  • If everything has worked for you so far, it's time to upload the webapp to a live server.  Open a terminal and type
cd AppEngine/
./appcfg.py update ~/IAquaponics_Relay/myapsystem
  • You will likely be prompted for the Google credentials you used to create the application in Step 0.
  • When the update is done, open a browser and go to your live webapp.
http://myapsystem.appspot.com
  • If you are not already logged into your Google account, you will be prompted to.
  • The main screen is a repeat of Fig 4.  Click the power button to change the state to on and go into your Admin Console to confirm the state has changed.  The admin console for live webapps is
http://appengine.google.com

Step 4 - Arduino
  • Connect the Ethernet shield to the Powerswitch Tail II as shown in the Fritzing diagram in Fig 7.
Fig 7.  Fritzing diagram of Ethernet shield and Powerswitch Tail II.
  • To test the relay, plug an appliance such as a lamp into the relay and plug the other end of the relay into the wall.
  • Now load the Arduino code from the project directory.
  • You will need to amend the Arduino code, pointing it to your live webapp.  There are two locations where the webapp link is listed.  Change ONLY the highlighted code in Fig 8 and Fig 9.
Fig 8.  First location.

Fig 9.  Second Location.
  • Save and upload to your Arduino.
  • Open the serial monitor.
  • In your webapp, toggle the button and wait to see the relay toggle.
  • And that's it.
Notes
  1. Since working with AppEngine and Arduino Ethernet we have encountered one consistent error.  The Arduino will fail to make the third request.  The first two are fine.  Every request after the third connects and works, but for some reason the third one will fail, every time.
  2. The Arduino creates a GET request and then pauses for ten seconds before parsing the response.  Toggling the power button in the webapp will not immediately toggle the light.
  3. The rate of the GET requests is quite high, for demonstration purposes.  If you are going to implement this, you may want to double the delayed time interval in order to keep extra instances from spawning and reducing the read/write operations.
The Next Steps
The point of this tutorial was to show the polling technique the Arduino uses to get the state of the relay from the web and then change the relay pin.  Here we implemented manual control, but there was logic involved.  When the Arduino made the request, App Engine queried for the Relay entity and simply returned the state property.  Instead, we could have changed the interface to be a simple form to get the start and end time for a grow light in a basement system - say 5:00 am and 10:00 pm.  Then we could set a conditional when the Arduino made its request, to compare the timestamp of the request with the current time.  If the timestamp is inside the operating time, the light is on, otherwise it is off.  This is just a small example of the kind of intelligence you could program in; the point is, program it on the web side, where you can make changes and see the current state of a relay.

You can find more tutorials like this on the Automating Aquaponics with Arduino page.

Related Projects
Real-Time Graphing Online
Online Temperature and Humidity

Any questions or comments are appreciated.