God's Eye TinkerCAD Circuit

by ashwin_chadha05 in Circuits > Arduino

528 Views, 1 Favorites, 0 Comments

God's Eye TinkerCAD Circuit

Alarm System Assignment.PNG

Introduction

A security system is meant to detect unlawful entrance into a building or other locations such as a house, school, museum, etc. This specific system detects objects within 131 inches. If said object is within range and is in motion, a buzzer will turn on and a set of LEDs resembling an exclamation mark will blink vibrantly unless a set of values are inputted into the 4x4 keypad that adds up to a sum greater than 25. Some steps may be altered to the user's preference, however, for the sake of neatness and clarity, follow the guidelines provided.

Supplies

Understanding the Components

step1.PNG
step1b.PNG
step1c.PNG
step1d.PNG
step1e.PNG
step1f.PNG
step1g.PNG

Solderless Breadboard:

A solderless breadboard is a device used to prototype electronics and tests circuit designs temporarily. Most electrical components in electronic circuits can be connected by inserting their leads or terminals into the holes and connecting them with wires where necessary. Once the power source being used (in this case an Arduino Uno R3), is connected to the breadboard's terminals, a jumper connection from the terminal to a hole in the breadboard will allow full connectivity for that row on the breadboard.

Arduino Uno R3:

The Arduino Uno R3 is a microcontroller board that uses a detachable ATmega328 AVR microcontroller in a dual-inline-package (DIP) format. There are 20 digital input/output pins on it (of which 6 can be used as PWM outputs and 6 can be used as analog inputs). The Arduino Uno R3 is the third and most recent version. All of Arduino's I/O pins can only execute HIGH/LOW commands, however, with the use of PWM output pins we have the capability of getting analog results with digital means (values other than 0, 1, HIGH, or LOW). Similarly, with the use of analog in pins, we can input values other than 0 and 1 into the Arduino microcontroller for it to process. All of these characteristics are essential when designing this security system.

5mm Red LED:

When current passes through a light-emitting diode (LED), it produces light. Electrons recombine with electron holes in the semiconductor, producing energy in the form of photons.

Resistors:

A resistor is a two-terminal non-polarized (can be connected to the circuit in any direction and still function accordingly) electrical component that acts as a circuit element by implementing electrical resistance. Resistors are employed in electronic circuits for a variety of purposes, including reducing current flow, adjusting signal levels, dividing voltages, biasing active components, and terminating transmission lines. They are also uniquely color-coded to help the user identify the resistance of the resistor in ohms. In this case, we will be using 330-ohm resistors and 1000 ohm resistors.

Piezo Electric Buzzer:

Piezo buzzers are inexpensive gadgets that produce basic beeps and tones. They use a piezo crystal, which is a type of material that changes when electricity is given to it. When a crystal collides with a diaphragm, such as a small speaker cone, a pressure wave is generated, which the human ear detects as sound.

PIR Motion Sensor:

A passive infrared sensor (PIR sensor) is a type of electronic sensor that detects infrared (IR) light emitted by objects in their field of vision. They're most commonly found in motion detectors with a PIR sensor. They only function by sensing infrared radiation (radiant heat) that is emitted or reflected by objects. These sensors measure heat energy in the surroundings using a pair of pyroelectric sensors. These two sensors are placed next to one other, and the sensor will engage when the signal difference between the two sensors changes (for example, if a human walks down a corridor).

Ultrasonic Distance Sensor:

An ultrasonic sensor is an electronic device that uses ultrasonic sound waves to detect the distance between a target item and transforms the reflected sound into an electrical signal. Ultrasonic sensors use the time between emission and reception to calculate the distance to the target. This is comparable to how radar determines how long a radio signal takes to return after colliding with an entity. Ultrasonic waves move quicker than audible sound waves (i.e. the sound that humans can hear).

4x4 Keypad:

This keypad has 16 buttons that are laid out in a 4x4 telephone grid. Since the keys are linked in a matrix, scanning the pad requires just 8 microcontroller pins (4 columns and 4 rows). The four-row pins are on the left, followed by the four-column pins on the right. These lines may be scanned by a microcontroller to identify button-pressed states.

Copper/Aluminum Conductor Wires:

A conductor is a substance (often a metal like copper) that permits electrical current to flow freely. Electrons are what make up the current. An insulator, on the other hand, blocks electricity from flowing through it. This ensures that the circuit is fully connected and that each component functions properly.

Connectivity and Placement

Schematic.jpg
step2.PNG
step2b.PNG
step2c.PNG
step2d.PNG
step2e.PNG
step2f.PNG

Check Hand Drawn Schematic Above For Full Diagram Placement, More Information Below:


Solderless Breadboards:

Firstly, the first breadboard's top power and ground rails must be connected to the 5v pin and GND pin on the Arduino. Then a jumper connection is required from the top power and ground rails to the bottom power and ground rails as we will have to make good use of the breadboard's space to fit all of the components. Finally, a jumper connection is required from the bottom ground rail of the breadboard to the bottom ground rail of the second breadboard.

