sensors_and_actuators:mysensors:gp_pcb_nano

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.

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.

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.

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.

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.

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.

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.

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.

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.

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

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

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.

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.

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:

  • 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
  • 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.
Case bottom with GP pcb Nano
  • 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.
Case top with modules
  • 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
Wiring
  • 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

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:

Click here to see the default PinConfig.cpp

Click here to see the default PinConfig.cpp

/home/homeassistant/pio/d-diot-nano-repeater/src/PinConfig.cpp
/* d-diot nano repeater - PIN configuration
 On the basis of the devices attached to your Arduino nano, comment or uncomment the following lines.
 Change the PIN number according to your needs. 
 PIN 2-13  = D2-D13
 PIN 14-21 = A0-A7 
 
 The following pin are not available and defined in MySConfig.cpp
IRQ PIN = D2
CE PIN = D7
CS PIN = D8
 
The signaling LED pin are defined in MySConfigg.cpp; comment the lines out if you need the pins for other scope
ERROR LED = A0
TX LED = A1
RX LED = A2
 Uncomment and define the MY_SIGNING_ATSHA204_PIN line if you want to use an ATSHA204 IC for signing.
*/
 
#define BUZZER_PIN 3
//#define DHT_DATA_PIN 4
//#define RGBW_W_PIN 5
//#define FRONT_PIR_PIN 5
//#define RGBW_B_PIN 6
//#define LEFT_PIR_PIN 6
//#define RGBW_G_PIN 9
//#define RIGHT_PIR_PIN 9
//#define RGBW_R_PIN 10
//#define MY_SIGNING_ATSHA204_PIN 17
#define BUTTON_PIN 17
#define NEOPIXEL_LED_PIN 18
#define MQ2_DIGITAL_PIN 19
//#define PHOTORES_PIN 20
#define MQ2_ANALOG_PIN 21

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

Click here to see the default MySconfig.cpp

Click here to see the default MySconfig.cpp

/home/homeassistant/pio/d-diot-nano-repeater/src/MySconfig.cpp
/* d-diot nano repeater - MySensors Configuration */
 
#define MY_REPEATER_FEATURE
#define MY_SIGNING_SOFT
#define MY_SIGNING_REQUEST_SIGNATURES
#ifdef MY_SIGNING_ATSHA204_PIN
#define MY_SIGNING_ATSHA204
#endif
#define MY_RADIO_RF24
#ifdef MY_RADIO_RF24
#define MY_RF24_PA_LEVEL RF24_PA_MAX
#define MY_RF24_IRQ_PIN 2
#define MY_RF24_CE_PIN 7
#define MY_RF24_CS_PIN 8
#endif
#define MY_DEFAULT_ERR_LED_PIN 14
#define MY_DEFAULT_TX_LED_PIN 15
#define MY_DEFAULT_RX_LED_PIN 16
// Timeout before starting loop without gateway connection
#define MY_TRANSPORT_WAIT_READY_MS 10000
#define MY_SPLASH_SCREEN_DISABLED
static const bool ack = false;

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.

Click here to see the default MainConfig.cpp

Click here to see the default MainConfig.cpp

/home/homeassistant/pio/d-diot-nano-repeater/src/MainConfig.cpp
/* d-diot nano repeater - Devices Configuration */
 
// DHT22 configuration
#ifdef DHT_DATA_PIN
#define SENSOR_TEMP_OFFSET 0
#endif
 
// Buzzer configuration
#ifdef BUZZER_PIN
#define BUZZER_FREQ 500
#endif
 
// NEOPixel LEDs configuration
#ifdef NEOPIXEL_LED_PIN
#define NUMPIXELS 16
#define STRIP_BRIGHTNESS 255
#endif
 
// MQ2 configuration
#ifdef MQ2_DIGITAL_PIN
#ifdef BUZZER_PIN
#define SOUND_ALARM
#ifdef SOUND_ALARM
#define BUZZER_ALARM_FREQ 1500
#define ON_PERIOD 500
#define OFF_PERIOD 500
#endif
#endif
#ifdef NEOPIXEL_LED_PIN
#define VISUAL_ALARM
#ifdef VISUAL_ALARM
#define LIGHT_ON_PERIOD 1000
#define LIGHT_OFF_PERIOD 1000
#define LIGHT_RED_VALUE 255
#define LIGHT_GREEN_VALUE 0
#define LIGHT_BLU_VALUE 0
#define LIGHT_DIMMER_PERCENT 100
#endif
#endif
#endif
 
// Button configuration
#ifdef BUTTON_PIN
#define SHORT_KEY_PRESS_TIME 250
#define LONG_KEY_PRESS_TIME 1000
#define DOUBLE_CLICK_INTERVAL 250
#ifdef BUZZER_PIN
#define KEY_PRESS_FREQ 1000
#endif
#endif

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.

Click here to see the default config section of main.cpp

Click here to see the default config section of main.cpp

/home/homeassistant/pio/d-diot-nano-repeater/src/main.cpp
// ******************************* NODE CONFIGURATION **********************************
 
// Sampling interval configuration
static const uint64_t UPDATE_INTERVAL = 60000;
static const uint8_t FORCE_UPDATE_N_READS = 10;
 
// Save states to EEPROM (useful but the total write cycle are limited to about 100000)
#define SAVE_STATE_TO_EEPROM
 
// Debug configuration
//#define MY_DEBUG
 
//  Pin configuration
#include <PinConfig.cpp>
 
// Devices configuration
#include <MainConfig.cpp>
 
// MySensors configuration
#include <MySConfig.cpp>
 
// ************************ END OF CONFIG **********************************
  • 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.

  • sensors_and_actuators/mysensors/gp_pcb_nano.txt
  • Last modified: 2021/02/12 11:27
  • by franzunix