🤖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 ?

    Scheduled Pinned Locked Moved M5GO
    m5go
    2 Posts 2 Posters 3.5k Views
    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 Offline
      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 Offline
        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

        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

        With your input, this post could be even better 💗

        Register Login
        • First post
          Last post