1. Mount the RAK4631 into the RAK19007 base board (in the Core slot):
- Gently slide the RAK4631 into the “Core” slot on the RAK19007 board until it clicks (it slides easily into the connector).
2. Mount the sensors in the dedicated slots:
- RAK1906 – into IO slot positioned at the bottom left (Slot A).
- RAK12004 – into another available IO slot (Slot B).
- Make sure they are powered correctly (VCC to VCC, GND to GND, SDA/SCL).
3. Mount the RAK1921 OLED:
- Connect the display to the I2C port of the RAK19007 board. It has 4 pins: VCC, GND, SDA, SCL.
4. Secure the board to a base (optional):
- you can use a WisBlock box, screws or a development board for stability.
5. The LoRaWAN gateway does not physically connect, but receives wireless data from the RAK4631.
Note: Each sensor has a specific connector (with position coding) on the RAK19007 – make sure to connect it correctly to avoid errors.
Step 2: Link to PC (via USB Cable)To connect to your PC you will need:
- WisBlock Base module RAK19007 with RAK4631 Core installed.
- Good quality USB Type-C cable.
- PC (Windows, macOS sau Linux).
Steps to follow:
1. Connect the USB Type-C cable to the port on the RAK19007.
2. Connect the other end of the cable to the USB port on your PC.
3. The LED on the board should light up (confirms power).
The RAK4631 uses the nRF52 USB chip (nRF52840). Sometimes Windows does not automatically detect the board.
Installation:
1. Go to: https://www.silabs.com/developers/usb-to-uart-bridge-vcp-drivers
2. Download and install the driver for your operating system (Silicon Labs CP210x).
3. Restart your PC after installation (if required).
Step 3: Setup Arduino IDE and Load FilesInstall Arduino IDE:
- Download de sofware from: https://www.arduino.cc/en/software
Verifying the connection in Arduino IDE:
1. Open Arduino IDE.
2. Go to Tools > Port and select the port that appears (e.g. COM3).
3. Go to Tools > Board and select:
- RAKwireless WisBlock Core RAK4631 (if installed correctly),
- or Adafruit Feather nRF52840 Express (compatible, if RAK variant does not appear).
Note: For the board to appear correctly, you must have the RAK board support package installed.
Installing RAK4631 support in Arduino IDE
- Open Arduino IDE
- Go to File > Preferences
- Under “Additional Board URLs”, add: https://downloads.rakwireless.com/Arduino/RUI3/package_rakwireless_index.json
- Go to Tools > Board > Board Manager. Search for “RAKwireless” and install the appropriate package for RAK4631.
Test connection: Blink
1. Open the example File > Examples > 01.Basics > Blink.
2. In Tools > Board, select WisBlock RAK4631.
3. In Tools > Port, select the active port.
4. Press Upload.
5. If everything is correct, the onboard LED will blink.
Install the required libraries:
Go to Sketch > Include Library > Manage Libraries, then search for and install:
- Adafruit BME680
- Adafruit MLX90614
- Adafruit SSD1306
- Adafruit GFX
- LoRaWAN RAK4630 (or RUI3 library from RAK)
PROGRAMMING
1. Open Arduino IDE
2. Select the board and port:
- Tools > Board → WisBlock RAK4631
- Tools > Port → COM-ul asociat (ex: COM4)
3. Copy the complete Arduino code (provided below)
4. Press Upload (⮕)
If everything is correct, the program will be uploaded, and you will see the data displayed on the OLED and in the Serial Monitor.
TESTING
Serial Monitor Check:
- Go to Tools > Serial Monitor
- Select baud rate to 115200
- View the data: temperature, humidity, VOC, IR temperature, alert status
OLED check:
- The display shows sensors data.
- If IR Temp > 50°C or VOC < 10kΩ, appears the message: "!!! ALERTA INCENDIU !!!"
LoRaWAN verification:
- In The Things Stack / TTN console, make sure you have:
o Activated the device with DevEUI, AppEUI, AppKey
o Received payloads (frames) in the Live Data section
- Use a decoder for interpretation.
Gateway Configuration
- Start the gateway and connect to its console (e.g. Helium, TTN – The Things Network)
- Create an application and add the node:
• DevEUI – from the Arduino sketch or from the RAK4631 code
• AppEUI and AppKey – defined in the code or generated
- Associate the node with the application and check if it receives the packets.
Testing and Validation
- Open the serial monitor and check if the sensors return correct values.
- The OLED screen should display:
T: 30.2 CH: 46.5 %VOC: 13.5 kOhmGAS: 290! ALERTA INCENDIU !
- If the IR temperature or gas level exceeds a set threshold, the alert message is triggered.
LoRaWAN testing:
- Check if the messages reach the gateway.
- Check the decoded payload in the application console.
Code
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <Adafruit_BME680.h>
#include <Adafruit_MLX90614.h>
#include <LoRaWan-RAK4630.h>
#include <Arduino.h>
// OLED
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
// Sensors
Adafruit_BME680 bme; // RAK1906
Adafruit_MLX90614 mlx = Adafruit_MLX90614(); // RAK12004
// Alert thresholds
float TEMP_IR_LIMIT = 50.0;
float VOC_LIMIT = 10.0; // kΩ
// LoRaWAN
uint8_t devEui[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01, 0x02, 0x03 };
uint8_t appEui[] = { 0x70, 0xB3, 0xD5, 0x7E, 0xF0, 0x00, 0x00, 0x00 };
uint8_t appKey[] = { 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88,
0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF, 0x00 };
void setup() {
Serial.begin(115200);
delay(1000);
// OLED
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println("Eroare la initializarea OLED");
while (1);
}
display.clearDisplay();
// Sensor RAK1906
if (!bme.begin()) {
Serial.println("Eroare senzor BME680");
while (1);
}
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setGasHeater(320, 150);
// Sensor MLX90614
if (!mlx.begin()) {
Serial.println("Eroare senzor MLX90614");
while (1);
}
// Initialization LoRaWAN
api.lorawan.init();
api.lorawan.setDeviceEUI(devEui, 8);
api.lorawan.setApplicationEUI(appEui, 8);
api.lorawan.setApplicationKey(appKey, 16);
api.lorawan.join();
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.println("Detectie incendii...");
display.display();
}
void loop() {
if (!bme.performReading()) {
Serial.println("Citire BME680 eșuată");
delay(5000);
return;
}
float temp = bme.temperature;
float hum = bme.humidity;
float voc = bme.gas_resistance / 1000.0; // kΩ
float tempIR = mlx.readObjectTempC();
// Alert condition assessment
bool alerta = false;
if (tempIR > TEMP_IR_LIMIT || voc < VOC_LIMIT) {
alerta = true;
}
// OLED display
display.clearDisplay();
display.setCursor(0, 0);
display.printf("T: %.1f C\nH: %.1f %%\nVOC: %.1f kOhm\nT.IR: %.1f C\n",
temp, hum, voc, tempIR);
if (alerta) {
display.setTextColor(WHITE, BLACK);
display.setCursor(0, 48);
display.setTextSize(1);
display.println("!!! ALERTA INCENDIU !!!");
}
display.display();
// Payload LoRa (6 octeți)
uint8_t payload[6];
payload[0] = (uint8_t)temp; // temp aer
payload[1] = (uint8_t)hum; // umiditate
payload[2] = (uint8_t)tempIR; // temp IR
payload[3] = (uint8_t)voc; // VOC
payload[4] = alerta ? 1 : 0; // status alertă
payload[5] = 0x00; // rezervat
// Send data via LoRaWAN
api.lorawan.send(2, payload, 6, false);
Serial.printf("Trimis: T=%.1f H=%.1f TIR=%.1f VOC=%.1f Alert=%d\n",
temp, hum, tempIR, voc, alerta);
delay(60000); // wait 1 minute
}
Decoding Payload in TTN
In the TTN console, to interpret the data:
function decodeUplink(input) {
return {
data: {
temp: input.bytes[0],
hum: input.bytes[1],
tempIR: input.bytes[2],
voc: input.bytes[3],
alert: input.bytes[4] === 1 ? "YES" : "NO"
}
};
}
prof. ing. Kele Ioan
Comments