Type your search keyword, and press enter

Sensoring Aquaponics

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

As part of my interest in aquaponics I’ve always intended to enable some kind of electronic monitoring, various thoughts on what to monitor and how have been in my head for a while. Recently I’ve been wondering if the temperature levels of the water are high enough so this was as good a place as any to start.

An Arduino was my obvious choice to start with, I built various circuits but soon decided that I wouldn’t be running Ethernet anywhere near and that kind of ruled it out with regards to re-using existing kit. I decided to use one of the nodeMCU devices I’m halfway through a project on (I’ll just buy another couple eventually).

Having previously used LUA script on the devices, I decided to use the Arduino method instead this time, mainly to investigate the OTA options now available. I’d already built up some perf board based shields to house a connector to a DS18B20 temperature sensor, so I just added some female headers to one of the waterproof sensors I have lying around and hey presto.

I have power near the tank so I’ve opted for an always on solution with a permanent supply, rather than power from batteries and have to worry about charge cycles. WiFi connection works perfectly outdoors too.

I will be publishing the sketch on GitHub shortly (watch here for an edit), just need to tidy up a little. But essentially it reads the temp every 10 seconds and publishes to an MQTT topic, fairly simple for now but I do plan on adding more sensors for humidity, greenhouse temperature and possibly others such as luminosity and maybe barometric pressure and pH. For now though I have enough to get me going and also have the data of interest.

The data itself just goes to an MQTT stream, but I’ve developed a simple web front end using jquery to show a simple gauge. I have also used the script at https://github.com/irvined1982/MQTT2RRD to generate rrd information to form rrd graphs which can actually be seen in the sidebar on this site.

Great data for now.

Here’s a couple of pics of the device and the probe in the water.


Arduino based Electricity monitor

Your ads will be inserted here by

Easy Plugin for AdSense.

Please go to the plugin admin page to
Paste your ad code OR
Suppress this ad slot.

Over the past 12 months or so I’ve been looking to add various “Smart House” components to my home, rather than do this in the traditional sense of buying something off-the-shelf I’ve been experimenting and building my own. One of the real plus points in me doing this is that all the data that is passed around is in an open standard and format chosen by me, not some cludge to try and extract information in a format decided by a-n-other manufacturer.

This post will cover the process I’ve gone through to build an Arduino based energy monitor, in the first instance this is only monitoring electricity usage

First step was to look at what information I could glean from the meter itself, there are a number of ways to extract information here, a clamp which sits around the wire between the meter and the consumer unit:


The other ways generally involve retrieving a pulse of some kind from the meter, either via a screw in terminal which sends a pulse over wire or a flashing LED. In my case it was a flashing LED as you can see in the following image.


This LED sends out a pulse every time a watt is used, or for monetary conversion 1000 for every kilowatt used. So knowing this I could create a device to read these flashes and convert them into usable data.



The configuration of the above circuit is really simple, a TSL261 Light to Voltage sensor connected to an arduino with an ethernet shield.

How to connect the TSL261
looking at the component, the sensor will have a raised part above it, this is the front. Front the front the pins run from left to right, pin 1 being GND, pin 2 V+ and pin 3 output. In my circuit I connected the voltage and ground appropriately (3v) and attached the output to digital pin 2.


My current incarnation has pins soldered to one end of a length of wire and the sensor the other (I used strands from CAT5e cable) to allow me to position the arduino then attach the sensor to the front of the electric meter, the attachment was a complicated process of sticking with some trusty old duct tape. I still need to get some heat shrink tubing to ensure the pins don’t short but it’s ok for now.


While researching this project I found this site, http://www.airsensor.co.uk/component/zoo/item/energy-monitor.html which took the data collected and stored it in a file on the SD card. This wasn’t exactly what I was looking for as I wanted to graph the data preferably from a live feed. I thought the best way to do this was to utilise one of my favourite current tools which I use in a lot of my other projects MQTT, I wanted the arduino to simple detect a pulse and send out information which I could retrieve on any device subscribed to a particular topic. More research led me to a page Nicegear where I found Hadley Rich doing pretty much exactly what I was looking for, his Arduino sketch created an output on a particular MQTT topic when a pulse was detected, but to top this he had also created a function to output the current watt usage every second. This proved to be more useful than the original idea of outputting the pulse on detection.

You can find the sketch at Hadleys website, or on my GitHub page. The only real difference between his sketch and the one on my arduino is the count of LED flashes per kWh, his needs to flash 1600 per kWh mine flashes 1000, or 1watt per flash.

So subscribing to the topic
house/power/meter/1/current would recieve a number of watts currently being used


or topic
would output a 1 everytime a pulse occurred.


Now what to do with this data?
My plan was to graph the data so had to figure some way of getting this data into a graphing application or service. More research ensued, Graphite/Carbon seems to be an ideal choice to pursue but at this point in time haven’t got anything functional. A lot of posts around the internet suggest the use of pachube, which became cosm which then became xively. Using a python script to listen to the mqtt topic usage and pipe to the xively API I ended up with a nice graph.


