Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi, this is my program for a PIR sensor. It’s not working? I’m not sure why. Whe

ID: 2293021 • Letter: H

Question

Hi, this is my program for a PIR sensor. It’s not working? I’m not sure why. When motion is detected it should detect it. But it doesn’t main.cpp main.cpp x 2 #include "nhed.h" 3 #include "C12832"h" 4 Digitalout ledl (p21): 5 Digitalout led2 (p22) 6 Digitalout Buzzer (p23): 7 InterruptIn alarm (p29): 8 C12832 1cd (p5, p7, p6, pe, p11): 10 int main() wait (0.2): while (0) 12 13 14 15 1 6 17 led1-1: led2-0 Buzzer 0; 10 if (alarm) ( 9 1ed1-1: 20 led2-0; Buzzer=1; 22 led.printf (" Motion detected! "; rld_WIZwill rld_WIzwil23 wait (5) 24 1ed.cls //clear screen 25 26 ) 27 Compile output for program: PIR motion Verbose Description

Explanation / Answer

The possible issue with code is with using while (0).

while (1) : It execute loop infinite times.

while(0) : It will not execute statements inside the loop.

From your code, alarm is an interruot which is receiving from PIR sensor as an active low. Please, check it whether output of PIR sensor is active low or active high.

Use while (1) in code and modfy if (! alarm) condition based on above result with proper power and IO connections.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote