📌 Ideation
For this week's assignment, I designed a Security Alarm Box. The idea is to create a smart system that detects when a box is opened and triggers an alarm. This concept could be useful for securing personal belongings or sensitive materials.
🔹 Why this idea?
The inspiration came from the need for simple, yet effective security solutions that can be implemented using Arduino. By using ultrasonic distance measurement instead of traditional magnetic sensors, the box can accurately detect when the lid is opened.
🔹 How it works?
A switch (button) is used to turn the security system ON or OFF.
When ON, the system monitors the ultrasonic sensor (HC-SR04) inside the box.
If the box is closed (distance < 5 cm), the LED and buzzer remain OFF.
If the box is opened (distance > 5 cm), the LED starts blinking and the buzzer sounds an alarm.
If the switch is OFF, the system is disabled, and no alarms are triggered.
Image for Reference
Software:
Components
Tools:
Code Source
1) I simulated my code logic on paper.
2) I simulated my wiring on TinkerCAD.
3) found reference for the idea and the code
Ref#1: Link
4) Feeded TinkerCad with the code.
5) Kept refining and editing inputs until I got the correct Result.
Design On Tinker Cad
HC-SR04 Ultrasonic Sensor
Trig → Pin 6
Echo → Pin 5
Switch (Button) → Pin 7
Buzzer → Pin 4
LED → Pin 3
Power Source → 5V from Arduino
Read the button switch state:
If OFF → System disabled (Buzzer and LED remain OFF).
If ON → Proceed to distance measurement.
Read ultrasonic sensor distance:
If distance < 5 cm → Box is closed → LED and Buzzer OFF.
If distance > 5 cm → Box is open → LED blinks, Buzzer sounds.
Code Logic:
Pin Setup:
Named pins:
TRIG_PIN: Sends sound wave
ECHO_PIN: Receives sound wave
SWITCH_PIN: Turns system ON/OFF
BUZZER_PIN: Makes sound
LED_PIN: Lights up
Setup:
Defined input/output for each pin.
Enabled serial monitor for testing distance.
Loop:
If switch is OFF: LED & buzzer stay off.
If switch is ON:
Measures distance using ultrasonic sensor.
Distance ≤ 6 cm: Box closed → No alarm.
Distance > 6 cm: Box open → LED blinks & buzzer sounds.
Delays:
Added to control blinking speed & avoid rapid readings.
In short: Switch ON → Measures distance → Box open? Alarm triggers. Box closed? Nothing happens.
The Circuit was simulated on TinkerCad
The circuit didn't work
Upon reviewing the code I found that I used the wrong PINs in action.
Title of Media
I learned how to program the Arduino to give me the multiple inputs and output functions I need.