RAK12047 WisBlock VOC Sensor Module Quick Start Guide
Prerequisite
What Do You Need?
Before going through each and every step on using the RAK12047 WisBlock VOC Sensor Module, make sure to prepare the necessary items listed below:
Hardware
- RAK12047 WisBlock VOC Sensor Module
- Your choice of WisBlock Base
- Your choice of WisBlock Core
- USB Cable
- Li-Ion/LiPo battery (optional)
- Solar charger (optional)
Software
- Download and install Arduino IDE.
- Install the RAKwireless Arduino BSP and add the RAKwireless Core boards to your Arduino Boards Manager. Follow the steps in the Github repo.
Product Configuration
Hardware Setup
WisBlock can integrate this module, which makes it easy to build up an air quality monitoring data acquisition system.
For more information about the RAK12047, refer to the Datasheet.
RAK12047 module can be connected to the sensor's slot of WisBlock Base to communicate with the WisBlock Core, as shown in Figure 1. It will work on SLOT A to F. Also, always secure the connection of the WisBlock module by using compatible screws.

Assembling and Disassembling of WisBlock Modules
Assembling
As shown in Figure 2, the location for Slot A, B, C, D, E, and F are properly marked by silkscreen. Slots C and D are located on the bottom of WisBlock Base. Follow carefully the procedure defined in WisBlock Base board assembly/disassembly instructions to attach a WisBlock module. Once attached, carefully fix the module with an M1.2 x 3 mm screw.

Disassembling
The procedure in disassembling any type of WisBlock module is the same.
- First, remove the screws.

- Once the screws are removed, check the silkscreen of the module to find the correct location where force can be applied.

- Apply force to the module at the position of the connector, as shown in Figure 5, to detach the module from the baseboard.

If you will connect other modules to the remaining WisBlock Base slots, check on the WisBlock Pin Mapper tool for possible conflicts. RAK12047 uses I2C communication lines, and it can cause possible conflict, especially on some IO modules.
After all this setup, you can now connect the battery (optional) and USB cable to start programming your WisBlock Core.
- Batteries can cause harm if not handled properly.
- Only 3.7-4.2 V rechargeable LiPo batteries are supported. It is highly recommended not to use other types of batteries with the system unless you know what you are doing.
- If a non-rechargeable battery is used, it has to be unplugged first before connecting the USB cable to the USB port of the board to configure the device. Not doing so might damage the battery or cause a fire.
- Only 5 V solar panels are supported. Do not use 12 V solar panels. It will destroy the charging unit and eventually other electronic parts.
- Make sure the battery wires match the polarity on the WisBlock Base board. Not all batteries have the same wiring.
Software Configuration and Example
Initial Test of the RAK12047 WisBlock Module
-
Install the RAKwireless Arduino BSPs for WisBlock by using the
package_rakwireless_index.json
board installation package, the WisBlock Core should now be available on the Arduino IDE. -
You need to select the WisBlock Core you have.
RAK4631 WisBlock Core

RAK11200 WisBlock Core

RAK11310 WisBlock Core

- Next, copy the following sample code into your Arduino IDE:
Click to view the code
/**
@file RAK12047_SGP40_GetVOCIndex.ino
@author rakwireless.com
@brief Get the VOC index data from the sensor SGP40 and print it out through the serial port.
The voc index can directly indicate the quality of the air. The higher the value, the worse the air quality.
@version 0.1
@date 2022-1-22
@copyright Copyright (c) 2020
**/
#include <SensirionI2CSgp40.h> // Click here to get the library: http://librarymanager/All#SensirionI2CSgp40
#include <Wire.h>
SensirionI2CSgp40 sgp40;
void setup()
{
uint16_t error;
char errorMessage[256];
uint16_t serialNumber[3];
uint8_t serialNumberSize = 3;
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH);
// Initialize Serial for debug output
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("RAK12047 SGP40 example");
Wire.begin();
sgp40.begin(Wire);
error = sgp40.getSerialNumber(serialNumber, serialNumberSize);
if (error)
{
Serial.print("Error trying to execute getSerialNumber(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
}
else
{
Serial.print("Serial Number:");
Serial.print("0x");
for (size_t i = 0; i < serialNumberSize; i++)
{
uint16_t value = serialNumber[i];
Serial.print(value < 4096 ? "0" : "");
Serial.print(value < 256 ? "0" : "");
Serial.print(value < 16 ? "0" : "");
Serial.print(value, HEX);
}
Serial.println();
}
uint16_t testResult;
error = sgp40.executeSelfTest(testResult);
if (error)
{
Serial.print("Error trying to execute executeSelfTest(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
}
else if (testResult != 0xD400)
{
Serial.print("executeSelfTest failed with error: ");
Serial.println(testResult);
}
}
void loop()
{
uint16_t error;
char errorMessage[256];
uint16_t srawVoc = 0;
float vocIndex = 0;
/*
* @brief Set the relative humidity and temperature in the current environment.
* Temperature and humidity calibration has been performed inside the sensor.
* RH/ticks=RH/%×65535/100
* T/ticks=(T/°C + 45)×65535/175
*/
uint16_t defaultRh = 0x8000; // 50 %RH
uint16_t defaultT = 0x6666; // 25 ℃
delay(1000);
error = sgp40.measureRawSignal(defaultRh, defaultT, srawVoc);
if (error)
{
Serial.print("Error trying to execute measureRawSignal(): ");
errorToString(error, errorMessage, 256);
Serial.println(errorMessage);
}
else
{
Serial.print("SRAW_VOC:");
Serial.print(srawVoc);
vocIndex = (float)srawVoc/131.07 ;
/* VOC index.
* The voc index can directly indicate the quality of the air. The higher the value, the worse the air quality.
* 0-100,no need to ventilate,purify.
* 100-200,no need to ventilate,purify.
* 200-400,ventilate,purify.
* 400-500,ventilate,purify intensely.
*/
Serial.print(" VOC Index:");
Serial.println(vocIndex);
}
}
If you experience any error in compiling the example sketch, check the updated code for your WisBlock Core Module that can be found on the RAK12047 WisBlock Example Code Repository and this sample code in Github will work on all WisBlock Core.
- Once the example code is open, install the Sensirion SGP40 library by clicking the link highlighted in yellow, as shown in Figure 9 and Figure 10.


During the installation, you will be asked to install the other libraries. Install it as well (optional).

- After successful installation of the library, you can now select the right serial port and upload the code, as shown in Figure 12 and Figure 13.
If you are using the RAK11200 as your WisBlock Core, the RAK11200 requires the Boot0 pin to be configured properly first before uploading. If not done properly, uploading the source code to RAK11200 will fail. Check the full details on the RAK11200 Quick Start Guide.


- When you have successfully uploaded the example sketch, open the serial monitor of the Arduino IDE to see the sensor's reading logs. If you see the logs, as shown in Figure 14, then your RAK12047 is communicating with the WisBlock core properly.
