Internet of Lab Things

Brian Naughton // Thu 26 January 2017 // Filed under biotech // Tags biotech iolt nodemcu arduino

The ESP8266 board seems to be the new weapon of choice for IoT applications. As far as I can tell it is basically like an arduino except it has wifi built in, and, if you're willing to wait on shipping, you can buy one for under $3 on aliexpress.

The D1 Mini has a processor, wifi chip, micro-USB, and 16 GPIO pins

There are several ESP8266-compatible boards, and the WeMos D1 Mini seems to be popular. I bought this $4 HiLetGo D1 Mini on amazon. It includes conveniences like a micro-USB port, so you can plug it straight into your computer and get started.

This board runs nodemcu, an open-source firmware for ESP8266 that I'd never heard of, based on Lua. The name comes from its "nodejs-style networking", so a lot of internet/web libraries are built in. I'm a fan of Lua, so this was very appealing. Nodemcu describes itself as a "prototyping" kit, I think reflecting the fact that using a scripting language on a teeny board like this not ideal. I don't think this is a big problem, and the very nice example code on the main nodemcu site should allay many concerns.

How is this gizmo different to a raspberry pi?

I have a raspberry pi, and the learning curve for the D1 Mini is way higher. The raspberry pi runs linux, and you can treat it like a regular, but low-powered, computer. These D1 Minis are much more work: you have to flash the firmware (using nodemcu-build), copy code over from your laptop using a special tool (ESPlorer), worry about the voltage of the battery you are using, check the baud rate, solder things if you want permanent connections, etc...

If I were doing something where I don't care much about size or power consumption and I could plug into the wall, I'd just use a raspberry pi (or similar linux-capable board) and program it in Python. The one caveat is that connecting sensors to a raspberry pi will be about as difficult as a D1 Mini.

Internet of Lab Things

I think the main reason you'd want one of these things is to connect a sensor and report readings.

I thought it would be fun to have a small sensor that you can place in the lab, forget about, and collect all the data on a server. There are a few potentially useful sensors for a lab environment: detecting light, air particles/pollution, movement (presence of people), and vibration, but temperature and humidity are probably the main ones.

The sensor should be (a) battery-powered (b) low power (c) cheap (d) precise (or even better, accurate). I am using a DHT11 temperature and humidity sensor, which is a cheap, common sensor. There are lots of options for thermometers, but nodemcu can be compiled with built-in support for DHT-compatible sensors.

IoLT prototype: solar battery, D1 Mini, DHT11

Powering the D1 Mini

When the nodemcu is plugged into your computer, it is powered by USB. It turns out that powering the D1 Mini (and similar boards) is pretty complicated, especially if you're not used to thinking about voltages. There's an interesting video that goes into this issue in depth. My conclusion after watching this video was that this was something I'd really rather not deal with. For example, if you attach the wrong kind of battery, you can fry the board, or you can run out of power with a half-full battery (due to voltage drop over time).

I decided the easiest way to power the board was with USB. This is an unusual way to power these boards for some reason, but it solves many of the more "analog" problems associated with batteries. Luckily, since most smartphones are powered by USB, there are now tons of options. In fact, probably the most interesting thing about this project is how the D1 Mini is powered. On amazon, you can buy a 1200mAh solar-powered USB battery for $12! That means that it has about half the capacity of a typical smartphone! And it's solar-powered! And it has an LED flashlight!

Perpetual motion sensors

Because it's solar-powered, in theory the battery could recharge faster than the D1 Mini consumes power. The solar charging works best in direct sunlight, but it can collect power from indoor lighting too. I'm not sure what it would take for it to collect power faster than the sensor uses it, especially indoors, but I think it might be possible. (Importantly, the device can simultaneously charge while powering the D1 Mini.) Even with no solar charging, this battery should last for months — of course, that depends on how often you take a reading.

Deep sleep

The D1 Mini has a special deep sleep mode (engaged by connecting two of the pins) that allows it to conserve battery between readings, so the draw can go below 0.01 amps. More specialist equipment and knowledge would be required to really minimize the draw. For my purposes, this is good enough.

D1 Mini power draw during deep sleep

Code

All the code is in this IoLT github repo. The Lua code is a hundred lines or so, and the server code is about 20 lines (this is why I am such a big fan of AppEngine!) There are lots of places to improve the code (for example replacing HTTP with MQTT), but frankly the debug cycle here is a bit of a pain.

Conclusion

I love the idea of a self-contained sensor that continually reports back on its environment. If it can somehow be perpetually powered by light, then it would be perfect, but a year or two of power would be good too. The fact that this whole setup costs less than $20 is amazing to me. I think there's probably a commercial product in here somewhere.


Comments


Boolean Biotech © Brian Naughton Powered by Pelican and Twitter Bootstrap. Icons by Font Awesome and Font Awesome More