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 36
andRELAY_PIN 26
.Thanks
Felix