You can see my live feed here, xively.com/feeds/73975854

All in all, I’m really pleased with this project. It’s still rough around the edges in places, both physically and software wise. I’d like to move the project to an Arduino mini pro with one of the smaller ethernet shields and have a nice box to house it. Get a graphite instance working and retrieving the data. First on the next steps list however is to try and extract the same information from the gas meter, I believe there is a pulse output on the front of the meter but this will require some more research so watch this space.


2013 – A good year

I thought I’d finish off the year with a bit of reflection, overall it’s been a pretty good year in both camps of my life – the geek/tech and the family side. Obvious highs of the year include:

  • Birth of my second child, Alfie.
  • OggCamp 13
  • LinuxCon Europe
  • Barcamp Blackpool
  • RossLUGs 3rd year – some fantastic meetings this year.

It certainly has been a full on year.

It’s been a really tech filled year, as since moving house last September I’ve had my own space for all my tech which is a real bonus. It’s allowed me to really get back into electronics with Arduino building the home automation system, the electric meter monitor (still to be finished) and more recently bringing a snowman christmas decoration back to life:

As part of my job heavily entails virtualisation and storage I’ve been getting heavily into oVirt, GlusterFS and Openstack (more specifically RDO). Making commits upstream too, to both code and documentation.

One of my other highs of this year tech wise was establishing a presence on GitHub I’ve uploaded most, if not all, the code I’ve worked on this year and licensed it with GPL with great reward of folks actually looking at my code. I feel like I’ve really given something back there.

On the topic of giving back, I finally became a Fedora ambassador this year. I’ve thought about it in previous years as I’ve always used the distro and given back where I can. After an experiment of using Ubuntu solely for a while I reverted back to my much cherished comfort zone, but decided to go the whole hog and really get involved in what has turned out to be a great community. Attending the events I regularly and ones I don’t, on behalf of the project has been a rewarding experience so far.

So whats in store for 2014? Well hopefully I’ll continue on this track, more open virtualisation, more Arduino, Raspberry Pi, more Fedora. But also coming in 2014 will be another track, STEM. I recently became a STEM ambassador which will allow me to impart some of my knowlege and skills and help bring a better quality of education in the tech sector to children. I’m hoping to get involved with, and also run, Arduino, Raspberry Pi coding sessions throughout 2014 so watch this space.

All in all 2013 has been an excellent year, lets hope 2014 is as good, if not better. All the very best to you all.


Light control with MQTT on Arduino

It’s been a while since I stayed up most of the night writing code, mainly down to having a young daughter but also down to the fact I haven’t found anything that needed a late night hack session to produce a result. This weekend changed all that, I’ve been playing around with home automation for a while but am now actually taking the plunge. I purchased a load of Arduino and electronics kit over the last few days to start prototyping the setup.

The plan:

I’m planning to replace all the lights in the house with 12v LED based bulbs, mainly as a power saving excercise but also in the idea that it will make designing control circuits easier and safer, and also able to save money on getting an electrician to do the wiring. Once the transformers are wired up it will just be a matter of splicing in my control circuit. This will also allow me to convert a room, or even lamp/light at a time and not cause too much of a fuss in the house.

The control circuit:
This will consist of an arduino with an ethernet shield, and a number of mosfet transistors to do the switching. A fairly simple circuit really, which will use a single pin for each light. I could, and probably will get a little bit more fancy introducing timers and dimmers but lets not get ahead of myself here, besides this will be a small change which could be done without too much disruption at a later date.

So working on the research I’ve been doing around the technology I decided to opt for MQTT as the messaging between devices, its really simple but also really powerful at the same time. By assigning each device a name and designating a topic to that device a simple message can be transmitted to the network by a publisher and the relevant arduino which subscribes to that topic will pick up the message, and depending upon the message will perform an action.

A little bit about MQTT:
So to explain MQTT a little more, there are 3 components to MQTT which we are interested in, Broker, Publisher and Subscriber. First of all to use MQTT you need a broker, this is essentially a daemon or service running on a server on your (or external) network. In my case I am using the excellent Mosquitto (yes 2 t’s), at the moment I am also running with the default config I literally just started the service. Next you need a publisher and a subscriber, these are exactly what the sound like.
The subscriber basically connects to the broker server and listens for messages on a particular topic. At its simplest this would look like this on the linux command line using the mosquitto tools:

mosquitto_sub -h -t Test/topic

So this subscriber is listening for messages on the topic Test/topic on the broker The publisher will send a message via the broker to a particular topic so to send a message to the above subscriber the following command using the mosquitto tools would be required.
mosquitto_pub -h -t Test/topic -m “hello world”

Any device subscribing to the Test/topic topic would now see a simple message of hello world appear.

So the plan is to utilise MQTT messaging and assign a topic per device and have the PubSubClient libraries present on an arduino to subscribe to the topics that particular device controls. So for example in the Study there will be 4 LEDs, so their topics would be house/study/led0 up to led3, the arduino will have 4 pins dedicated to the control of these so when a message is recieved on these topics a control signal will be sent.

Moving onto the switching side of things, it will be an arduino publishing the messages to the relevant topics based on push button switches being pressed to close signals on certain arduino pins.

So the messaging flow would look something like this:

switch 0 pressed -> Arduino pin 3 recieves HIGH signal -> Arduino publishes “On” MQTT message to topic house/study/led0

Arduino controlling lights recieved MQTT message on the house/study/led0 topic that it is subscribing to -> Arduino sends HIGH signal to pin 3 which in turn switches the LED light on.


The prototype:

After deciding on a plan of action, a prototype setup is required. I have setup an Arduino with pins 3 and 5 activating an LED each, attached to a breadboard via a resistor. After testing the LEDs using the blink sketch it was now time to get the board recieving MQTT messages and activating the said LEDs. Once I was happy that the Arduino was network connected using the Ethernet libraries I added the PubSubClient library and had it subscribe to the above topics – I did one first then added a second later.
In order to debug the MQTT I literally had it output the payload to serial and send messages from the linux command line tools.

All that seemed to go together quite well, my next problem was implementing an if statement to recognise the content of the payload. Because I was using the web service written my Jonathan Oxer it already had some device IDs preprogrammed so I used these until I decide upon my own. So LED0 on was 2-42 and off was 2-43. I wrote and rewrote the if statement but could not get it to recognise the contents, partly down to my lack of C++ knowlege. I eventually managed to get the payload contents output to serial and noticed it was suffixed with a ‘d’. Deciding I could live with this for now I included it in the search and everything lit up, literally. Need to get to the bottom of the ‘d’ though. Now I was happy with the program I added the second LED into the mix which worked fine.

Using a slightly modified version of Jonathan Oxers web service sending out messages via phpMQTT I can now turn on and off the prototype LEDs. Next step is to order some more Arduino and create the on/off switches to complete the circuit.

I have uploaded my code for the control module sketch to github which can be found here: https://github.com/jfarcher/mqttlightcontrol_lightside

I have also forked Jonathans web page and service and will be soon uploading my differences.

I will also be adding a video of the process to youtube soon.

The pubsubclient library for Arduino by Nick O’Leary can be found on GitHub:
with more details here:

Arduino Client for MQTT

New projects: Pi’s and Arduinos

Recently I’ve been working on several new projects, all of which use either a Raspberry Pi or an Arduino.

Site-To-Site VPN

A friend of mine recently opened a new satellite office, and as part of his day to day work had a requirement to connect the two together so resources on either side could see each other. Site-to-site VPN I thought, and what better kit for the task than a couple of Raspberry Pi’s. Nice and small so they can be kept along side the routers. Each site had a simple ADSL broadband link, with a couple of PC’s connecting up.

I’ll run through the complete setup in a seperate post as a Howto/tutorial, but the process was so simple to get them setup literally flash raspbian to a couple of SD cards, go through the motions to get a working console. I removed any unneeded packages, then installed and setup OpenVPN. After a bit of broadband/user error at one of the sites, simply opening the ports on the routers firewalls it all connected up beautifully. Fileshares and network based resources were all available wherever they wanted.

Home Automation
For a long time now I’ve been wanting to implement some kind of home automation system. After looking at X10 i was a little disappointed, as the technology was very dated and slow but also very expensive. Any other newer technologies were a little out of my price range, and also a very closed shop. So after about 12 months of it being on the edge of a project, a lot of research has been done and I think I am now in a position to put something in place. I’ll be using a mixture of Arduinos (or shrimps if I can), Raspberry Pi’s and other tech.

The idea is now coming to fruition due to a decision to transform all the lights in the house to 12v from 240v. This will make working with lighting a lot easier and safer, and cheaper due to not having to employ a spark to do all the connecting for me. The rough plan of attack will be to combine arduinos and mosfet transistors as switching mechanisms. Also implemented on these arduinos will be ethernet shields in order to connect the circuits up and have them centrally managable.

Essentially taking a traditional, feed -> switch -> bulb circuit and turning it into feed -> transformer -> arduino -> “switch” -> bulb. the switch component will be defined by the use of the light and could comprise of a push button SPST, an android app, a PIR or a combination of those. I plan to use a combination or software technologies for running all this, MQTT, python, PHP etc.

I plan to replace any fluorescent lights with LED strips, and have been toying with the idea of RGB here too which will bring a whole new depth to the lights. Many things to consider and a lot of exciting tech to play with, that is accessible, cheap and using open standards.

Exciting times.