Invisible Tripwire
I made an invisible tripwire. Here's why: Invisible tripwires would be useful because they could provide security and safety without being noticed. Since they cannot be easily seen, they would be effective at detecting intruders without giving them a chance to avoid the system. Invisible tripwires could be used to protect homes, museums, or restricted areas by triggering alarms when someone crosses a boundary. They could also help in safety situations, such as warning workers if someone enters a dangerous area. Overall, invisible tripwires would improve protection and awareness while remaining discreet and efficient. Thinking about this, with my need for creation, I had to try and make one. It worked! Here are the simple instructions:
Supplies
You need:
- Arduino Uno
- Breadboard (Optional only if you can solder)
- Ultrasonic distance sensor HC-SR04
- Jumper wires
- Something to upload and write the code on (needs arduino editor: https://login.arduino.cc/login?state=hKFo2SBvdE5tR1hXRkx4TnJJeXRFY1JTNjhuR21kb0JjVjh1N6FupWxvZ2luo3RpZNkgRkdGZTJyczVlZC1jNnppbW1ZWVpnaXFOdzVzM0Z5b0yjY2lk2SBlOXFpcEEyTjBrOVA4dnZyZTlmZEdjNnU5S2w5ZUhTUA&client=e9qipA2N0k9P8vvre9fdGc6u9Kl9eHSP&protocol=oauth2&scope=openid+profile+email&redirect_uri=https%3A%2F%2Fapp.arduino.cc&response_type=code&response_mode=query&nonce=ZHFhflo2UlFCa2htTFlhS21IM1h1REVORlM1LmkuU35NQ1BjdHV%2BTXdSTg%3D%3D&code_challenge=YmWNjgTsAmHE0Rwu0MzsNTQdP2I-F0aljz2Qev_pnXo&code_challenge_method=S256&auth0Client=eyJuYW1lIjoiYXV0aDAtc3BhLWpzIiwidmVyc2lvbiI6IjIuMS4zIn0%3D#/sso/login
- It only takes like 3 min to set up an account
The Connections
To start you need to connect the pins. If you don't want to use a breadboard, another option is soldering. The breadboard still is highly recommended. Here are the connections:
- Gnd - Gnd of sensor
- 5v - 5v of sensor
- D2 - Buzzer positive
- D3- Trig of sensor
- D4- Echo of sensor
- Gnd- Buzzer negative
If you want to connect any modifications, now is the time.
The Code
For the code I decided to use simple if conditions instead of overcomplicating it. Here is the code. I added explanations for it in the code but if you have any questions feel free to ask in the comments. I made a comment where you can adjust the tripwire length in the code.
#define TRIG_PIN 3
#define ECHO_PIN 4
#define BUZZER_PIN 2
long duration;
float distance;
void setup() {
pinMode(TRIG_PIN, OUTPUT);
pinMode(ECHO_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);
Serial.begin(9600);
}
void loop() {
// Send ultrasonic pulse
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
// Read echo time (with timeout for safety)
duration = pulseIn(ECHO_PIN, HIGH, 30000);
// Calculate distance in cm
distance = duration * 0.034 / 2;
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
// Turn buzzer on if object is within any amount you want
// The 30 that you see below this line is the amount of centimeters long you want your tripwire to be
if (distance > 0 && distance <= 30) {
tone(BUZZER_PIN, 1000); // Beep at 1 kHz
} else {
noTone(BUZZER_PIN); // Turn buzzer off
}
delay(100);
}
// If you added extra components in the previous step, now is the time to edit in the code for them.
Upload the Code!
First plug the board into the device your using. Then press upload!
It should work after that. keep it plugged into a power source and set it next to your doorway for maximum security!