Arduino Based Physical Deterrent System
7/14/20233 min read
In cybersecurity, there's a widely embraced strategy called "defense in depth." It's like building layers of protection around your digital assets to keep them safe from various threats. One crucial layer is securing the physical aspects of infrastructure- things you can touch, like hardware and access points. By locking down the physical layer, you're adding an extra shield against unauthorized access, tampering, or theft.
Now, imagine applying this concept to our daily lives, where we're building a physical deterrent system using Arduino and an ultrasonic sensor. Essentially, we're creating a real-world barrier to prevent unwanted physical access. It's a practical way to beef up security and aligns perfectly with the idea of defense in depth.
Understanding the Components:
1 x Arduino UNO R3
1 x HC-SR04 Ultrasonic Sensor
1 x Solder-less Half Breadboard
3 x RGB LED
1 x Buzzer 5v
4 x 220 Ohms Resistor
1 x Breadboard and Arduino Holder
10 x Jumper Wires
Software
Arduino IDE
Fritzing (for schematic drawing)
CoolTerm for Mac- Serial port monitoring
MS Excel- Data Processing and Visualisation
Building the Circuit:
Below is the schematic for my system depicting the sense-think-act subsystem:
Coding the Arduino
Programming the Arduino involves translating the conceptual framework into executable code. To create the sketch I used C++.
Project Breakdown
Setup Phase : Initialising communication channels and defining pin configurations for the sensor, LEDs, and buzzer.
Loop Phase : Iteratively executing the main program logic, which includes:
Reading distance data from the ultrasonic sensor.
Implementing conditional statements to interpret sensor data and trigger appropriate responses:
Activating LEDs to indicate safe (green), caution (yellow), and danger (red) zones based on predefined distance thresholds.
Emitting audible alerts through the buzzer when an object is detected within the danger zone.
void setup() {
// setup code goes here, to run once:
}
void loop() {
// main code goes here, to run repeatedly:
}
Understanding setup() and loop():
setup(): This function is called only when the Arduino is powered on or reset. It is utilised to initialise values and configure the environment for the main program execution.
loop(): Contrary to setup(), the loop() function runs continuously until the device is powered off. It serves as the main execution loop where the core logic of the code resides.
Arduino Pin Mode:
In Arduino programming, configuring pins as either input or output is crucial for interfacing with external components. This is achieved using the pinMode() function.
pinMode(13, OUTPUT); // sets pin 13 as output pin
pinMode(13, INPUT); // sets pin 13 as input pin
Arduino Constants
Understanding Arduino constants simplifies the coding process by providing pre-defined values that remain constant throughout program execution.
Pin Modes: Constants such as INPUT and OUTPUT determine whether a pin is configured as an input or output.
Pin Levels: Constants HIGH and LOW represent the logical states of a pin, corresponding to voltage levels.
Built-ins: Arduino boards often include an onboard LED connected to a specific pin. The constant LED_BUILTIN references this pin.
Writing Digital Values
Controlling the digital output of pins is achieved using the digitalWrite() function, which sets the voltage level of a pin to either HIGH or LOW.
digitalWrite(13, HIGH); // Sets the output voltage on pin 13 to 5V
digitalWrite(13, LOW); // Sets the output voltage on pin 13 to 0V
Conclusion:
This project has been quite the learning adventure for me. One of the big takeaways has been the boost it gave to my C++ skills. As I dove into coding the Arduino, I found myself getting more comfortable with C++ concepts and syntax. Every bug I squashed and every line of code I wrote contributed to my understanding of how programming really works.
But it wasn't just about learning C++. This project also showed me how theory meets practice in the real world. Playing around with Arduino and putting together different parts was fun and showed me how what I learn in class actually applies out there. It was hands-on learning at its finest, and it made me realise just how powerful practical experience can be.
Full code: