Code written and more designs. 14 Sep 2016.

A project log for Aquarium controller / home automation

I am building an automated aquarium controller to fit into my home automation system.

pjpj 09/14/2016 at 11:060 Comments

Here I am on Tuesday September 13th 2016 and not much has been physically built but I have written something like 1000 lines of code. Written in three different computer languages namely, Python, Bash and Arduino-Sketch.

I have had some success attaching a water temperature sensor up to a nodemcu so I know I can do it (well... just!).

As I am an analyst/programmer I set too and tried to design something to see if i could get a Node mcu and an Arduino to send MQTT messages back to a central p.c. (Will replace P.C. with a raspberry pi or an ordoid at a later stage to shrink things down.)

Success!. I have been able to get the arduinode (as I am now calling them) to send (publish) mqtt messages to the mqtt broker on the p.c. and I have a python program resident on the p.c. subscribing to these messages - doing some calculation on the message (like temp too hot etc) and then sending new messages down the line for the arduinode to pick up, to, say, switch on a pump or a fan etc. Sorry, I am not explaining myself very well. Anyway that is the protocol I am going to use so that all my devices communicate over the same way. Sending message to and from each other. It is the way I am going to do my IOT (Internet of things) project. I hope it will expand so i can maintain the system over the internet at some stage. My first internet connection will be for the p.c. to send me an email if there is a problem (like tank overflowing! or similar - eeek!)

I have written a lot of the infrastructure now as I know I can get msgs going to and fro' and the devices that need to listen are listening and the devices that I need to talk are talking. I have written and re-written programs to try and standardise as much as possible and use industry standard formats like using JSON styled data structures and reading and writing of INI type files. I am using LInux as an operating system on the P.C. - it is easier for me as I know this system well and it is better than Windows. (in my opinion) (No flames please).

The design of the hardware has come on a notch too. Each Node (!) (see below) will have a project box with an arduino or a nodemcu in. Each box will also have a few relays, a power transformer from 240v to (approx) 5v, a connector block, a few leds (for information purposes) and a few sockets.

The overall system design is to have a passive server and an active node... I will explain...

I have thought about the number of messages going to and fro through the system and what it could do to my Intranet in my house (I share the network with 3 mobile phones, 1 internet TV and 4 computers). To this end I have now decided upon a passive server and an active node system. The server's code will be .... wait and wait some more until a msg comes in from a node.

The server will then decide if the message is for it and then decode the message (e.g. in plain English I mean.... I am the temperature sensor in the tank1 and the temp is to low). Once the server has decoded the msg it will then act upon it. E.g. Send message to Node2 to switch on pin3 which will then trigger a relay which will then switch on tank1-heater2. The Active Node system means that it reads the values of all its attached sensor devices. (Sometimes there will be only 1 sensor and sometimes more). Each node will have a small amount of intelligence in as much it will know if the value returned to it from the sensor is not within acceptable limits (E.G. Temperature high is > 25 or < 20) If it is not within limits the node then sends a msg over the network. (This is hard to explain sorry). This device will keep on sending msgs until the sensor value is within limits.

Now, sometimes a situation will arise when the sensor value will not change immediately (E.G. The water is not warm enough - switch on the heater - this will take quite a few minutes) So, with this is mind, when the first occurrence of the msg arrives at the server - code will be updated to when the next time that the server will read a message from this sensor.

I have designed this system this way so I can integrate another two systems into this with very little work, namely... my household (lights, curtains, garage doors, emails etc) and a Burglar Alarm system (door sensors, bells, strobes emails etc) and they could all work hand-in-hand if I wanted them to (E.g. Fish tank overflowing - sound off the alarm system ! )

All that would be required is a project box like the one below (or smaller/larger whatever) a small piece of code in the arduinode to define the acceptable sensor limits (E.G. On/off or door open/closed or Daylight-level low so draw the curtains etc etc etc) and some extra code in the server to act upon the msg. (E.G. Close the curtains, switch on the light, sound the alarm, switch on the strobe etc etc)

((I feel this project will last for ever and that worries me as I am a bit of a protagonist))

(((I am moving house aswell sometime in the future so this lot has to be uber-portable)))

Overall design of the Aquarium and water system. You will notice (below) that the end result of the tank water is to water a few flower pots. (Which is really why I am doing this whole thing!) (Just to see if I could!)