🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    M5GO Motion Sensor, how it work ?

    M5GO
    m5go
    2
    2
    1.7k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • R
      Recyclosaucisse
      last edited by

      Hello, everyone,

      I have a new M5Stack, the M5Stack GO starter kit. It includes a motion sensor, and I would like to use it. I've read the instructions and connected the motion sensor to the black port, where G26 is for IN/OUT and G36 is for input.

      When I execute this code:

      #include <M5Stack.h>
      
      #define SENSOR_PIN 26
      #define RELAY_PIN 36
      
      void setup() {
        pinMode(RELAY_PIN, OUTPUT);
        pinMode(SENSOR_PIN, INPUT);
        Serial.begin(9600);
        M5.begin();
        M5.Lcd.println("I am on");
      }
      
      void loop() {
        M5.Lcd.println("Checking for presence");
        int SensorValue = digitalRead(SENSOR_PIN);
      
        if (SensorValue == HIGH) {
          digitalWrite(RELAY_PIN, LOW);
          M5.Lcd.println("Movement detected");
          delay(500);
        } else {
          digitalWrite(RELAY_PIN, HIGH);
          M5.Lcd.println("No movement");
        }
        delay(1000); // Add a delay in milliseconds (e.g., 1000ms) to control how often you check the sensor.
      }
      

      My sensor constantly writes 'no movement.' I think I haven't correctly defined the pin. What can I do to activate my motion sensor and have it write when it detects movement?

      Thank you for your valuable advice!

      1 Reply Last reply Reply Quote 0
      • felmueF
        felmue
        last edited by

        Hello @Recyclosaucisse

        you already described it correctly: G26 can be IN or OUT; G36 is IN only.

        Your defines need to be swapped: SENSOR_PIN 36 and RELAY_PIN 26.

        Thanks
        Felix

        GPIO translation table M5Stack / M5Core2
        Information about various M5Stack products.
        Code examples

        1 Reply Last reply Reply Quote 1
        • First post
          Last post