Thursday, October 22, 2020

Bluetooth Mesh fog machine

A fog machine can greatly affect the ambience of Halloween displays but unless you invest in an expensive one they can be impractical. The machines that pop up around the holiday must be plugged in to the wall, are not weatherproof, and have relatively small "fog juice" reservoirs. Requiring AC power isn't uncommon for Halloween decorations and they are often installed close to the house, under the eaves or porch covering, so workarounds for the first two challenges are familiar. The obvious solution to the fog juice shortage is to only make fog when someone is around to appreciate it -- but how?

Completed build

Why Bluetooth Mesh?

Although standing around for several hours on Halloween night waiting to press buttons on remote controls might be an option for the most dedicated among us, ideally the remote controls would be able to activate themselves -- either in response to motion or the state of other devices. Similarly, running wires around the yard is fine in some situations but wireless communication is usually superior. A decade ago I would have advocated using IR to build a network that essentially consisted of a bunch of TV remote controls and receivers but now inexpensive radios are an attractive option because they:

  • Are arguably easier to work with
  • Don't require line-of-sight (or a convenient reflection)
  • Aren't affected by ambient light or fog
  • Allow bidirectional communication
  • Offer a path to smart device interoperability
The Bluetooth Mesh functionality that Nordic provides as part of the nRF Connect SDK (NCS) offers all of the advantages of using a radio plus one more that makes it especially interesting for a Halloween display: the behavior of the network can be reconfigured by modifying the devices' publication and subscription addresses using an app, without modifying any firmware. This means that, for example, next year when a second motion detector is added to the display one or more of the devices that used to be triggered by the original motion detector can be pointed to the new one with only a few button presses in the nRF Mesh app (Android or iOS).

Fog machine operation

The main components of a fog machine are a heater, a pump, and a fog juice reservoir. More sophisticated machines can also include features like timers, lights, or chillers but you probably won't find such extravagances on $40 machines like this one.

Fog machine internals

The large block on the right is the heater. The red wires above it are connected to a thermostat that acts as a switch -- it closes whenever the heater drops below a temperature threshold. Insulating material helps the heater stay hot for as long as possible and is visible next to the thermostat, poking out of the enclosure.

The silver cylinder to the left of the heater is the pump. Its job is to pull fog juice out of the plastic reservoir and push it into the heater so it can be vaporized and expelled from the front of the machine.

The entirety of the machine's wiring fits in a single diagram:

Fog machine schematic
When the thermostat is closed the electricity flows through the heater. During these periods the remote control, which connects via the three pins at the bottom of the diagram, is effectively "off." This happens frequently when the fog machine is producing fog because the heat stored by the thermal mass of the heater is used to vaporize the fog juice, causing the heater to cool. It also happens occasionally -- even when the machine is idle -- as the heater radiates heat to the surrounding environment.
Back panel of fog machine

Wired remote controls typically have a button and at least one LED. An LED that indicates when the machine is currently capable of producing fog is useful because it wouldn't be obvious otherwise.

Original remote control internals

This remote has two LEDs: one is on when the machine is capable of producing fog, the other when the machine is currently producing fog.

The original remote is a very simple device:

Original remote control schematic

In summary:

  • When the machine is ready to produce fog the thermostat is open and AC is available to the remote control via the BROWN and YELLOW/GREEN wires.
  • Connecting the YELLOW/GREEN and BLUE wires together powers the pump

Replacing the remote

Nordic's Thingy:52 is a prototyping platform that combines an nRF52832 SoC, rechargeable battery, and a bunch of sensors into a neat little package. Putting a 3V microcontroller in control of the fog machine requires solving two problems:

  1. Detecting the presence of AC to determine that the machine is ready to produce fog
  2. Operating a switch to open and close an AC circuit

The first problem can be solved with the help of a cheap 5V wall wart. By taking it apart and connecting it to two of the wires from the original remote the Thingy:52 will think that it's plugged into USB whenever the fog machine is ready. As a bonus, this will also recharge its battery -- the same battery that keeps it from browning out when the heater becomes active!

5V wall wart

Wall wart schematic

The 5V from the wall wart is also hardwired to an LED on the top of the new remote's enclosure, to replicate the original remote's functionality. This 5V also supplies power to a separate board -- a board that solves the second problem by using a BJT transistor to open and close a 5V relay. This allows a GPIO output from the Thingy:52 to operate the relay, effectively replacing the functionality of the original remote's button.

5V relay schematic

5V Relay protoboard

Manual operation is useful, especially when positioning the fog machine during setup, so a large push button was also added to the new remote.

Button schematic
Finally, an external power switch is needed so the rechargeable battery can be disconnected when the fog machine is in storage. The addition of seven wires, including one from VDD to the external power switch's LED, is the extent of the required modifications to the Thingy:52 itself.

Firmware

The Thingy:52 already has a USB_DETECT pin that is pulled high when 5V is present on the USB port so keeping track of when the fog machine is ready only requires enabling a pin change interrupt on a GPIO. The button for manual operation is handled the same way. Using a GPIO output to control the relay is even easier.

Adding Bluetooth Mesh is also pretty straightforward, at least when starting from the Light Switch sample in NCS. The original Light Switch sample enumerates four Elements, one for each of the LEDs on a typical Nordic development kit. Each Element has a Generic OnOff Server that allows the other devices on the mesh network to read and write the state of one of the LEDs.

The remote control only needs two of these servers:

  1. The server in the first element works like the button. Setting this element to 1 will produce fog until it is written back to 0 or the heater becomes active. It is automatically set back to 0 when the heater becomes active. If the fog machine is not able to produce fog then setting it to 1 has no effect.
  2. The server in the second element is set to 1 when the fog machine is capable of producing fog and 0 when the heater is active. Writing to this element has no practical effect because the written value will be immediately reverted. A client can read this value to determine whether or not the fog machine will be able to immediately produce fog.

The firmware, along with details for provisioning the node, are posted here. The nRF Mesh app is used for provisioning and configuring the node. It also presents a nice GUI that enumerates the Elements and their servers:

The app also allows for interaction with both of the servers. Selecting one of them and then scrolling down leads to a "Generic On Off Controls" widget:

The "READ STATE" button at the bottom does exactly what it claims and the state of the server can be toggled by pressing the "ON" button.