RAK12006 WisBlock PIR Sensor Module Quick Start Guide
Prerequisite
- Assemble the RAK12006 with a WisBlock Base and WisBlock Core by following the RAK12006 Installation Guide.
- Download and install the Arduino IDE, then add the RAKwireless Core boards by installing the RAKwireless Arduino BSP.
- USB Cable
- Li-Ion/LiPo battery (optional)
- Solar charger (optional)
Initial Test of the RAK12006 WisBlock Module
- This guide uses the RAK4631 WisBlock Core to demonstrate the configuration process. You can also use the RAK11200 or RAK11310 as the WisBlock Core.
- When using the RAK11200, configure the BOOT0 pin correctly before uploading the source code. Otherwise, the upload may fail. For detailed instructions, refer to the RAK11200 Quick Start Guide.
-
Install the RAKwireless Arduino BSP for WisBlock by using the
package_rakwireless_index.jsonboard installation package. The WisBlock Core should now be available on the Arduino IDE. -
You need to select first the WisBlock Core you have.
Figure 1: Selecting RAK4631 as WisBlock Core- 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);
}
}
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.
- Once the example code is open, you can now select the right serial port and upload the code.
Figure 1: Selecting the correct Serial Port
Figure 1: Uploading the RAK12006 example code- When you successfully uploaded the example sketch, open the Serial Monitor of the Arduino IDE to see the sensor's reading logs, 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 1: RAK12006 PIR detection readings