Skip to main content

RAK12006 WisBlock PIR Sensor Module Quick Start Guide

Prerequisite

What Do You Need?

Before going through each and every step on using the RAK12006 WisBlock module, make sure to prepare the necessary items listed below:

Hardware

Software

  • Download and install ArduinoIDE.
  • To add the RAKwireless Core boards on your Arduino board, install the RAKwireless Arduino BSP. Follow the steps in the Github repo.

Product Configuration

Hardware Setup

The RAK12006 is a Pyroelectric Infrared Radial (PIR) module. It is designed to detect occupancy and motion from infrared radiated objects. The sensor uses AM312 from Senba Sensing Technology Co., Ltd.

For more information about RAK12006, refer to the Datasheet.

Figure 2283: RAK12006 connection to WisBlock Base

Assembling and Disassembling of WisBlock Modules

Assembling

The RAK12006 module can be mounted on the IO slot of the WisBlock Base board, as shown in Figure 2. Also, always secure the connection of the WisBlock module by using compatible screws.

Figure 2284: RAK12006 mounting connection to WisBlock Base module
Disassembling

The procedure in disassembling any type of WisBlock modules is the same.

  1. First, remove the screws.
Figure 2285: Removing screws from the WisBlock module
  1. Once the screws are removed, check the silkscreen of the module to find the correct location where force can be applied.
Figure 2286: Detaching silkscreen on the WisBlock module
  1. Apply force to the module at the position of the connector, as shown in Figure 5, to detach the module from the baseboard.
Figure 2287: Applying even forces on the proper location of a WisBlock module
NOTE

If you will connect other modules to the remaining WisBlock Base slots, check on the WisBlock Pin Mapper tool for possible conflicts.

After all this setup, you can now connect the battery (optional) and USB cable to start programming your WisBlock Core.

warning
  • 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 RAK12006 WisBlock Module

  1. Install the RAKwireless Arduino BSP for WisBlock by using the package_rakwireless_index.json board installation package. The WisBlock Core should now be available on the Arduino IDE.

  2. You need to select first the WisBlock Core you have, as shown in Figure 6 to Figure 8.

RAK4631 Board

Figure 2288: Selecting RAK4631 as WisBlock Core

RAK11200 Board

Figure 2289: Selecting RAK11200 as WisBlock Core

RAK11310 Board

Figure 2290: Selecting RAK11310 as WisBlock Core
  1. Next, copy the following sample code into your Arduino IDE.
Click to view the example
/**
* @file RAK12006_MotionDetection.ino
* @author rakwireless.com
* @brief motion detection example
* @version 0.1
* @date 2021-06-15
* @copyright Copyright (c) 2021
*/
#include <Wire.h>
#define SENSOR_PIN WB_IO6 // Attach AM312 sensor to Arduino Digital Pin WB_IO6

int gCurrentStatus = 0; // variable for reading the pin current status
int gLastStatus = 0; // variable for reading the pin last status

void setup()
{
pinMode(SENSOR_PIN, INPUT); // The Water Sensor is an Input
pinMode(LED_GREEN, OUTPUT); // The LED is an Output
pinMode(LED_BLUE, OUTPUT); // The LED is an Output
Serial.begin(115200);
time_t timeout = millis();
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
Serial.println("========================");
Serial.println(" RAK12006 test");
Serial.println("========================");
}

void loop() {

gCurrentStatus = digitalRead(SENSOR_PIN);
if(gLastStatus != gCurrentStatus)
{
if(gCurrentStatus == 0)
{//0: detected 1: not detected
Serial.println("IR detected ...");
digitalWrite(LED_GREEN,HIGH); //turn on
digitalWrite(LED_BLUE,HIGH);
}
else
{
digitalWrite(LED_GREEN,LOW);
digitalWrite(LED_BLUE,LOW); // turn LED OF
}
gLastStatus = gCurrentStatus;
}
else
{
delay(100);
}

}

NOTE

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 RAK12006 WisBlock Example Code Repository and this sample code in GitHub will work on all WisBlock Core.

  1. Once the example code is open, you can now select the right serial port and upload the code, as shown in Figure 9 and Figure 10.
NOTE

If you're 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.

Figure 2291: Selecting the correct Serial Port
Figure 2292: Uploading the RAK12006 example code
  1. When you successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the sensor's reading logs, as shown in Figure 11, and you will also see the green LED and blue LED from the WisBlock Base lights up whenever it detects motion based on changes in infrared light in the environment. Therefore, your RAK12006 is properly communicating to the WisBlock core.
Figure 2293: RAK12006 PIR detection readings