How to use GPIO2 on SEN0395
I wanted to try to use the SEN0395 as a motion/presence detector to monitor my garage area as we have teens breaking into cars over the last couple of weeks. I was able to get the unit working with an UNO and in the serial mode but I want to use it with an ESP-01 so just want to use the GPIO2 for 1 - “someone is there” or 0 - “no one is there” per the documentation. For some reason the GPIO2 pin is not changing depending on the presence/absence of a person.
Program is dirt simple:
/* 09/03/23
* Created this version to see if using the digital GPIO2 pin of the SEN0395 will work or not
*/
int ledPin = 13; // LED on the UNO
const int RadarPin = 2; // Connect GPIO2 of SEN0395 to pin 2 of UNO
const int buzzerPin = 4; // Define the pin a buzzer is connected to
void setup()
{
pinMode(ledPin, OUTPUT); // Set to output to blink LED
pinMode(buzzerPin, OUTPUT); // Set to output to turn on buzzer
pinMode(RadarPin, INPUT); // Set to input to read GPIO02 of SEN0395
}
void loop()
{
int pinState = digitalRead(RadarPin); // Read GPIO02 output state
if (pinState == HIGH){ // SEN0395 has detected someone
digitalWrite(ledPin, HIGH); // Turn on LED on UNO
digitalWrite(buzzerPin, HIGH); // Turn the buzzer on
delay(1000); // Wait for 1 second (1000 milliseconds)
digitalWrite(buzzerPin, LOW); // Turn the buzzer off
delay(1000); // Wait for 1 second (1000 milliseconds)
digitalWrite(ledPin,LOW); // Turn off LED on UNO
}
}
Anyone have any idea why the GPIO02 pin is not changing state? I tested the state of the pin by changing the condition to if (pinState == LOW) and the buzzer turns on and off like it's supposed to so that tells me the GPIO02 pin is not triggering and is staying low.
Any help or suggestions would be appreciated.
OK. . . never mind. . .
I spent 2 hours the other night trying to get the GPIO2 pin to trigger the Uno and beep to signal when it detected me. It refused to work. I just powered up the board to do some troubleshooting and it magically started working. No idea why. Moon phase? Murphy asleep? Just the universe having it's sick little joke? No clue, but hey. . . it's working now so time to try it was an ESP-01, ESP8266, ESP32 or Pi Pico W and see what happens.
Joe.Cloud