RF (Radio Frequency)

Enter Your Project for a chance to win a Spectrum Analyzer for the Most Innovative RF Project!

Back to The Project14 homepage

Project14 Home
Monthly Themes
Monthly Theme Poll

 

What it is

This will demonstrate how to make a mail box sensor that will last for years on small batteries so you will not miss any holiday cards or presents.

att push

Live dashboard.

 

Features

  • How to select appropriate hardware for low-power devices
  • Getting started with LoRaWAN and The Things Network
  • Configure integrations with TTN for data visualization and alerts
  • How to measure power consumption in the mA and uA range
  • Low-power tricks
  • Visualize LoRaWAN signals with SDR
  • Simple weather-proof enclosures

 

Requirements

  • Basic electronics, soldering and Arduino experience
  • Arduino environment (Arduino IDE, Visual Studio Code or similar)
  • Access to a The Things Network LoRaWAN network
  • The Things Network-account
  • Wisen Talk2 Whisper Node LoRa
  • FTDI programmer
  • Micro switch
  • Soldering station
  • Wires, resistors, breadboards etc.

 

Recommended equipment

 

Background

I started this project 2 years ago when the amount of physical post was decreasing and we were fed up with finding an empty mail box most days of the week. As many in the element14 community, we still eagerly await exciting packages from all over the world on a weekly basis, so leaving it unchecked for several days was not an option. At this time I was getting into embedded systems and lpwans. Putting together an Arduino with a LoRa-transceiver powered by a wall adapter is all well. Having a device last for years on small batteries in cold Nordic climate are miles apart with regard to hardware, software and necessary power profiling. The device has so far lasted for 2 years on the same 2xAAA batteries and it has come to be so reliable that I can't comprehend how we lived without it.

 

With a background in software development this was my first long running electronics project and as my experience has grown quite a bit in these two years, it was time to revisit the project.

deploy2

 

Evaluation and improvements

For all it's shortcomings what I got right the first time was power consumption. My measurements when deploying it showed a consumption of 8.70uA in sleep mode and an average of 8.62mA during 6 seconds of transmission (43.5uWh). The 2xAAA Energizer batteries show a voltage (though not under load) of 3.175 volts after 2 years of operation through all kinds of weather, sometimes below -10 degrees Celcius. The first 10 months it sent almost 600 messages, at which point I lost data.

Otii original

 

  • The mechanism of operation may seem oversimplified but it has proven reliable and fit for the job.
  • I have wanted to cast a resin enclosure for esthetics and weather proofing.
  • The application code and circuit could be simplified and improved a little bit.
  • The alerts have worked nicely and will be untouched.

 

Microcontroller

For this project I used the development board Talk2 Whisper Node by Wisen. It is by no means high-tech or small but the components offer the best option for low-power consumption I have tried so far. Featuring a tried and proven Atmel AVR ATMega328p it also features highly efficient step-up regulator and a RFM95/96 LoRa Radio (Semtech SX1276). For board setup in Arduino environment, libraries and excellent documentation go here.

Whisper node old

 

Pinout

Whisper Node pinout top

Whisper Node pinout bottom

 

To use it as a LoRaWAN device you need to close jumper 15. This requires some SMD soldering with the supplied zero-ohm link.

Zero ohm link

I used a Weller SMD tip, but you could probably get away with a much larger tip. The problem arises as you can hardly heat up only one side and the link has a tendency to come off with the soldering iron. I held it in place with a pair of pliers.

Jumper

 

3 volt battery supply

For powering the device I have used 2 AAA Energizer batteries. I highly recommend using some quality batteries as the first cheap no-brand set I tested stopped working after having been out in sub-zero temperatures. For an introduction to measuring current consumption in the mA and uA range, please allow the creator of the board Mike Musskopf explain:

 

uCurrent Gold and multimeter/oscilloscope

I found using a multimeter for monitoring power consumption a bit coarse, as it was hard to tell what was going on on the MCU at a given point in time. I experimented with combining uCurrent and an oscilloscope. First it was hard to make out the weak signals, and it turned out the step-up regulator was draining what I was looking for in noise. When I bypassed the regulator it worked pretty well. Then only problem now was that I was not measuring the whole system, so I could not trust the results to be representative of real-life operations. The other problem I faced was to display the power consumption alongside serial output, using the scope's serial decoder. This would allow me to know what part of the code was running with simple println's. It worked in theory, but in practice it was hard to scale in any usable manner on the time scale.

