lorawan®-based motion detector with battery monitoring on wisblock

Learn how to build a motion-triggered alert system with real-time battery level reporting using WisBlock. This project sends alerts over LoRaWAN to ChirpStack whenever motion is detected.

Figure 1: Motion Detector with Battery Monitoring Device

In this project, you'll create a motion detection system with battery monitoring using RAKwireless WisBlock modules. The system sends alerts over LoRaWAN when motion is detected and includes the battery level in each uplink.

Utilizing the RAK12006 PIR sensor and the RAK4631 LoRaWAN module, this project is perfect for low-power, long-range IoT applications, including remote monitoring, smart security, and environmental automation.

You will also learn how to:

  • Use OTAA to connect your WisBlock device to a LoRaWAN network
  • Trigger uplinks based on motion activity
  • Monitor battery voltage from a LiPo battery
  • View and decode data on ChirpStack

How It Works

Motion Detection Logic

  • The PIR sensor detects motion and outputs a LOW signal.
  • The code checks for a falling edge (HIGH → LOW) on the sensor pin.
  • Upon detecting motion:
    • The LED is toggled.
    • A LoRaWAN uplink is triggered.

Figure 2: Motion Detector Diagram

Battery Monitoring

  • The voltage is read from pin A0 using a voltage divider.
  • Values are compensated and converted into:
    • Actual mV.
    • Percentage (0–100%).
    • An 8-bit battery level (0–255) for the LoRaWAN payload.

Where to Use This System

This motion detection system with integrated battery monitoring leverages WisBlock and LoRaWAN to deliver:

📶 Long-range and low-power operation, ideal for remote deployments

🔒 Secure communication uses OTAA-based LoRaWAN activation for reliable data transmission

🔋 Real-time battery monitoring, included with every uplink to ensure uninterrupted performance

🌐 Seamless integration with ChirpStack for device and data management

Use Case Scenarios:

🏢 Smart buildings: Automate lighting, HVAC systems, or access control

🛡️ Security systems: Detect motion in restricted or sensitive areas

🌿 Outdoor monitoring: Track activity in fields, farms, or natural  parks

🚪 Occupancy tracking: Monitor room usage in offices, schools, or public spaces

🏠 Home automation: Trigger alarms, cameras, or appliances based on movement

🏞️ Environmental research: Record wildlife activity in remote locations

🔋 Battery-powered remote sensing: Ideal for long-term, maintenance-free deployments

🏗️ Industrial and construction sites: Enhance safety with motion-triggered alerts

What You’ll Need

Figure 3: Required Hardware Components

 

COMPONENT DESCRIPTION
RAK4631 WisBlock Core with nRF52840 and SX1262
RAK12006 PIR Motion Sensor for motion detection
RAK19007 WisBlock Base Board
RAK7246G LoRaWAN Gateway
LiPo Battery or USB Power Power supply for the WisBlock device
Arduino IDE Used for writing and uploading firmware
Customized Enclosure Optional custom enclosure, designed to match the device's specific function.

 

Hardware Setup (RAKwireless WisBlock Platform)

1. Install the RAK4631 WisBlock Core into the J5 CPU slot and the RAK12006 PIR Motion Sensor into the J7 IO slot of the RAK19007 base board. For more information, refer to the WisBlock IoT Education Kit - Movement Detection Hardware Setup guide.

Figure 4: RAK19007 + RAK4631 + RAK12006 Board Assembly

2. Attach the LoRa antenna to the RAK4631 LoRa labelled I-PEX connector.

Figure 5: RAK4631 LoRa Antenna Label

3. For the power supply, connect a LiPo battery to the battery terminal for portable operation.

Figure 6: Battery Connection

4. Connect the base board to your computer via USB-C.

Firmware Development (Arduino IDE)

1. Install Required Tools

2. Upload the Firmware

  • Open the Arduino IDE and paste the provided sketch (Motion_Detection.ino).
  • Make sure to replace the following credentials with your own:
uint8_t nodeDeviceEUI[8] = { ... }; // Your DevEUI
uint8_t nodeAppEUI[8]    = { ... }; // Your AppEUI
uint8_t nodeAppKey[16]   = { ... }; // Your AppKey

 

  • In the Tools menu, select:
    • Board: WisBlock Core RAK4631
    • Port: The correct COM port
  • Click Upload.
  • Then, open the Serial Monitor (set to 115200 baud) and verify the following:
    • Motion detection messages
    • Battery voltage logs
    • Uplink sent successfully

Figure 7: Arduino IDE Serial Monitor 

  • Once the code is successfully uploaded, the motion detection setup will function as follows:
    • On the left: the idle state with no motion detected
    • On the right: motion detected with the LED indicator turned on.

Figure 8: Motion Detection Device Status

 

3. Gateway Configuration (RAK7246G)

For a comprehensive guide on setting up the RAK7246G, refer to the RAK7246G Quick Start Guide.

4. LoRaWAN Server Setup (ChirpStack)

1. Integrate the RAK7246G Gateway with ChirpStack

2. Register the Device (RAK4631 + RAK12006) in ChirpStack

  • In the ChirpStack UI, navigate to Applications and create a new one (if none exists).

Figure 9: Add Application on ChirpStack

  • After entering the necessary details, the new application (e.g., motion_detector) will appear in the Application list. Click on the created application name as shown in Figure 10.

Figure 10: Application Added on ChirpStack

  • In the DEVICES tab, click the + CREATE button to begin adding a new device, as shown in Figure 11.

Figure 11: Add device on ChirpStack

  • Enter the Device EUI, Join EUI, and App Key.
‼️
IMPORTANT

Ensure that the same DevEUI, AppEUI, and AppKey are used both in ChirpStack and in your device firmware.

 

  • Select OTAA as the activation method.
  • Assign the device to the appropriate application profile.

Figure 12: Add Device Details and DevEUI

Figure 13: Add Application Key (AppKey)

Figure 14: Device Successfully Added to ChirpStack

  • Under Device Profile, follow the settings listed in the following table:
SETTING VALUE
Activation Mode OTAA
LoRaWAN MAC Version 1.0.3
Regional Parameters PHY V1.0.3 REV A (e.g., EU868, US915)
RX Delay 1 sec
Application Port 2

 

Figure 15: Create Device Profile

  • After adding the gateway and device to ChirpStack, press the device restart button to verify its join status.

Figure 16: Reset the Motion Detection Device

If the integration with ChirpStack is successful, you will see a JoinAccept message in the device’s status.

Figure 17: ChirpStack LoRaWAN Frames

Troubleshooting

ISSUE SOLUTION
Device not joining the network Check the OTAA keys, regional frequency band, and ChirpStack configuration
No uplink received Ensure that the PIR sensor is being triggered. Use serial output to test and confirm activity.
Incorrect battery reading Verify the analog reference voltage and ensure proper calibration of the voltage divider.

Conclusion

This project showcases how WisBlock modules can be seamlessly integrated to build a reliable, low-power motion detection system with built-in battery monitoring and long-range LoRaWAN communication. Designed with minimal hardware requirements and full compatibility with ChirpStack, it offers a flexible framework for smart IoT applications.

Whether for automation, security, or environmental sensing, this solution is easily adaptable, scalable, and ready for real-world deployment.

 


 

karla-jimenez.png

Karla Jimenez

Karla is a technical documentation support at RAKwireless with an engineering background. She enjoys learning about technology, innovation, and IoT, and likes helping others understand and build with these tools—one guide at a time.


Changelog

  • Version 1 - LoRaWAN-Based Motion Detector with Battery Monitoring on WisBlock
    • Author: Karla Jimenez
    • Reviewer: Harold Duarte
    • Date Published: 07/01/2025

 

Updated