Ultrasonic Distance Sensor:

Place the distance sensor relatively close to the left side of the first breadboard without overlapping the wires as we will need to save some room for other components. Firstly, use jumper wires to connect the bottom power and ground rails to the rows on the breadboard which the distance sensor's power and ground pins are placed. Secondly, create a jumper connection from and non-PWM pin on the Arduino to the row in which the trig pin on the distance sensor is placed. This is because the trig pin only creates a pulse allowing the echo pin to detect the distance of the object thus requiring only a HIGH or LOW value. Finally, create a jumper connection from a PWM pin on the Arduino to the row in which the echo pin on the distance sensor is placed as this pin will create/detect a whole set of values rather than just 1 or 0 for the Arduino microcontroller to process.

PIR Motion Sensor:

Firstly, place the PIR motion sensor relatively close to the distance sensor to conserve space. Secondly, connect the motion sensor's power and ground pins to the bottom power and ground rails via jumper wires. Finally, use a jumper connection to connect a non-PWM pin on the Arduino to the row in which the signal pin is placed on the breadboard. This is because there are only 2 values that are essential for this circuit, motion/no motion, 0/1, or HIGH/LOW.

Piezo Electric Buzzer:

Firstly, place the buzzer relatively close to the PIR sensor to save room. Secondly, connect the buzzer to ground via a jumper connection to the bottom ground rail. Finally, connect the positive pin on the buzzer to a non-PWM digital I/O pin as we only require the buzzer to do one of 2 things, create a high-pitched tone or remain quiet.

LEDs:

Firstly, arrange the LEDs as pictured in the above image and relatively close to the buzzer. Then create jumper wire connections for each major group of LEDs to a digital I/O pin on the Arduino as for this circuit all we require is a simple On/Off feature. Finally, use 330-ohm resistors as jumper connections (1 for each major group of LEDs) to the ground terminals on the breadboard (top or bottom, whichever is convenient).

4x4 Keypad:

Firstly, due to all of the room on the first breadboard being filled to maximum occupancy, place the keypad on the second breadboard. Then connect the row pins to the ground via 4, 1000 ohm resistors (1 resistor for each pin) jumper connection to the bottom ground rail. Then connect the 4-row pins to the analog pins (because when we code this device each row will have the capability to create 3-4 different values) on the Arduino via jumper wire connections. Next, connect the 4 column pins to any 4 digital I/O pins available.

Understanding the Code

step3.PNG
step3b.PNG
step3c.PNG
step3d.PNG
step3e.PNG

Declaring the Variables and Assigning Values/ Arduino Pins:

First, we need to declare the many integer variables needed such as the pins for the distance sensor, motion sensor, keypad, buzzer, and LEDs. We will also need a variable to keep track of the values inputted by the keypad (can be named whatever the user prefers which is relevant to the theme, for this case I just used the name "val").

Setup:

Now we will need to ensure all pins are correctly dubbed as input or output pins. For example, the LED pins will be output (no data is being transferred from the LEDs to the Arduino, however, a current is being forced out from the Arduino and into the LEDs), and the row pins in the keypad will be input (data is being transferred from the keypad to the Arduino every time a button is pressed).

Flashes:

Every time motion is detected and the object is within distance range, we want the LEDs to blink on and off indicating intrusion. Therefore, for the sake of convenience, we should create a function dedicated to the LEDs and will be called upon when the time comes (the name of the function is optional, for this case I used the name "flashes"). This function will start by waiting a couple of seconds, turning all of the LEDs on, waiting a couple of seconds, turning all of the LEDs off, waiting a couple of seconds, and repeating.

Main Loop:

Firstly, we have to turn on the echo, trig, and sensor pins. Then create 2 variables known as duration and distance to keep track and calculate the distance for the distance sensor so it will be more useful for us. This will be done by using the pulseIn command and reading the echo pin for the duration. This will be useful to calculate the actual distance for it to be used by the user, we will have to divide the duration by 74 and divide that quotient by 2. This equation will determine the value for our distance variable. Secondly, we need to make the code for the keypad. When the loop begins, it will start by turning each column on. Then check row by row if an individual button was pressed. If so, it will deliver this information to the Arduino which will add that number to the previous value of val. If the 0 key is pressed, val will have a value of 0. Now that we have coded the values for the distance variable and the keypad, we will need to determine an exact value for val in which if that value is met or exceeded, the system will turn off. My circuit's On/Off determiner was 25, however, this value can be varied depending on the user's preference. To code this, we will use an if statement stating, if val has the value of 25 or greater, the buzzer and the LEDs will remain off/LOW. To ensure the distance sensor is relevant in this security system if the object being sensed is out of range, we do not want the LEDs or the buzzer to turn on as there is no intrusion to detect. To do this we will create an "else if" statement recognizing that if the distance sensor is sensing a distance of 1 inch or greater than 1 inch, 100 inches or less than 100 inches, and if the sensor pin in the motion sensor is sensing motion (reading a 1), the buzzer will sound (and stay on) and the LEDs will flash (call upon the flashes function).

