Alarm system with sensor and buzzer
📖 Scenario: You want to build a simple alarm system using an Arduino board. The system will detect when a sensor is triggered and then activate a buzzer to alert you.
🎯 Goal: Create an Arduino program that reads a sensor input and turns on a buzzer when the sensor is triggered.
📋 What You'll Learn
Use a variable called
sensorPin set to pin 2 for the sensor inputUse a variable called
buzzerPin set to pin 9 for the buzzer outputCreate a variable called
sensorState to store the sensor readingWrite code to read the sensor state using
digitalRead(sensorPin)Turn on the buzzer by setting
buzzerPin HIGH when the sensor is triggeredTurn off the buzzer by setting
buzzerPin LOW when the sensor is not triggeredPrint
"Alarm ON" when the buzzer is on and "Alarm OFF" when it is off💡 Why This Matters
🌍 Real World
Alarm systems are used in homes and offices to detect intruders or unsafe conditions and alert people.
💼 Career
Understanding how to read sensors and control outputs is a key skill for embedded systems and IoT device programming.
Progress0 / 4 steps
