M5GO Motion Sensor, how it work ?
-
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!
-
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 36andRELAY_PIN 26.Thanks
Felix
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