ARDUINO: How I made a alarm that makes noise once you come near it.
- AT Electronics
- Jul 28, 2020
- 2 min read
ARDUINO ALARM PROJECT
Recently I created some sort of "alarm" that once you come near it makes noise using an active buzzer. I will give you a picture of the circuit, a picture of the code, and an explanation of how I made it. YOU can also follow along and create this simple project. Lets get into it.
First we have to identify the components. Here are some of the things you will need in this project.
Standard Jumper Wires.
Any Arduino board (we will be using Arduino Uno specifically, if you dont know what is Arduino stay tuned for a new explanation post)
Active or passive buzzer (which will operate the noise in the circuit)
Ultrasonic Sensor (HC-SRO4 Module, this module uses some form of echolocation, more explanation soon in new post !)
Now lets get into the circuit, here is a brief picture of it below ---
PICTURE COMING SOON
----
Here is how you do it assuming you have some brief knowledge of Arduino, if not tutorial posts will come soon to provide some information to help you get into Arduino. Connect your buzzer to a breadboard.On the side of the active buzzer with a plus, connect that to any of any of the numerical pins on the Arduino board. Connect the other side of the buzzer to the ground pin on the Arduino. Ground means negative or at times, any piece of solid metal.Now the next step is to connect the Ultrasonic Sensor. Look at the pinout below to do it. U do not need a breadboard to connect it, just some generic male to female jumper wires.
GND label on ultrasonic sensor to ---- ground on arduino
Echo label on ultrasonic sensor to --- pin 8 on arduino
Trig label on ultrasonic sensor to --- pin 9 on arduino
VCC label on ultrasonic sensor to ---- 5 volts on arduino
Now you have done the circuit! Now its time for the code. You can copy the code below. I will give a brief explanation of how the code works also!
int echopin = 8;
int trigpin = 9;
int buzzpin = 12;
int traveltime;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(echopin,INPUT);
pinMode(trigpin,OUTPUT);
pinMode(buzzpin,OUTPUT);
}
void loop() {
digitalWrite(trigpin,LOW);
delayMicroseconds(10);
digitalWrite(trigpin , HIGH);
delayMicroseconds(10);
digitalWrite(trigpin , LOW);
traveltime = pulseIn(echopin, HIGH);
delay(300);
Serial.print(traveltime_cm);
Serial.print(" cm");
Serial.println();
delay(1500);
if (traveltime_cm > 200) {
digitalWrite(buzzpin, HIGH);
delay(10);
digitalWrite(buzzpin, LOW);
delay(10);
}
}
float traveltime_cm = ( traveltime / 2) / 29.1;
So basically how this works is that the program uses the sensor to detect the time it took to come from the object and back. This line below converts the time to length.
float traveltime_cm = ( traveltime / 2) / 29.1;
Then it reads the length and if it is in a specific length near the Ultrasonic Sensor then it proceeds to signal to the buzzer to make a sound. That is all for the post I hope you learned something. Thank You for reading this post!
ggs bro
NP NP cool stuff
thx praneel
Congrats buddy