Motion Detect Sample

This application demonstrates motion detect function of the module. It uses Arduino IDE's Serial Monitor and IoT Node's onboard LED to display motion state.

To run the example:

  1. Open the IoT_Node_PIRMotionDetect sketch from the examples menu.

  2. Select Turta IoT Node from the Tools > Board menu.

  3. Select your device's COM port from Tools > Port menu.

  4. Open Serial Monitor from Tools > Serial Monitor.

  5. Select 115.200 baud from the Serial Monitor's status bar.

  6. Upload the code to your device.

Sample Code

#include <Turta_PIRMotionDetect_Module.h>
#define LED 13

// Global variables.
bool motionDetected = false;
bool oldMotionState = false;

// Create PIR Motion Detect instance.
Turta_PIRMotionDetect_Module pir;

void setup() {
  // Initialize onboard LED.
  pinMode(LED, OUTPUT);

  // Initialize PIR.

  // Configure serial port.

void loop() {
  // Read PIR state.
  motionDetected = pir.readMotionState();

  // On motion detected / no motion.
  if (oldMotionState != motionDetected) {
    digitalWrite(LED, motionDetected ? HIGH : LOW);
    Serial.println(motionDetected ? "Motion detected." : "No motion.");

  // Store last motion state.
  oldMotionState = motionDetected;

  // Delay 10ms.


After the application is uploaded to the device, it writes motion state to the Serial Monitor if the state is changed. The example output should be like this:

Motion detected.
No motion.

The application runs forever until you clear it from memory.

Last updated