Arduino Security System (Yasin)

by 769606 in Circuits > Arduino

373 Views, 3 Favorites, 0 Comments

Arduino Security System (Yasin)

Security System.png

Introduction

This is a simple tutorial on how to build a security system to keep people away from your personal stuff! The ultrasonic sensor will detect movement, and the LEDs will work according to how close you are. For example, if you’re less than 50 cm away, the green light will turn on. If you’re less than 20 cm away, the yellow light will turn on. If you’re less than 5 cm away, then the red light will turn on and you will hear a buzzing sound. It won’t stop until the person moves away.

Where I got Inspiration from

Security System

Arduino Doorbell

Supplies

  • 1 Buzzer
  • 3 LEDS
  • 10 Jumper Wires
  • 1 Arduino
  • 1 Mini Breadboard
  • 1 Ultrasonic Distance Sensor
  • 4 220 Ohm Resistor

The Layout

Security System.png

Connect a red wire from the 5V pin on the Arduino to the power rail (positive) of the breadboard. Connect a black wire from the GND pin to the ground rail (negative) of the breadboard.

Pins for Ultrasonic Distance Sensor

trigPin = 2

echoPin = 3

Pins for LEDs

LEDlampRed = 4

LEDlampYellow = 5

LEDlampGreen = 6

Pin for Buzzer

soundbuzzer = 7

The cathode of the LEDs should be connected to the GND rail via 220 Ohm resistors. The anode of the LEDs should be connected by jumper wires to their designated pins.

Constructing the Breadboard

Exquisite Fulffy-Kieran.png

This step is the easiest out of the whole project. All that is required is to connect a red wire from the 5V pin on the Arduino to the power rail (positive) of the breadboard. Connect a black wire from the GND pin to the ground rail (negative) of the breadboard. This will give us positive and negative power to the whole circuit.

Adding the Ultrasonic Distance Sensor

Brave Snicket.png

How it works

This sensor has 4 pins, Power, Trigger, Echo, and Ground. The trig pin is use to trigger sound pulses, and the echo pin creates a pulse from the reflected signal. The sensor gets its power from the power and ground rails.

How to connect it

Firstly, I would recommend moving the distance sensor far onto the top right corner of the breadboard to leave space for all the other components. Then, connect a red wire from the power rail (positive) to the VCC pin on the distance sensor. Also, connect a black wire from the ground rail (negative) to GND on the distance sensor. Then, connect another jumper wire (green wires, yellow wires, blue wires, any of these work) from pin #3 on Arduino to the Echo pin, and connect another jumper wire from pin #2 on Arduino to the Trig pin.

Adding the LEDs

Exquisite Fulffy-Kieran (1).png

How it works

LEDs produce light by passing the electric current through the diode. The LEDs anode (positive) is connected to power on the arduino, and the resistors limit the flow of current going through the LEDs while connected to the cathode (negative).

How to connect it

For this step, you will need your three LEDs, three jumper wires, and three 220 Ohm resistors. First, put down your three LEDs 1 pin space apart as shown in the circuit.

Green LED

For the green LED, connect a jumper wire from pin #6 on arduino to the anode of the LED. Then, connect a 220 Ohm resistor from the ground rail to the cathode of the LED.

Yellow LED

For the yellow LED, connect a jumper wire from pin #5 on arduino to the anode of the LED. Then, connect a 220 Ohm resistor from the ground rail to the cathode of the LED.

Red LED

For the red LED, connect a jumper wire from pin #4 on arduino to the anode of the LED. Then, connect a 220 Ohm resistor from the ground rail to the cathode of the LED.

Adding the Buzzer

Exquisite Fulffy-Kieran (2).png

How it works

When power is given to the buzzer, current goes through the wire inside of the buzzer, which creates a magnetic field. This causes the buzzer to vibrate, and the sound is created by the vibration. The buzzer has 2 pins, a positive and a negative channel. Connected to the negative leg is a 220 Ohm resistor, which limits the current flowing through it, preventing it from vibrating too much. The positive leg has a jumper wire connected from the arduino to it, and this gives it power.

How to connect it

Connecting the buzzer to the circuit is very simple. All you need to do is connect a jumper wire from pin #7 on the arduino to the positive leg of the buzzer (the longer leg). Then, you have to connect a 220 Ohm resistor from the ground rail to the negative leg of the buzzer (shorter leg).

Code

#define trigPin 2

#define echoPin 3

#define LEDlampRed 4

#define LEDlampYellow 5

#define LEDlampGreen 6

#define soundbuzzer 7

int sound = 500;

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(LEDlampRed, OUTPUT);

pinMode(LEDlampYellow, OUTPUT);

pinMode(LEDlampGreen, OUTPUT);

pinMode(soundbuzzer, OUTPUT);

}

void loop() {

long durationindigit, distanceincm;

digitalWrite(trigPin, LOW);

delayMicroseconds(2);

digitalWrite(trigPin, HIGH);

delayMicroseconds(10);

digitalWrite(trigPin, LOW);

durationindigit = pulseIn(echoPin, HIGH);

distanceincm = (durationindigit/5) / 29.1;

digitalWrite(LEDlampGreen, HIGH);

digitalWrite(LEDlampYellow, HIGH);

digitalWrite(LEDlampRed, HIGH);

if (distanceincm < 50) {

digitalWrite(LEDlampGreen, HIGH);

sound = 1000;

}

else {

digitalWrite(LEDlampGreen, LOW);

}

if (distanceincm < 20) {

digitalWrite(LEDlampYellow, HIGH);

sound = 1000;

}

else {

digitalWrite(LEDlampYellow,LOW);

}

if (distanceincm < 5) {

digitalWrite(LEDlampRed, HIGH);

sound = 1000;

}

else {

digitalWrite(LEDlampRed,LOW);

}

if (distanceincm > 5 || distanceincm <= 0){

Serial.println("Outside the permissible range of distances");

noTone(soundbuzzer);

}

else {

Serial.print(distanceincm);

Serial.println(" cm");

tone(soundbuzzer, sound);

}

delay(300);

}