Gas Sensor and RGB Lamp
This is the first MySensors node of the d-diot project. It is meant to be a repeater for other nodes and it offers the following functionalities:
- Detect GAS leakage
- RGB lamp
- Buzzer
- Acoustic (beep) and visual (Lamp flash) alarm when a GAS leak is detected
- Capacitive touch button to turn on and off the RGB lamp and to enable or disable the sound and visual alarm
- Radio activity LEDs
See the dedicated forum page if you need more information about this node.
Hardware
GP PCB Nano
The d-diot MQ2 gas sensor is built with the d-diot GP pcb Nano board.
This is a general purpose pcb, so its use is not limited to this node and you can use the board as a starting point to build any sensors or actuators you like. See the dedicated wiki page to know more.
The schematic, Gerber files and the entire Kicad project are available for download here and in the dedicated d-diot github repository, so you can easily get 10 of this PCB with about 5€ using an online PCB manufacturer like JLCPCB or PCB way.
Arduino Nano
The brain of the node is the well known Arduino Nano board. It is available in generic e-commerce platforms for few euros.
It is a 5V board so it is not ideal for battery powered sensors but for repeaters, actuators and “always on” sensors is a good choice because, thanks to the mini USB port, it can be easily powered with a common wall plug phone charger.
NRF24L01 Radio module
For the radio module you have a multiple choice. In fact in the market are present different modules. You need also an electrolytic capacitor (something between 4.7 and 47 uF is fine) to stabilize the power line of the radio module.
The 3d printable case is designed around the E-byte radio module (the green one in the picture). This module is the same used in the d-diot board, it is an amplified module (PA LNA) and it has an external shield that ensure a good signal range but it is a little more expensive respect to a non amplified module (the black one in the picture) and requires an external antenna.
So if you plan to use this node as a repeater for other nodes and you need an extended signal coverage, go with the green E-Byte module, otherwise save few bucks and go with a not amplified black module with integrated pcb antenna.
MQ2 Gas Sensor module
This module is sensitive respect to the following gas:
- LPG
- Smoke
- Ethanol
- Propane
- Hydrogen
- Methane
- Carbon Monoxide
in concentrations anywhere from 200 to 10000 ppm.
It has a digital output, that is adjustable, and an analog output, both used by the firmware
Read this article if you want to know more about how to this sensor works.
WS2812 ring 16 LEDs
This ring of 16 WS2812 addressable LEDs provides the RGB lamp functionalities to the node.
This component is available on the market in generic e-commerce platform like, for example Ebay.
Buzzer
This simple component is available on the market in generic e-commerce platforms.
It produces a very annoying sound adjustable in frequency that is perfect to catch your attention when a gas leakage is detected, or to wake up you in the morning.
TTP223 Capacitive touch button
This button is available on the market for few cents.
Respect to a mechanical button, it does not generate spurious open/close transitions when pressed and simplify the design of the external case.
3d printable case
The 3d model files and the print instructions of the case are available in thingiverse.
If you don't have access to a 3d printer, you can consider an online 3d printing service.
AMS117 3.3V voltage regulator (optional) and capacitors
This component and the two associated capacitors (C3 and C4) are necessary only if you are using an amplified radio module, that requires more current respect to what the 3.3V line of the Arduino Nano board can provide.
C3 is a 22 uF Tantalum capacitor, while C4 is a 10 uF ceramic capacitor. The input of the AMS1117 is selectable with jumper JP2 and the output with the jumper JP4
Spare parts
To complete the build you need the following parts:
- Male and female 2.54 mm pitch Pin Header
- 3 x 330 Ohm resistors
- 1 x 5 mm Red LED
- 1 x 5 mm Green LED
- 1 x 5 mm Yellow LED
- jumpers caps
- jumper wires
- 3 x M2.5 self tapping screw
Cost
A cost estimation of the node is reported below:
Part | Cost € |
---|---|
GP pcb Nano | ~0.50 |
Arduino Nano board | ~2.50 |
NRF24L01 radio module with capacitor | 1.50 - 4.50 |
MQ2 Gas sensor | ~1.50 |
WS2812 - 16 bit LED ring | ~2.00 |
Buzzer | ~0.25 |
TTP223 capacitive touch button | ~0.25 |
3d printable case | ~1.00 |
AMS1117 voltage regulator with capacitors | ~0.50 |
Spare parts | ~2.00 |
Total | 12.00 - 15.00 |
So for about 12.00 - 15.00 € you can build your own wireless MQ2 gas sensors and RGB lamp with sound and visual alarm. This node is also an ideal repeater for other MySensors nodes that are to distant from the d-diot hub.
Building
Print the case
Well, this is the most time consuming part of the building, but once you have started the print job, you don't have too much to do except watching your 3d printer at work, so you can proceed with the other steps.
The model files and print instruction are here.
The top and bottom parts of the case can be printed in about 3-4 hours each, with a layer height of 0.2 mm.
The rgb and radio led covers can be printed in few minutes with a layer height of 0.1 mm.
Solder the components
Use the interactive BOM tool to see where to place each component
You have to solder the following components on the GP PCB Nano board:
References | Component | Description | Quantity |
---|---|---|---|
C7 | Electrolytic capacitor | Capacitor for radio module (4.7 - 47 uF) | 1 |
R7 R9 R10 | Resistors for radio LEDs | Any value between 330 - 500 Ohm is fine | 3 |
D1 D2 D3 | Radio activity LEDs | Error LED = RED, TX LED = YELLOW, RX LED = GREEN | 3 |
U3 | Female Pin Header, 2.54 mm pitch | Socket for NRF24L01 radio module | 6 |
A1 | Female Pin Header, 2.54 mm pitch | Socket for Arduino Nano board | 30 |
BZ1 | Buzzer | Buzzer 12×9.5 mm | 1 |
JP5 | Male Pin Header, 254 mm pitch | Connects IRQ radio PIN to D2 PIN of Arduino | 1 |
The following components are optionals, you have to solder them only if you use an amplified (PA LNA) radio module:
References | Component | Description | Quantity |
---|---|---|---|
C3 | Tantalum capacitor, 22 uF | Output capacitor of AMS1117 3.3V | 1 |
C4 | Ceramic capacitor, 10uF | Input capacitor of AMS1117 3.3V | 1 |
U2 | Voltage regulator, 3.3V | LDO voltage regulator to power PA-LNA radio modules | 1 |
JP2 JP4 | Male Pin Header, 2.54 mm pitch | Input (JP2) and output (JP4) selector of AMS1117 3.3V | 2 |
The following components are optionals, you can solder the jumper wires directly to the board:
References | Component | Description | Quantity |
---|---|---|---|
P1 | Male Pin Header, 2.54 mm pitch | MYSX 2.6 Connector | 1 |
J3 J6 | Male Pin Header, 2.54 mm pitch, right angle | Vcc (J6) and GND (J3) power connectors | 2 |
The GP pcb Nano with the soldered components, including the optional one, should look like this:
Jumper configuration
- Short the jumper JP5 with a jumper caps to connect the IRQ PIN of the radio module to the D2 PIN of the Arduino Nano.
- Short the PIN 2 (U2 in) and 3 (Vcc) of the optional jumper JP2
- Short the PIN 1 (U2 out) and 2 (+3.3V) of the optional jumper JP4
Assembly and wiring
- With the Arduino Nano board and radio module inserted, place the GP pcb Nano in the bottom part of the 3d printed case.
- Fix the board to the case with the M2.5 self tapping screw.
- Connect 4 Female-Female jumper wires to the PINs of the MQ2 gas sensor module and fix it to the top part of the case with 2 x M2.5 screws
- Connect 3 Female-Female jumper wires to the TTP223 capacitive touch button and insert the module in the dedicated bay of the top part of the case.
- Solder 3 female jumper wires to the DI, GND and 5V pads of the WS2812 LEDs ring and insert the ring in the dedicated bay of the top part of the case.
- Connect the MQ2 sensor to the GP pcb Nano
MQ2 Pin | GP pcb Nano Pin | Wire color (picture) |
---|---|---|
Vcc | J6 | Yellow |
Gnd | J3 | Brown |
DO | P1 (MYSX) A5 SCL | Violet |
AO | P1 (MYSX) A7 | Green |
- Connect the TTP223 capacitive touch button to the GP pcb nano
TTP223 Pin | GP pcb Nano Pin | Wire color (picture) |
---|---|---|
Vcc | J6 | Yellow |
Gnd | J3 | Brown |
I/O | P1 (MYSX) A3 | Purple |
- Connect the WS2812 LEDs ring to the GP pcb nano
WS2812 Pin | GP pcb Nano Pin | Wire color (picture) |
---|---|---|
5V | P1 (MYSX) Vcc | Red |
GND | P1 (MYSX) GND | Black |
DI | P1 (MYSX) A4 SDA | Blu |
- Glue the rgb LED cover and radio LED cover on the top and bottom part of the case
- Close the case and mount the SMA antenna if you are using an amplified radio module
Firmware
The firmware for the GP pcb Nano board is available here; it supports different sensors and actuators (see here) and you can upload it to your Arduino Nano board with PlatformIO directly from your d-diot hub, following this guide.
Respect to the example reported in the guide run the following commands to download the d-diot nano repeater firmware
pi@d-diot:~ $ sudo -u homeassistant -H -s homeassistant@d-diot:~ $ cd /home/homeassistant/pio homeassistant@d-diot:~/pio $ git clone https://github.com/d-diot/d-diot-nano-repeater.git homeassistant@d-diot:~/pio $ cd /home/homeassistant/pio/d-diot-nano-repeater
If you have followed the wiring diagram in the previous section the PinConfig.cpp file should appear as follow:
If you have a different wiring, modify them according to your needs.
All the MySensors parameters are in the file MySconfig.cpp; if you are using a PA LNA radio module you can leave it unchanged, while if you are using a standard radio module change the following directive from:
#define MY_RF24_PA_LEVEL RF24_PA_MAX
to
#define MY_RF24_PA_LEVEL RF24_PA_LOW
If you don't need the repeater feature simply comment out the line:
//#define MY_REPEATER_FEATURE
By the default the signing features is enabled, so you need to personalize the node following this guide.
If you don't need the signing features, you can disable it commenting out the following lines in the MySconfig.cpp file
//#define MY_SIGNING_SOFT //#define MY_SIGNING_REQUEST_SIGNATURES
Other parameters, like the buzzer frequency, color and frequency of the visual alarm, double click time etc…, are in the MainConfig.cpp file. You can modify it according to your needs.
In the configuration section of the main.cpp file you can change other parameters like the update interval and the save state to EEPROM feature which will save your settings to the MCU EEPROM, so they will be consistent across power cycles.
Usage
- Single short button press: turn the RGB lamp on or off and force an update of all the sensors readings.
- Double button press in short time: turn on and off the sound alarm, so when a gas leakage is detected the node will inform you with an annoying sound. When the alarm is activated with the button press you can hear a confirmatory double tone with intervals and frequency defined in the MainConfig.cpp. When the alarm is deactivated with the button press you can hear a single tone with intervals and frequency defined in the MainConfig.cpp.
- Long button press: turn on and off the visual alarm, so when a gas leakage is detected the node will inform you with a flashing light. When the alarm is activated with the button press you can see a confirmatory double flash light with color and frequency defined in the MainConfig.cpp. When the alarm is deactivated with the button press you can see a double flash light with color and frequency defined in the MainConfig.cpp.
- You can completely control the node, including Buzzer and RGB lamp in the Home Assistant web interface.