Arduino Powered Aquarium Controller – Part 3

Welcome to the long overdue part 3 of my Arduino powered aquarium and aquaponics controller. In this post I am going to outline some major design challenges I faced, the resulting changes I had to make and detail getting some simple data logging running. Before we continue, if you have not seen the earlier posts in this series be sure to check them out so you can follow along. Here are the links for Part 1 and Part 2.

The Challenges

When I left you last time, we had our hardware connected up, we had tested that everything was working as expected and all we needed was the code to tie it all together. Fantastic! I actually made a start on the code very shortly after completing the last post. I had all three sensors being polled for data and I was connecting to my wifi network without a hitch. At this point I was already very aware of the fact that almost all of the memory on the Arduino was being used. The major problem I was having at this point was that when I tried to send my data string to the Xively server, I was getting errors which I suspect was due to there not being enough contiguous memory to build the entire string. I spent some time trying to work out a way to get this all work, finding a few solutions. I have no doubt that with a little more code tweaking I would have had this working, however, this would not have helped me with the growing problem of limited memory. I am sure that a coding wizard would have been able to free up a lot of memory. I am not one of those wizards though and I wanted this project to be easily understandable to fellow non-wizards.

The second problem that came up was that Xively had decided to stop allowing free developer access to their system. While I was still able to access their system, I was concerned about how future proof it was going to be. No one wants to spend all this time getting their data logger running to have it all pulled out from under their feet.

The Solution

Not long after my initial purchase of the hardware for this project I started seeing rumours of a new Arduino board coming out called the Yun. Cursing my luck about the timing I didn’t give it too much attention other than to satisfy my curiosity. Given that they could not be purchased yet anyway, I pressed on with the hardware I had. As the weeks passed while I was trying to find easy solutions to my challenges, the Yun had been released, followed closely by the Dragino Yun Shield. After reviewing some of the projects people were using the Yun for I decided that it was going to be the easiest solution for me. It will allow me to have a local web interface that can be used to directly control the system and will remove the problem of having 3rd party services changing over time. It was just a matter of playing the waiting game for my Yun Shield to arrive.

Making the Changes

Fortunately the changes to the hardware are minimal, highlighting the benefits of the shield system that Arduino use. It was a simple case of removing the CC3000 and data logging shield, plugging in the Yun shield and plugging the sensor back in. I wont reinvent the wheel with regards the setting up the Yun and connecting to your wifi because it has been covered very well on the Yun Getting Started page. This guide will show you how to install the latest Arduino IDE, connect to your Yun and configure it.

Once you have your Yun set up on your local wifi, insert a USB pen into the USB slot. Using a SCP program for you operating system of choice we are going to login to the YUN and create the file that we want to data log to.

The USB pen will auto mount to the following directory:

 /mnt/sda1

Within this directory we want to create a file called ‘aquarium.csv’. This will be the file that we will record all of the data to and initially copy to our PC to view the results. CSV stands for Comma-Separated Value and is a way to record data using commas to delimit the information in a text file. This is a very common format and all computer platforms will have at least some support to view it.

Let the Coding Begin

My code is quite well documented, so I wont go through it line by line. I will go through a brief overview and let you read through the code to see what is going on in detail. I have broken each program task into easily digestible chunks and labelled them according to their function. I think that there would be far more efficient ways to code this, however I want it to be easy to understand for new comers (myself included!).

The program is a simple beast at this stage. It initialises the sensors, the bridge to the SoC and a console to send serial data to the Arduino IDE. It then drops into the main program loop where it polls the sensors, assembles the data into a string to record and then saves that string to the ‘aquarium.csv’ file. At the bottom of this post a link to download the Arduino sketch so you can upload it to your Yun and try it out for yourself.

Viewing the Data

At this point in time recovering the data from our data logger is a little convoluted but not too bad. Using the SCP program you used earlier, log into your Yun, navigate to the /mnt/sda1 directory and copy the ‘aquarium.csv’ file to your computer. From here there are a few options you can take although the simplest I know of is to open the file in a spreadsheet program such as Microsoft Excel, OpenOffice Calc or LibreOffice Calc. Now you can see the benefit of using a CSV file format. Each of our data points has been placed in its own cell, making it very easy for us to select all of our data and draw a graph. Below is a graph that I made after running for a few days. You can see that there are a few erroneous readings in there, especially with the sump level that I am yet to work out.

Conclusion

In this post I had to make a few changes to my original plan. This has allowed a lot of extra flexibility and will result in a much better tool. While this data logger is still in its infancy, there is a lot of potential using the Arduino Yun to create a great looking, but more importantly powerful tool to allow us to remotely monitor and control our aquariums. Stay tuned for the next update!

Links

Ardiuno Yun

Dragino Yun Shield

Guide to the Arduino Yun

Downloads

AquariumAutomation_V0.1

1 comment

Leave a Reply