uCurrent

Otii Arc from Qoitech

The Otii Arc combines power supply, ammeter, voltmeter, serial decoder, graphing tools and many more things into one easy to use package. It is even good for nA values.

Otii Arc setup

I have slightly improved power consumption in sleep mode (now average of 8.31uA) and while transmitting by simplifying the circuit and some minor code changes. Using the Otii Arc in this way is a great workflow to take the guesswork out of power optimization. I only wish I could program the board over FTDI with the Arc.

otii improved

Otii improved 2

I believe you can download and install the client to view my power profile.

 

Coin cell power

Please have a look at the tutorial that got me started with low-power. It is based on LoRa between two nodes, and not LoRaWAN, but the methods of measurement and discussions on pulsing when powering with coin cell batteries are well worth the read. The forum contains discussions on how to achieve coin cell battery powered LoRaWAN devices, something I wish to test further at some point. For this I wish I could get my hands on an enterprise license for the Otii Arc for the battery profiles and battery profiling tools.

 

Mechanism

I started this project by creating a mock post box using foam board. This is a great way of quickly prototyping physical mechanisms and gave me room to experiment without losing mail - pluss my kids still play with it! I made a list of possible mechanisms of detecting if mail had been received. Most solutions were either too power hungry or too fragile, or both:

  • Infrared - power hungry, hard to cover all the space
  • Ultrasonic - same as infrared
  • Weight - too fragile for small pickup notes, would probably get misaligned from dust etc.
  • Camera - forget it

 

I was left with reed switch and micro switch. My initial experimentation with reed switches proved they would be a bit problematic to mount and to align right.

mock

 

Micro switch

So a micro switch will not actually tell if you have got mail or not. It can't tell if the post carrier has deposited mail from someone having opened the lid to check. I can only tell you that it has worked well for this application and I am going to keep it. Basically the switch is connected in a Normally Open configuration. When the lid is opened the switch goes to closed (not depressed) and this closes the circuit. The Arduino-compatible microcontroller is sleeping and waiting for a falling edge interrupt. The circuit is connected between an interrupt capable pin (D3) and GND. The pin is pulled up, using built-in resistor.

 

The following pictures are from when I first experimented with micro switches so it is connected Normally Closed, but the mounting has stayed the same.

Micro switch 1

Micro switch 2

Circuit

For some reason I did not know about the built-in pullup resistors on the MCU, or I didn't understand how to use them. Therefore I made a simple external circuit that did the same. I had used a 10k Ohm resistor, for who knows what reason.

circuit old

I used the opportunity in this revisit to get rid of this all togheter. Now I only use a digital pin on the board and configure it with 20k Ohm internal pullup. This is connected to GND via wires and the switch.

 

Schematic

Schematic

 

Arduino code

Libraries used

  • T2WhisperNode
  • LowPower
  • Arduino-LMIC
  • RadioHead

 

I will refer to example code for setting up and transmitting packets to The Things Network. Basically the code makes sure to put unused features to sleep, authenticate with TTN, sleep until interrupted and then send battery voltage when the mail box lid is opened. I also add a 8 second grace period where the device sleeps not listening to interrupts. This is to ignore multiple openings of the lid in a row. Feel free to explore the source code to investigate.

 

Interrupt is configured in this way:

pinMode(wakeUpPin, INPUT_PULLUP);

 

When the board goes to sleep I register this pin as an interrup with falling edge.

myRadio.sleep();
attachInterrupt(digitalPinToInterrupt(wakeUpPin), wakeUp, FALLING);
LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF);

 

You can't use any old pin, on the ATMega328p only pins 2 and 3 support interrupts. I use pin 3. See documentation and examples.

The Interrupt Service Routine does nothing, the code just resumes and the lmic-library takes care of the next transmission.

void wakeUp() 
{
}

 

Note: After a change in Arduino I had to follow this instruction to be able to compile lmic.

 

