Miguel Montiel VegaAntonio Valente
Published

Integration of the RAK12039 Sensor

This document outlines the complete process for integrating the RAK12039 sensor (based on the SCD30 sensor

BeginnerWork in progress2 hours67
Integration of the RAK12039 Sensor

Things used in this project

Hardware components

RAK12039
×1
RAK1906
×1
RAK11300
×1
RAK19007-O
×1

Software apps and online services

Arduino IDE
Arduino IDE
The Things Stack
The Things Industries The Things Stack

Hand tools and fabrication machines

Digilent Screwdriver
Digilent Screwdriver

Story

Read more

Custom parts and enclosures

3d_rak19007_hUI5xSFEjn.stp

Code

Source Code for RAK12039 + RAK1906

Arduino
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME680.h>

// I2C address for BME680
Adafruit_BME680 bme; // Uses default I2C address 0x76

// RAK12039 Touch sensor on IO1
#define TOUCH_SENSOR_PIN WB_IO1

void setup() {
  Serial.begin(115200);
  while (!Serial);

  pinMode(TOUCH_SENSOR_PIN, INPUT);

  Serial.println("Initializing RAK1906 (BME680)...");
  if (!bme.begin()) {
    Serial.println("Could not find a valid BME680 sensor, check wiring!");
    while (1);
  }

  // Configure BME680 oversampling and filter settings
  bme.setTemperatureOversampling(BME680_OS_8X);
  bme.setHumidityOversampling(BME680_OS_2X);
  bme.setPressureOversampling(BME680_OS_4X);
  bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
  bme.setGasHeater(320, 150); // 320*C for 150 ms
}

void loop() {
  // Read touch sensor
  int touchValue = digitalRead(TOUCH_SENSOR_PIN);
  Serial.print("Touch Sensor State: ");
  Serial.println(touchValue == HIGH ? "TOUCHED" : "NOT TOUCHED");

  // Trigger BME680 reading
  if (!bme.performReading()) {
    Serial.println("Failed to perform reading from BME680");
    return;
  }

  Serial.print("Temperature = ");
  Serial.print(bme.temperature);
  Serial.println(" *C");

  Serial.print("Humidity = ");
  Serial.print(bme.humidity);
  Serial.println(" %");

  Serial.print("Pressure = ");
  Serial.print(bme.pressure / 100.0);
  Serial.println(" hPa");

  Serial.print("Gas Resistance = ");
  Serial.print(bme.gas_resistance / 1000.0);
  Serial.println(" KOhms");

  Serial.println("---------------------------");

  delay(2000); // Delay between readings
}

Credits

Miguel Montiel Vega
11 projects • 9 followers
Teacher at Maude Studio & Erasmus+ project member: "Developing Solutions to Sustainability Using IoT" (2022-1-PT01-KA220-VET-000090202)
Antonio Valente
12 projects • 9 followers
Antonio Valente is a Professor at UTAD University and Principal researcher of Developing Solutions to sustainability using IoT. LoRaWAN
Thanks to Jose Miguel fuentes Garcia , and JoseCarlos Rosado.

Comments