What could be the problem if my HC-SR501 keeps on saying in the output monitor of Arduino IDE, "motion detected" even if there are nothing to be detected?
It could be the code you didn't post, or the schematic you didn't post, or both.
What do you mean?
Where do you come from?
uhm phil..
I have moved your topic to an appropriate forum category @calhexazz.
In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.
This is an essential part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. It contains a lot of other useful information. Please read it.
Thanks in advance for your cooperation.
Did you mean "I'm from the state of Philadelphia in the United States of America"? This is an international forum.
I think @paulpaulson wanted to understand what your first language is, because of the answer you gave to @anon56112670 's question.
@anon56112670 was saying that there could be a problem with your code. Or there could be a problem with your circuit. But you didn't post any details of those things, so there is no way for anyone on the forum to spot those errors, if they do exist. The forum guide that @pert gave the link to will suggest what you should include in your post and how to include it, so that forum members can actually help you, instead of just trying to guess.
Here is my guess: This type of PIR sensor usually have a small pot to allow you to adjust the sensitivity. If that's set to maximum, it may falsely trigger. The other pot adjusts the time that the output remains high after a detection.
Ohhh sorry, thank you for the clarification.
const int MOTION_SENSOR_PIN = 2; // Arduino pin connected to the OUTPUT pin of motion sensor
const int BUZZER_PIN = 4; // Arduino pin connected to Buzzer's pin
int motionStateCurrent = LOW; // current state of motion sensor's pin
int motionStatePrevious = LOW; // previous state of motion sensor's pin
void setup() {
Serial.begin(9600); // initialize serial
pinMode(MOTION_SENSOR_PIN, INPUT); // set arduino pin to input mode
pinMode(BUZZER_PIN, OUTPUT); // set arduino pin to output mode
}
void loop() {
motionStatePrevious = motionStateCurrent; // store old state
motionStateCurrent = digitalRead(MOTION_SENSOR_PIN); // read new state
if (motionStatePrevious == LOW && motionStateCurrent == HIGH) { // pin state change: LOW -> HIGH
Serial.println("Motion detected!");
digitalWrite(BUZZER_PIN, HIGH); // turn on
}
else
if (motionStatePrevious == HIGH && motionStateCurrent == LOW) { // pin state change: HIGH -> LOW
Serial.println("Motion stopped!");
digitalWrite(BUZZER_PIN, LOW); // turn off
}
}
here is the code that i used
For the time adjustment delay of the sensor, i rotated it fully clockwise, and full counterclockwise for the sensitivity
That might be maximum sensitivity. Are there markings near the controls on the sensor that have "+" and "-" or other symbols printed near them? I would suggest setting both controls to the mid-point to begin.
I can see the + and - markings but its near the pins of the sensor, for other markings all i can see are the letters on the corner namely: "MD", "L", "H"
Those "+" and "-" may be power (Vcc) and ground.
I guess "L" and "H" are low and high sensitivity. Not sure about "MD".
Does your module look similar to this?
PS. I can't see any problem with your code.
It does, but my sensor doesn't have that yellow rectangular box on the corner and the thing sitting next on it in the right
It may be time for some photographs. Make them bright and sharp, so every wire can be traced. Also a close-up of your sensor, similar to the photograph above.
uhm just a follow up my pir sensor can now detect something, like if i put my shaking hand on it ,it will say on the serial monitor that "Motion Detected" but right after it will already say that "Motion stopped" even though im still shaking my hand in front of the sensor
Ok, so "MD", "H" and "L" refer to the trigger repeat control, not the sensitivity control.
The yellow box in the photo I posted is a "jumper" which can be placed in two positions on the 3 pins that stick out of the board. It's like a cheap version of a toggle switch. Your version just has solder pads. You put a blob of solder across one pair of pads or the other, to affect how the trigger works.
It could be that the sensor doesn't see your shaking hand as movement because it is too close and fills up the whole field of view of the sensor. I think these sensors have a small number of sensitive sectors or areas, and can only sense the presence of absence of an object in each sector/area. Your shaking hand fills most or all of these sectors, and as long as it is there, the sensor sees nothing change.
If you remove your hand and after a few seconds put it in front again, does the sensor sense that?
I already found the answer, it's the coding itself that has the problem. Thank you very much for staying with me and answering all my nooby questions. Highly appreciated!
I would be interested to understand what the problem was, I wasn't able to spot a problem in your code. Can you post it please?
Also why did you mark post #18 as the solution?