WebLED: my first IoT project on the Arduino platform
...or: how to open a garage door using WiFi
I am quite a physical guy, and it reflects also on software. For a long time I've wanted to get more into embedded stuff, but with the lack of time and so many things to do, I needed an excuse to motivate me to familiarize with the Arduino world. Luckily my parents' old place has a motorized garage door which I sometimes use, but since I don't have the remote, it's not always that handy. I found a super cheap chip, namely the ESP8266, which is Arduino-compatible and has WiFi without any extra Arduino shields.
Originally I wanted to make an Android application to operate the door, but I opted for a website, as there are web server libraries already available for the Arduino.
Planning and building
I have a friend who's done a lot of Arduino stuff already, and he recommended I use PlatformIO instead of the Arduino IDE for development. I did test the connectivity with the IDE at first, but realized really soon PlatformIO is the way to go. For getting started I bought a LinkNode D1 development board, which was one of the only ones available in Finland. It's a nice looking white PCB and did the thing nicely. For the final installation I used a WeMos D1 mini. You can get about ten D1 minis from China with the price of one D1 from Finland.
The program is very simple: serve a web page and blink a LED (or send another signal, i.e. open the garage door) on POST request. Still, a simple project like this already makes you bump into several problems. From where do you serve the web page, as there's no storage? What about current transients on power up, will they open the door accidentally? What about the voltage differences between the devices? And how much current does the chip handle? It's a fascinating world when there's actually the possibility of something exploding or at least breaking up.
For serving the website, I decided to use a build script to convert a standard HTML file into an includable header file and embed it into the program code. That way it's easy to code and style the web page using a browser. The WiFi config file is also converted into a header file.
As for the physical connection, some kind of relay was needed to close the garage door opener circuit. I used a BC548 transistor, which has a collector-emitter and a collector-base voltage of 30 V. The garage door opener circuit operates at 20 V so it's within limits. The ESP8266 output pins have a 3.3 V voltage, and the base-emitter on voltage of the BC548 is around 0.7 V. The maximum current of a GPIO pin on the ESP8266 is 12 mA. So, aiming for around 8 mA of current to drive the transistor, the equation R=U/I gives about 320 Ω for the resistor to put between the output pin and the transistor.
My friend has a Saleae Logic Pro 8 logic analyzer which we used to check out if there would be any potentially dangerous transients when power was toggled - you don't want your garage door to open after there's been a blackout. There actually were some very short-lasting current spikes, so we ended up soldering a capacitor between the transistor base and ground. It eliminated pretty much all the transients. After the whole thing was done, it was time to package everything using heat-shrink tubing.
The final product
I named the project WebLED and made it available on GitHub. It's now been in use for a few weeks and everything works perfectly. The ESP8266 has a surprisingly strong WiFi signal, and easily works from dozens of meters away.
I also recorded a video of the device in operation, embedded below from YouTube.