The creator has posted a tutorial about setting up the board for TTN integration using a simpler library, TinyLora by Adafruit. The only reason I haven't used this is because it currently only supports ABP authentication and not OTAA that I prefer.

 

The Things Network

There are many great guides on setting up a TTN application. After registrering a device in the usual manner a custom payload decoder has to be defined to piece together the voltage measurement. Source code.

function Decoder(bytes, port) {
    // Decode an uplink message from a buffer
    // (array) of bytes to an object of fields.
    var decoded = {};
  
    if (port === 1) decoded.battery = (bytes[0]<<8 | bytes[1]);
  
    return decoded;
  }

 

For this project I have experimented with many different integrations. In the end all I needed was a notification on my devices. AllThingsTalk provided this in a pretty simple manner. I refer to the documentation on how to set up the integration and define devices.

TTN-ATT integration

att device

A custom decoder has to be defined on the ATT side also, it does exactly the same as the former decoder, but in ABCL. Source code.

{
    "name": "mailboxsensor",
    "comment": "Sent when lid opens, with battery voltage.",
    "version": "1.0.0",
    "sense": [
      {
        "asset": "Voltage",
        "value": {
          "byte": 0,
          "bytelength": 2,
          "type": "integer",
          "signed": false
        },
        "comment": "Voltage value as millivolts."
      }
    ]
  }

 

Att decode

 

I also defined a watchdog that will supply a trigger for a rule that will notify when it has not heard from the device in a few days. This has triggered when there has been problems with my LoRaWAN gateway, before redundant gateways were deployed where I live.

att watchdog

att rules

att rule lid

 

Debugging with SDR

Whenever I take on a new development environment I reach out for debugging tools. For the microcontroller the Otii Arc and Atmel ICE are examples. For LoRaWAN I have experimented with visualizing the radio signals using Software Defined Radio. So far I have a setup of the Airspy R2, a 868MHz filtered preamp from Uputronics and a omni-directional antenna Sirio OMNI 900. Using SDR# and SDR-RADIO I have been able to identify my transmissions. Although I can't decode the actual payload there are a few handy advantages in development:

  • Are my devices actually transmitting?
  • At what band/frequency and spreading factor?
  • Gauge approximate signal strenght
  • Airtime
  • Collisions

airspy

 

preamp

Another really valuable tool is to get a sense whether the device antenna is appropriate. I have gathered that a lot of (cheap) LoRa-devboards are sold with incorrectly tuned antennas. A spectrum analyzer would be a better tool, but my lab is missing this, for now..

sdrlorawan1

sdrlorawan2

sdrlorawan3

 

I have made some attempts in actually being able to visualize the chirping of the signals. Without a spectrum analyzer I believe I need to use a transceiver that can transmit with SF 12 and 7.8 kHz bandwith to be able to see it live.

 

More on reverse engineering LoRa (not WAN).

 

Enclosure

For the enclosure I have relied on a simple weather proof electrical box (ABB). It is IP65 rated, but after making holes for antenna, wire and screws I can see a tiny amount of dust has penetrated.The main thing is that it has not shorted or corroded the electronics. After  having heard Ben Ward talk about his experience with deploying home made sensors with the Oxford Flood Network, I do admit I was somewhat nervous if the bomb squad would be waiting for me when I got back after the first deployment.

squad

A while later my local makerspace (Makerspace Bodø) bought a vinyl cutter, Silhouette Cameo 3, and this enabled me to make it look a bit less threatening. Please keep this in consideration if you are planning on deploying a project like this in public.

Vinyl 1

It consists of two layers of different color vinyl aligned with transfer tape.

Vinyl 2

Vinyl 3

 

deploy1

Resin casting custom enclosure

Lastly I have started designing a custom enclosure. This will be 3D printed and sanded with filler before I make silicon molds. Then I can cast using resin. Here is a sketch of what I have in mind, including some teaser pictures of previous castings I have made for what's to come.

sketch

mold1

mold2

mold3

Conclusion

I am really proud of this project and impressed it has stayed so reliable and useful. It has in many ways reminded me that the simple solutions often are better. I hope this may inspire other makers and tinkers to start similar projects. My only regret was not setting aside a identical battery for comparison with self discharge.