sensorPin reads sensor input, so it must be INPUT, not OUTPUT.
Step 2: Verify buzzerPin mode
buzzerPin controls buzzer output, so OUTPUT is correct.
Final Answer:
sensorPin should be set as INPUT, not OUTPUT. -> Option B
Quick Check:
Input pins need pinMode(INPUT) [OK]
Hint: Set sensor pins as INPUT, buzzer pins as OUTPUT [OK]
Common Mistakes:
Setting sensorPin as OUTPUT
Confusing input and output pin modes
Misusing digitalWrite for sensor reading
5. You want to modify an Arduino alarm system so the buzzer sounds only if the sensor detects HIGH for 3 seconds continuously. Which code change correctly implements this?
hard
A. Add a delay(3000) after detecting HIGH before turning buzzer ON.
B. Set sensorPin as OUTPUT and buzzerPin as INPUT to control timing.
C. Turn buzzer ON immediately when sensorPin is HIGH, then delay 3000 ms.
D. Use a timer to check if sensorPin stays HIGH for 3000 ms before activating buzzer.
Solution
Step 1: Understand requirement for continuous HIGH detection
We need to confirm sensorPin stays HIGH for 3 seconds before buzzer sounds.
Step 2: Evaluate options for timing logic
Using a timer to measure continuous HIGH duration is correct; delay alone pauses code and is insufficient.
Final Answer:
Use a timer to check if sensorPin stays HIGH for 3000 ms before activating buzzer. -> Option D
Quick Check:
Continuous HIGH detection needs timer logic [OK]
Hint: Use timer logic, not delay, for continuous sensor check [OK]
Common Mistakes:
Using delay which blocks code execution
Switching pin modes incorrectly
Turning buzzer ON immediately without timing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.