# Gerrit Niezen

Maker of open-source software and hardware.

## Which LoRaWAN module to use in 2021

If your electronics projects needs to talk to other devices, but you don't have access to WiFi, LoRaWAN is a great alternative. The Things Network (TTN) is a global collaborative Internet of Things ecosystem which allows devices to use the network for free. No payment or SIM cards are required like with NB-IoT or Helium, you just need to keep to the usage limits.

The problem is that there are very limited options for LoRaWAN modules, given the current global chip shortage. As I'm based in the UK, I'm looking specifically for 868MHz modules.

The RN2483 LoRaWAN module from Microchip used to be the de facto option when you don't want to run a LoRaWAN stack on your microcontroller. Unfortunately they are out of stock until 2022 or later. Luckily there are other options, so let's have a look at what's out there.

## RAK3172

RAK Wireless has a range of LoRaWAN modules where different microcontrollers are combined with LoRa chips. The RAK3172 is their first module that uses the STM32WL, combining a microcontroller and LoRa on the same chip. It comes preinstalled with a LoRaWAN stack, so you can use it with your own microcontroller over a UART interface.

## LoRa-E5

Seeed Studio's LoRa-E5 module also uses the STM32WL chip, and is also controlled over a UART interface if you use the preinstalled stack.

Unfortunately both the RAK and Seeed modules suffer from a high transmit power consumption bug, which look like it may not be able to fix in firmware without reducing the range significantly.

## Ra-07H

Ai-Thinker's Ra-07H uses the ASR6501 chipset which also combines a LoRa transceiver with a microcontroller, and can also be controlled over a UART interface.

## E78

Ebyte's E78 module is also based on the ASR6501 chipset. It appears that both the Ra-07H and E78 modules are compatible with TTN v3.

There are other LoRaWAN modules out there, like Move Solutions' STM32WL-based MAWLE-C1, but the ones above are ones that were actually in stock at the time of writing.

#IoT

## 5 different ways to measure air quality

The WHO Global Air Quality Guidelines mention five different pollutants, but what are they? Let's have a look.

## Particulate matter (PM2.5 and PM10)

Particulate matter (PM) are inhalable particles smaller than 10 micrometer (PM10) and 2.5 micrometers (PM2.5) respectively. PM can consist of things like mineral dust, ammonia, nitrates and black carbon. The WHO limit is 15µg/m³ for PM2.5 and 45µg/m³ per 24 hours.

## Carbon monoxide

Carbon monoxide is produced by burning wood and fossil fuels like natural gas, petrol and kerosene. You can't see, taste or smell it, but in high levels it can kill you. The WHO limit is 4mg/m³ per 24 hours.

## Nitrogen dioxide

Nitrogen dioxide is reddish-brown in colour and is produced by fossil-fuel based heating, transport and power generation. It irritates airways and is linked to asthma and other respiratory diseases. The WHO limit is 25µg/m³ per 24 hours.

## Ground-level ozone

When nitrogen oxides (NOx) react photochemically, they form ground-level ozone, which is a major component of smog. Ozone causes problems breathing, triggers asthma and leads to lung disease. The WHO limit is 100µg/m³ per 24 hours.

## Sulfur dioxide

Sulfur dioxide is yet another pollutant produced by the combustion of fossil fuels like coal. It is a colourless gas that easily dissolves in water to form sulfuric acid. The WHO limit is 40µg/m³ per 24 hours.

Interesting how many of these air pollutants are fossil fuel based, and if we just stop burning stuff, it helps to prevent climate change too. Who knew?

## 4 things you can do to improve air quality

You already know that air pollution is a big problem, but you're not sure what you can do about it personally? Instead of waiting on the government or other people to solve the issue, here are 4 practical things you can do to improve air quality:

## Stop burning stuff

Wood-burning stoves are one of the leading causes of air pollution in countries like the UK. Even a candle in your living room emits particulates. While we may have romantic or cozy feelings towards burning stuff, it's not great for our lungs.

Even electric cars emit particulates when braking, so the best way to get yourself from A to B is on a bicycle or by walking. For longer journeys, public transport is the way to go.

## Grow plants

Back in the 1980s NASA did this study to show that plants are great at purifying the air. Though later studies didn't quite replicate their results, having some beautiful green plants in your house is never a bad thing.

## Switch to an induction stove

Gas stoves generate a lot of particulates during cooking, and you can cut down on this by using an induction stove instead. Is the convenience of a gas hob really worth the risk to your family's health? You may just find that a modern induction stove is just as convenient as the gas version.

## Choosing a battery charger chip for your solar-powered project

With the current global chip shortage it can be challenging to find the right chip for your project that's actually in stock. I want to share some of my own challenges and what the options are. First up: What LiPo battery charger chips can be used with solar panels?

## Moisture sensor

To know when I need to water my seedlings in the propagator, I got an analogue capacitive soil moisture sensor for £3.67 (including P&P).

The pinout is a simple three-wire interface, with Vcc, ground and the analogue output pin. To read the values, I just needed to do the following in Espruino:

const moistureSensorPin = A5;
const airMoisture = 955;
const waterMoisture = 670;

pinMode(moistureSensorPin, 'analog');

const moisture = Math.round(analogRead(moistureSensorPin) * 1000);
const moisturePercent = Math.round(map(moisture, airMoisture, waterMoisture, 0, 100));
console.log(Moisture is ${moisture} ~${moisturePercent} %);

if (moisturePercent < 16) {
console.log('Needs more water');
}


To get airMoisture and waterMoisture, I took readings from the sensor when it was dry and placed in a glass of water respectively. The map() function I got from the Arduino libraries:

function map(x, in_min, in_max, out_min, out_max) {
// from https://www.arduino.cc/reference/en/language/functions/math/map/
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}


I place the sensor directly under the rockwool cubes of the seedlings to measure the moisture content.

## Water level sensor

To detect the height of the water level sensor, I'm using a VL53L0X LIDAR sensor, that uses a laser and time-of-flight measurements to accurately measure distances between 50mm and 1200mm. It's pretty amazing that they can fit a laser and a detector into a package that's barely larger than a grain of rice.

The sensor uses an I2C interface, so I connected the pins as follows:

• SDA pin to Espruino B3
• SCL pin to Espruino B10
• GND pin to ground
• VIN pin to Espruino 3.3V
• X pin to Espruino 3.3V (maybe not necessary)

To set it up in Espruino, you just do:

  I2C2.setup({ sda: B3, scl: B10 } );
laser = require("VL53L0X").connect(I2C2);


To then perform a measurement, you do:

// measure water level
const distance = laser.performSingleMeasurement().distance;
if (distance > 20) {
console.log(distance, 'mm');
// TODO: minimum water level notification
}


I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com.

For my hydroponics setup there are a bunch of reasons why I would want to be notified of an issue, e.g.:

• Temperature of range
• Lights on/off outside of schedule
• Water overflow
• Humidity out of range
• Water level too low

Since my setup is based around using Bluetooth LE for wireless communication, that means I need to think about how to get notified about these issues on my mobile device.

It used to super simple to get mobile notifications in Android from Bluetooth using Eddystone-URLs, but Google disabled this in 2018 due to abuse by marketers. Eddystone and iBeacons are now only supported in native apps.

It is possible to send web push notifications from a PWA, but this requires service worker support, which is not supported by Web Bluetooth yet.

This leaves having a web server somewhere within range of the Bluetooth device, that can subscribe to Bluetooth notifications an send send these out as web push notifications to your mobile device.

Edit: There is also another option: The Physical Web Association now provides an unbranded native app that can be used to interact with Eddystone-URL beacons. Maybe this app can then launch the PWA?

I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com.

## Hydroponics: Controlling AC mains devices

For my hydroponics setup, I want to be able to turn on and off both the LED grow lights and the water pump using a microcontroller. This is typically done using relays, and is the implementation I described in yesterday's blog post.

I've been thinking it over more and realising that having a solution that can be implemented by anybody shouldn't rely on dealing with AC mains voltages and wiring. Smart plugs using Bluetooth or WiFi having been coming down in price a lot, to the extent that they're a viable alternative to relays, especially if you take the cost of AC sockets and enclosures into account. If you don't want to have exposed wiring, you may want to consider putting your electronics inside a plug case.

## Smart plug options

Bluetooth LE smart plugs are used by HomeKit and Philips Hue, but they're still a bit expensive at around £30 per plug. They also don't make use of the standardised Bluetooth profiles and services, but implemented their own proprietary BLE services.

WiFi smart plugs are around £10 each, and you can buy a WiFi power Strip with 3 outlets for £30. Unfortunately these smart plugs are getting more locked down, where you may be forced to use the manufacturer's app and proprietary API to get access to the plugs.

Thanks to Espruino's excellent documentation, I found another option: remote control sockets at around £5 each. They operate in the 433MHz range, which means you use a dirt cheap 433MHz transmitter to talk to them.

I really like this last option, as they use a simple wireless protocol that's easy to implement, and they're almost cheaper than using relays.

I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com.

## Hydroponics: Setting flood interval and duration

For my ebb-and-flood (also called flood-and-drain, or ebb-and-flow) hydroponics system, I need to pump water over the flood table at regular intervals. The time between flooding depends on various things, of which the growing medium is the deciding factor:

• Expanded clay pebbles: 4 to 8 times a day (every 2 to 4 hours)
• Coconut coir: 3 to 5 times a day (every 3 to 5 hours)
• Rockwool: 1 to 5 times a day (once a day to every 3 hours)

I'm going to put rockwool starter cubes in expanded clay pebbles, so every 3 hours sounds like a good idea. I then also need to figure out how long to flood the table for, which depends on how quickly the pump floods the table. Let's say it's around 30 seconds, which then leads to the following Espruino script for my Pixl.js:

const floodIntervalMinutes = 180;
const floodDurationSeconds = 30;

const pumpPin = B15;
const waterSensorPin = B3;

setInterval(() => {
console.log('Water detected!');
digitalWrite(pumpPin, 0);
}
}, 1000);

setInterval(() => {
// TODO: check if daylight
// TODO: max delay between floodings

digitalWrite(pumpPin, 1);

setTimeout(() => {
digitalWrite(pumpPin, 0);
}, floodDurationSeconds * 1000);

}, floodIntervalMinutes * 60 * 1000);

function onInit() {
pinMode(waterSensorPin, 'input');
pinMode(pumpPin, 'output');

E.setTimeZone(1);
console.log('Current time:', (new Date()).toString());
digitalWrite(pumpPin, 0); // make sure pump is off
}


Note that I also added a water sensor for switching off the pump in case there's an overflow.

What I still need to do is to add a light sensor to check if there's daylight, and then only flood during daylight hours. I then also need add a maximum delay between floodings, so that the plants don't go for more than 12 hours without water. Thanks to ChilliChump for these ideas.

I’m publishing this as part of 100 Days To Offload. You can join in yourself by visiting https://100daystooffload.com.

## An API for plants

This morning I discovered Trefle, an API for plants, through the r/hydro Reddit. What is exciting is that it does seem to cover a number of the variables I'm looking to include in my growing spreadsheet:

• days to harvest
• pH range
• light range
• temperature range

There are also other interesting fields, e.g.:

• humidity