9.10.2024
Meshtastic (more here: Meshtastic - Network for the Zombie Apocalypse) is a network used for communication, at least in my area. However, various hardware can be easily connected to Meshtastic devices – these are the "things" in the commonly used phrase "Internet of Things."
We tested how to send information from a PIR sensor (motion detector) via the Meshtastic network. The PIR sensor is typically used in automatically activated lights or alarm systems, and is ideal for detecting movement cheaply (including humans, cats, martens... or even mosquitoes if misconfigured). While activating a light through Meshtastic may be overkill, using it for a basic alarm system in a garden shed without electricity is a perfect solution.
The entire Meshtastic device chain could look like this:
Meshtastic sends information over a single frequency channel. This channel is shared, and without additional configuration, Meshtastic devices broadcast to everyone. PIR sensor data shouldn’t be sent publicly because it could annoy others and cause a privacy breach. Meshtastic allows for the creation of a private encrypted channel. The easiest way to set this up is via the mobile app.
With remote administration set up, you can connect permanently via Bluetooth to the device with the siren and make any necessary adjustments from there.
The PIR sensor has its own settings page: "Detection Sensor." A detailed description is available on the Meshtastic website: Detection Sensor Module Usage. Three critical options are:
Settings can be tested without the PIR sensor attached. In a resting state, the device should not send any messages. When the GPIO pin is connected to ground, the device should send a detection message. This behavior corresponds to the following settings:
This ensures proper functionality when using a transistor to boost the PIR sensor signal and maintain correct logic levels.
We have three different PIR sensors available. The best in practice is the largest one (HC-SR501). Smaller, simpler sensors can't be adjusted, and if the sensitivity is too high, the sensor will trigger from every tiny movement, like a passing insect, causing many false alarms. The HC-SR501 allows adjustments for sensitivity, activation duration, and detection mode. The sensor is clearly designed for switching lights and offers two modes: The first mode: the light stays on as long as movement is detected. The second mode: the light turns on with motion but switches off after a preset time, regardless of further movement.
When the sensor detects movement, it sets the output to a logical 1. You can measure this signal with a modern digital voltmeter (an older analog voltmeter may have too low an internal resistance, which can affect the accuracy of the measurement), but the signal strength is too weak to drive the circuits in the Heltec Meshtastic device directly. Therefore, a switching transistor is needed to boost the signal. We used a BS170 (a switching FET), but many other bipolar switching transistors would likely work just as well.
The transistor operates against the internal pull-up resistor in the Heltec device. If the device lacks an internal pull-up, an external resistor can be used. In our case, the external resistor shown in the schematic wasn't necessary.
For experiments with the PIR sensor, a siren isn't necessary—you can use the Meshtastic device connected via Bluetooth to a mobile phone, which can notify you gently. However, a loud siren is a good addition to a security alarm system in regular use.
The siren is connected to the second, receiving device. We used a simple miniature speaker salvaged from an old PC. However, you can also use a real siren, as they often look the same but behave differently. Both can be used effectively.
In addition to a siren, you can connect a signal LED or a vibration motor (from an old phone) to the Meshtastic device. Both the LED and siren can be connected directly, although using a switching transistor as an amplifier might be useful. For the vibration motor, a transistor is recommended (though untested).
We encountered a key issue: the speaker only worked on GPIO 0 (likely the only pin supporting PWM).
Settings can be found under "External Notification" on the Meshtastic site: External Notification Module Configuration.
The critical settings are:
Similarly, you can connect an LED, a relay to activate a real ship siren for serious alarms, or any other alerting device.
An interesting option is connecting an I²S device, which sends an audio signal digitally (similar to MIDI or I²C). AliExpress offers various amplifiers for around one or two dollars, which can be connected to a speaker and power supply. However, we haven't tested this setup.