Code:

int pinSensor = 5;

int pinEcho = 3;

int pinTrig = 2;

int pinBuzz = 6;

int pinExclamationTop = 8;

int pinExclamationLeft = 7;

int pinExclamationCenter = 4;

int pinExclamationRight = 9;

int row1 = A0;

int row2 = A1;

int row3 = A2;

int row4 = A3;

int col1 = 10;

int col2 = 11;

int col3 = 12;

int col4 = 13;

int val = 0;

void setup(){ //ensures all pins are correctly reserved as input or output pins

pinMode(pinEcho, INPUT);

pinMode(pinTrig, OUTPUT);

pinMode(pinSensor, INPUT);

pinMode(pinBuzz, OUTPUT);

pinMode(pinExclamationTop, OUTPUT);

pinMode(pinExclamationLeft, OUTPUT);

pinMode(pinExclamationCenter, OUTPUT);

pinMode(pinExclamationRight, OUTPUT);

pinMode(row1, INPUT);

pinMode(row2, INPUT);

pinMode(row3, INPUT);

pinMode(row4, INPUT);

pinMode(col1, OUTPUT);

pinMode(col2, OUTPUT);

pinMode(col3, OUTPUT);

pinMode(col4, OUTPUT); }

void flashes(){

digitalWrite(pinExclamationTop, HIGH);

digitalWrite(pinExclamationRight, HIGH);

digitalWrite(pinExclamationCenter, HIGH);

digitalWrite(pinExclamationLeft, HIGH);

delay(500);

digitalWrite(pinExclamationTop, LOW);

digitalWrite(pinExclamationRight, LOW);

digitalWrite(pinExclamationCenter, LOW);

digitalWrite(pinExclamationLeft, LOW);

delay(500); }

void loop() { //allows the 7 segment display (if there was one) to show the tens digit of the distance of the object

//detected by the ultrasonic distance sensor after the motion

//sensor turns it on as well as make the buzzer beep when an error occurs

pinSensor = digitalRead(5);

long duration, distance;

digitalWrite(pinTrig, LOW);

delayMicroseconds(2);

digitalWrite(pinTrig, HIGH);

delayMicroseconds(10);

digitalWrite(pinTrig, LOW);

duration = pulseIn(pinEcho, HIGH);// provides "duration" with its correct value

distance = (duration/74)/2;// calculates distance

digitalWrite(col1,HIGH);// Provides a function for the numerical values in the first collumn (1, 4, 7)

digitalWrite(col2,LOW);

digitalWrite(col3,LOW);

digitalWrite(col4,LOW);

if(digitalRead(row1) == 1){

val = val + 1; }

else if(digitalRead(row2) == 1){

val = val + 4; }

else if(digitalRead(row3)== 1){

val = val + 7; }

digitalWrite(col1,LOW);// Provides a function for the numerical values in the second collumn (2, 5, 8, 0)

digitalWrite(col2,HIGH);

digitalWrite(col3,LOW);

digitalWrite(col4,LOW);

if(digitalRead(row1) == 1){

val = val + 2; }

else if(digitalRead(row2) == 1){

val = val + 5; }

else if(digitalRead(row3) == 1){

val = val + 8; }

else if(digitalRead(row4) == 1){

val = 0; }

digitalWrite(col1,LOW); // Provides a function for the numerical values in the third collumn (3, 6, 9)

digitalWrite(col2,LOW);

digitalWrite(col3,HIGH);

digitalWrite(col4,LOW);

if(digitalRead(row1) == 1){

val = val + 3; }

else if(digitalRead(row2) == 1){

val = val + 6; }

else if(digitalRead(row3) == 1){

val = val + 9; }

if (val >= 25){

digitalWrite(pinBuzz, LOW);

digitalWrite(pinExclamationTop, LOW);

digitalWrite(pinExclamationRight, LOW);

digitalWrite(pinExclamationCenter, LOW);

digitalWrite(pinExclamationLeft, LOW); }

else if (distance >= 1 && distance <= 100 && pinSensor == 1){

digitalWrite(pinBuzz, HIGH);

flashes(); }

}

Conclusion

In conclusion, this is the entirety of this security system. With the use of the ultrasonic distance sensor, one can have an "automatic trigger" which helps save electricity usage for the system as only when the system is truly needed will it activate. Similarly, without motion detected by the motion sensor, the system will remain off unless and until it is needed, making it an overall efficient system. Furthermore, the placement saves space making it as compact as possible and the code uses as few lines as possible making it as practical as possible for the engineer.

My Circuit