Mac Format

Hot tub timer machine

Control electronic gadgets from iOS

-

The Arduino controller is in the utility room, next to the boiler, which is too far away for Bluetooth to reach all the way to the sitting room.

That means I need to use Wi-Fi, but the Arduino Uno I’m using only comes with wired Ethernet support. I could add the official Arduino Wi-Fi shield but it costs £88 and that seems like a lot to pay, just for notificati­ons. At the other end of the scale is the ESP8266 Wi-Fi transceive­r. This is only £6.59, but it’s just a bare circuit board and would need quite a bit of work to integrate it with the Arduino. Luckily someone has already done this for me, in the form of the KOOKYE Wi-Fi shield, and this only costs £10 so it seems like the sensible compromise option.

The Wi-Fi module is designed to make the programmin­g really easy. It automatica­lly intercepts anything I print to the serial port and rebroadcas­ts it over Wi-Fi. I can connect either to my home router, or directly to a

remote server using a simple configurat­ion page. I want to send the current fill level of the hot tub to a web page, so that I can use Safari on my iPad to monitor it from the sofa. I sign up for some free web hosting and create a simple MySQL database to hold the data and then create a couple of scripts in PHP. The add.php script takes ‘post’ commands sent over the web and inserts a new record in the table and then index.php generates a web page to display the most recent record.

This works fine when I just send post commands from a browser, but doing it from the Arduino is another matter. The Wi-Fi shield automatica­lly handles the process of connecting to the remote web server, but before I can post to the database, I also need to log in to MySQL and I have no idea how to format the network packets to do this. Ironically, this problem has already been solved for just the bare ESP8266 transceive­r and there are excellent code libraries and online tutorials that I could cut and paste. But my Wi-Fi shield automates just enough of this process that the existing libraries don’t work, and it’s obscure enough that there aren’t any libraries specifical­ly for this board.

After two frustratin­g days trying to capture Wi-Fi packets and reverse engineer them, I give up and spend £60 on an Arduino Yun, which is what I should have done in the first place. This is the version that has built-in Wi-Fi hardware controlled by a separate processor on the same board. It is pincompati­ble with the Arduino Uno, but costs less than an Uno plus the official Wi-Fi shield. Best of all, since it’s an official Arduino product, it has

excellent library support.

Electrical failure

There’s just one teeny, tiny gotcha. My Arduino Uno has an on-board voltage regulator that accepts power anywhere from 7V to 12V and converts it down to 5V for the board. The new Yun skips this circuitry to save space and requires exactly 5V. I forget this important detail and connect my board to the 12V supply I was using for the Uno. Result: some interestin­g flashing lights and the Ethernet socket immediatel­y becomes too hot to touch. So now I have to buy another Yun and the total bill for this project climbs to £130. Remember when I said £88 was too much to pay for notificati­ons?

Out of the box, the Yun acts as a Wi-Fi hotspot. I connect to this from my iPad and access the configurat­ion web page at IP address 192.168.240.1. When I try saving the name and password for my home Wi-Fi, I get ‘AJAX Error 0’, which some forums suggest may be because of the ongoing legal spat between the different factions of the Arduino organisati­on at Arduino.org and Arduino.cc. The only suggested solution is to update the OpenWRT firmware, but this invalidate­s the Yun’s warranty and feels like a classic example of “when in a hole, keep digging”. I spend an hour looking at different forums and periodical­ly resetting the Wi-Fi settings and retrying, with no success. Then, as a last act of desperatio­n before I go for the firmware update, I try resetting the board all the way back to the factory default. And suddenly, mysterious­ly, the Wi-Fi configurat­ion wizard completes successful­ly! The moral of this story is… well, actually, I’m not sure what the moral is. Keep bashing your head against the wall until it breaks, I suppose.

Magic middleware

With the Yun now connected to the internet, I could go back to my original plan of posting hot tub readings to a database. But there’s a much sexier option. Blynk is a mobile app that lets you drag and drop widgets onto a phone or iPad and connect them over the internet to a remote microcontr­oller. The Blynk servers take care of all the network synchronis­ation and they provide template code to paste into your own Arduino sketches. It takes me a couple of minutes to create a simple interface on my iPad, with a status LED, a fill gauge and

I try resetting the board and, suddenly, the Wi-Fi configurat­ion wizard completes successful­ly!

a couple of buttons. By adding a few lines of code to the program that controls the hot tub, I can tell it to send the fill level to the Blynk servers and this is picked up by the app on my iPad. The communicat­ion works in the other direction as well – I can tap the buttons in the app to remotely start or stop the filling process. To alert me when the tub is full, I can set Blynk to send me an email, a tweet, or just a regular app notificati­on.

Insofar as any aspect of a hot tub in the garden can be deemed essential, being able to turn the taps on and off is obviously much more important than the ability to monitor the water level without pausing Netflix.

The beauty of the Blynk solution is that it completely isolates the iPad code from the software that controls the tap valves. That makes things much less likely to break and means that I can upgrade my iPad or change the UI layout without having to mess about with the Arduino code.

 ??  ??
 ??  ?? And to think Luis thought that getting the hot tub in place was the tricky bit…
And to think Luis thought that getting the hot tub in place was the tricky bit…
 ??  ??
 ??  ?? The hot tub controller blends seamlessly with the tangled mess of wires and pipes.
The hot tub controller blends seamlessly with the tangled mess of wires and pipes.

Newspapers in English

Newspapers from Australia