DIY – ESP8266/Alexa Powered Smart Fish

Smart Fish for a Smart Home – 3D Printed lamp housing.

If Apple made aquariums the Biorb Life tank is what it would be. Yes its modern but its also astonishingly expensive, £300 for something that really is worth no more than £50. But there we go, I have this ridiculous tank and I love it, now that the pain of paying for it is a distant memory. Unfortunately the Smart light at the top started flashing and causing me issues – presumably afte failure of one or more of the LEDs.

With Alexa you can set routines – like 30 mins before sunset turn Orange.

I looked at BiOrbs replacements and for the price of a small mortgage they have the Biorb MCR which offers any colour at the press of a button and it comes with a remote.

DIY Smart Lamp

Having made a number of projects using the ESP8266 wifi connected boards I thought I could make my own lamp if I could find a suitable LED and perhaps code up an app to change the colours.

Turns out its easier than that, with a little research all the building blocks are out there – if a little tricky to find out what they are called.

  • PowerDot 10W RGB LED – this was probably the most expensive part especially as I trashed the first one.
    • One issue I did encounter was that the blue stopped working and I thought this would be failure of the LED but it turned out that the solder was fractured, so simply re-flowing it with proper leaded solder fixed that.
  • ESP8266 – Generic, whatever happened to be on Amazon that day.
  • 40mm graphics fan
    • These are cheap and readily available.
  • 3D printed custom enclosure – I designed this is Solidworks in two parts that can be press-fitted together. I printed it in white PLA.
  • Software Libraries
    • Espalexa – library that simulates Philips Hue devices
    • FastLED – library that provides addressable LED functionality in addition to many colour utility functions, such as fading from one colour to another.
    • ESPAsyncWiFiManager – Generic library I always use instead of hard-coding the wifi credentials. This starts up a hotspot and then you can set the details using your phone.

I wanted to prolong the life of the fan as much as possible as its a moving part in addition to keeping the noise as low as possible (Although the aquarium is noisy anyway with the pumps etc). So using the FastLED library you can work out the power dissipation of the current colour and brightness, I use this to produce a power factor between 0 and 1 and then use that to control the fan speed. In the end the fan starts to turn at 25% brightness and the maximum duty ratio is 40% of full power – so even at full chat its almost silent. The only exception is that on start-up I run the fan at full power for 5 seconds before reducing the speed to blow off the dust and give the bearings a good thrashing.

At night the fan isn’t required and in the day (8hrs) it runs at about 40%. I used an N-Channel logic level FET to control the fan speed. The fan is brushless and doesn’t really like being powered by PWM signal, so I created a simple RC filter, so the fan see’s an average voltage. This also stops it singing at the PWM frequency.

Alexa

Once you have configured the library, you use the Alexa app to search for your device – here I called it ‘Fish’ and it identifies as a Hue Colour device. You could also have just white, dimmable, colour tuneable etc.

You can set routines with Alexa and have the aquarium come on at a specific time, or sunrise if you like. I found it to be a little hit and miss because I have 3 different echo dots on different VLANs (I think that is the issue) – so for the initial turn on and off, I add a 2 minute delay and then repeat the command and that tends to work. It may be that we get a fix in the library at some point.

FastLED

FastLED is a great library, but to fade from one colour to another you need to working the the HSV colour space rather than RGB. The library finds the approximate closest HSV colour to what you have or want and fades smoothly. But it has issues with secondary colours. So orange looked green, magenta looked red. This was a pain as you didn’t get the colour you asked Alexa for unless it was White, or RGB. So in the end as there is only a handful of colours Alexa recognises I hardcoded them in so that it would translate on the device.

ESP8266 Limitations

The ESP8266 struggled with PWM and FastLED libraries at the same time, because its doing the PWM in software. So you saw random flashes of solid colour from the LED with occasional glitching when fading colours. What I did was to disable the FAN PWM when fading. You probably wouldn’t ever notice.

Retro METAR Clock

Time and Weather

As an aviator its important to know what the weather is doing and in my case whether there is an point tuning up to the airfield.

I had been toying with the idea of making a retro LED clock for some time, but as I now have to use an ESP8266 connected device for everything because its cheap and east to use, I thought I could add value by displaying the current METAR. A METAR is an aviation text encoded weather observation that really belongs 100 years in the past, but is still useful. It tells us what the wind is doing, the pressure, cloud and visibility. These are all available online in JSON requests or via many free API’s. So all we need to do is make a web request.

The ESP8266 does not have a real time clock, but it is able to sync with NTP (Network Time Protocol) and keep time that way. So all we really need is the ESP8266 and the LED display.

Two 4 panel LED displays is too large for my 3D printer so its made it two halves. Simple affair, there is no back but it includes screw hangars and a notch for USB entry.
To join the two LED panels, I used 5 wire links between them.
CDS light cell / resistor tacked on to the board allows sensing of ambient light levels. Other than that its all driven directly from the ESP8266, the USB powers everything.
  • ArduinoOTA – allows for it to be updatable over the air, essential when its screwed to the wall.
  • Adafruit GFX Library – required for the LED panel.
  • MegunoLink – used to filter the light sensor data to stop the brightness hunting.
  • ArduinoJson@5.13.4 – specific version required to parse the JSON web request for the METAR data.
  • WifiManager – to create a hotspot to allow the device to be configured.
  • Max72xxPanel – the shift register driver for the matrix panel.

Refinements

I found that the string class, although very powerful, can lead to heap fragmentation on the ESP8266. The forums are not terribly helpful basically saying that people should learn to use char arrays and pointers instead and stop being lazy. Whilst that may be true especially on a tiny process with a few kb of RAM its not helpful when leveraging 3rd party libraries, particularly the JSON class – you could do this manually but its unwieldy.

The solution I went for is to restart the ESP every 24 hours instead to clear up the memory. The LED display will just retain whatever it was showing whilst the restart fires, and it only takes a few seconds. I may revisit this and refine it a bit later, but for now its perfectly workable.

Clones

As it happens by word of mouth I have made quite a few of these. Its ironic that the most expensive part is a nice USB cable! There’s one at Flightpath flying school at Wolverhampton Halfpenny Green.