I am such a guy who loves his thing very much and specially i don't like any one coming to my work space without my prior knowledge,mostly if the persons are my sibling or young kids.I need a way to make an alarm to help me protect my space and guard it properly.
But buzzer are too low in volume to implement.Until i got this . A freaking loud siren from DNA technology.
It was so loud that i had to wear plugs before i had to turn it on.
I just loved it but also needed to decrease the volume of the siren , which i achieved by using a pwm ,which i will explain later.
I coded a simple sketch in arduino to input from a ultrasonic sensor and if their is somebody near 100 cm of my workplace it ativates te alarm and stays on still the person is present.
Also like my page for support
Step 1: Items
You can easily get all Electronic Components Online in India from DNA Technology
I still give the items you shall be needing
I just showed the breadboard prototype in the instructable, i will be making a case later and shift he circuit in the case.
Step 2: Circuit
The Circuits are given
The only thing that i need to explain is the Ultrasonic sensor.
HC-Sr04 Ultrasonic Sensor
It is one of the most commonly used distance measuring ultrasonic sensors and works extremely well with Arduino.
This module has 4 pins- Vcc (5V), Trig, Echo, GND. Trig (trigger) is used to send out an ultrasonic high level pulse for at least 10μs and the Echo pin then automatically detects the returning pulse.
How it works ?
The time it takes the sound wave to be sent, hit the object and return back to the sensor is measured. This time is then multiplied by the speed of sound (343m/sec = 0.0343cm/μs = [1/29.1] cm/μs approx.) to give the total distance traveled by the ultrasonic wave, which is then divided by 2 (to account for the fact that the wave was sent, hit the object, and then returned back to the sensor, hence covering twice the distance to the object)Distance = (Time for wave to return * Speed of sound) / 2.
Step 3: How to Control the Volume of Buzzer Using PWM
PWM Stands For Pulse Width Modulation
Analog Signal can be represented in digital world by means of pulse train .In a Pulse Width Modulation we basically represent analog voltage it term of the pulse width. In arduino, we use the analogwrite function to get a PWM wave the function generates a square wave of specified duty cycle the value of which is defined by the user. In the graphic below, the green lines represent a regular time period. This duration or period is the inverse of the PWM frequency. In other words, with Arduino's PWM frequency at about 500Hz, the green lines would measure 2 milliseconds each. A call to analogWrite() is on a scale of 0 - 255, such that analogWrite(255) requests a 100% duty cycle (always on), and analogWrite(127) is a 50% duty cycle (on half the time)
Step 4: Programming the Arduino
I searched a lot for the ultrasonic sensor, there was Ping library but it didn't worked for me.
Also there was a newping library
but i went with a simple sketch
int triggerPin = 7; //triggering on pin 7
int echoPin = 8; //echo on pin 8
int siren= 3;
//we'll start serial comunication, so we can see the distance on the serial monitor
pinMode(triggerPin, OUTPUT); //defining pins
int duration, distance; //Adding duration and distance
digitalWrite(triggerPin, HIGH); //triggering the wave(like blinking an LED)
delay(10); digitalWrite(triggerPin, LOW);
duration = pulseIn(echoPin, HIGH); //a special function for listening and waiting for the wave
distance = (duration / 2) / 29.1; //transforming the number to cm(if you want inches, you have to change the 29.1 with a suitable number
if (distance < 100 )
analogWrite(led,75); Serial.print("ON"); //printing the numbers
Serial.print(distance); //printing the numbers Serial.print("cm"); //and the unit Serial.println(" "); //just printing to a new line