RAK12015 WisBlock Vibration Detection Sensor Module Quick Start Guide
Prerequisite
-
Assemble the RAK12015 with a WisBlock Base and WisBlock Core by following the RAK12015 Installation Guide.
-
Download and install the Arduino IDE, then add the RAKwireless Core boards by installing the RAKwireless Arduino BSP.
-
USB Cable
Initial Test of the RAK12015 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.
In this example, you will monitor if this sensor is triggered by nearby vibrations.
-
Install the RAKwireless Arduino BSP's 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- Copy the example code below:
Click to view the code
/**
@file RAK12015_Shock_801S.ino
@author rakwireless.com
@brief Setup and read values from a 801S sensor
@version 0.1
@date 2021-07-23
@copyright Copyright (c) 2021
**/
#include <Arduino.h>
#include "Wire.h"
#define SensorOutput WB_A1
uint8_t interrupt1Flag = 0;
void setup() {
// put your setup code here, to run once:
time_t timeout = millis();
Serial.begin(115200);
/* WisBLOCK 12015 Power On*/
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH);
delay(300);
/* WisBLOCK 12015 Power On*/
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
//falling edge fires , triggers interrupt a1, and calls the interrupt flag function
pinMode(SensorOutput, INPUT);
attachInterrupt(SensorOutput, interruptHandle1, RISING);
Serial.println("RAK12015 test Example");
}
/*
* brief:The threshold of the sensor is determined by the resistance of the pull-up resistor.
* Now the pull-up resistance is 10K
*/
void loop() {
// put your main code here, to run repeatedly:
if (interrupt1Flag == 1)
{
Serial.println("Trigger vibration sensor");
interrupt1Flag=0;
}
delay(500);
}
void interruptHandle1(void)
{
interrupt1Flag = 1;
}
If you experience any error in compiling the example sketch, check the updated code for the RAK12015 WisBlock Vibration Detection Sensor Module that can be found on the RAK12015 WisBlock Example Code Repository
- Then select the right Serial Port and upload the code.
Figure 1: Selecting the correct Serial Port
Figure 1: Uploading the sample code- When you have successfully uploaded the sample code, lay the module flat on the table and hit or stomp the table. Then, you can open up your serial monitor to get the sensor reading.
Figure 1: Hitting the desk or table to create vibrations
Figure 1: Triggered sensor reading in Serial Monitor