Arduino Intruder Sensor

For this makerspace/coding project we developed an ultrasonic sensor to detect an intruder, our main source was the ”Arduino Project Handbook” written by Mark Geddes which is available on makerspace.

Our main goal with this project is to develop a low costing security alarm in which we use ultrasonic is used as a trigger to when the perimeter is breached.

For the execution of the project we used the following materials: Arduino board;Breadboard; jumper wires; Four-pin HC-SR04 ultrasonic sensor; Servomotor; Red LED; Green LED; 2 220-ohm resistors. Follow the steps below to accomplish the estimated work.

Step 1: Step 1:

Once you already have the materials, insert the ultrasonic sensor (HC-SCR04) into the breadboard, connect the sensor’s GND to the Arduino GND rail, VCC to Arduino +5V, Trig to Arduino GND rail, VCC to Arduino pin 12, and Echo to Arduino pin 13. The images above can fit you as an inspiration.

Step 2: Step 2:

Now we are connecting the servo’s brown wire to the Arduino GND rail, its red wire to the Arduino +5V rail, and its yellow signal wire to Arduino pin 9. Images above.

Step 3: Step 3:

After we have completed Part 2, Insert the red and green LEDs into the breadboard with the shorter, negative legs in the Arduino GND rail. Add a 220-ohm resistor to each of the positive legs and connect the red LED to Arduino pin 2 and the green LED to pin 3 via the resistors.

Step 4: Step 4:

Connect the power rails on the breadboard to Arduino +5V and GND.

Step 5: Step 5:

Upload the following code to Arduino:

#include  // Call NewPin library
#include // Call Servo library #define trigPin 12 // Trig pin connected to Arduino 12 #define echoPin 13 // Trig pin connected to Arduino 13 #define MAX_DISTANCE 500 NewPing sonar(trigPin, echoPin, MAX_DISTANCE); // Library setting int greenLed = 3, redLed = 2; // Set green LED to pin 3, red to pin 2 int pos = 20; Servo myservo; void setup() { Serial.begin (115200); pinMode(trigPin, OUTPUT); pinMode(echoPin, INPUT); pinMode(greenLed, OUTPUT); pinMode(redLed, OUTPUT); myservo.attach(9); // Servo attached to pin 9 } void loop() { int duration, distance, pos =0, i; digitalWrite(trigPin, LOW); delayMicroseconds(2); digitalWrite(trigPin, HIGH); // Trig pin sends a ping delayMicroseconds(10); digitalWrite(trigPin, LOW); duration = pulseIn(echoPin, HIGH); // Echo receives the ping distance = (duration / 2) / 29.1; Serial.print(distance); Serial.println(" cm");
 if (distance <= 40) {
    digitalWrite(greenLed, LOW);
    digitalWrite(redLed, HIGH);
    myservo.write(180);
    delay(450);
    digitalWrite(redLed, LOW);
    myservo.write(90);
    delay(450);
    digitalWrite(redLed, HIGH);
    myservo.write(0);
    delay(450);
    digitalWrite(redLed, LOW);
    myservo.write(90);
 }
else {
  digitalWrite(redLed, LOW);
  digitalWrite(greenLed, HIGH);
  myservo.write(90);
 }
 delay(450);
}

Step 6: Congratulations!

If you have followed all the steps correctly, your project must be completed and well functioning! The project was made after the coordenades from Arduino Project Handbook.

Share

    Recommendations

    • First Time Author

      First Time Author
    • Big and Small Contest

      Big and Small Contest
    • Toys Contest

      Toys Contest

    Discussions