Introduction: Arduino Alarm With Ultrasonic Sensor
This instructable is about how to make an easy and cheap alarm device by youself.All you need is basic knowledge in electronics and arduino programming.
If you have any questions or problems you can contact me on my mail:email@example.com
Here is also video of this project:
So let's begin.
Step 1: Watch the Video
You can also see on video how this project is working.
Step 2: Materials
All materials you need for this project you get on ebay or amazon.
-Arduino Mega or Uno
-Ultrasonic sensor HC-SR04
-2 push buttons
-Arduino relay modul
-3 LEDs(green,red,blue) If you want you can choose other colors
-some resistors (10k ohm)
Step 3: Connecting Ultrasonic Module
For this project I used ultrasonic module HC-SR04 because it is cheap and it is easy to work with.I bought it on internet for 3$.
So on this sensor you have 4 pins.
1.pin Vcc - this pin is connected to 5V+.
2.pin. Trig - you need to define this pin in your program.
3.pin Echo -this pin is the same as Trig you also need to define him.
4.pin GND - this pin is connected to ground.
How to define pin.
In this case you need to define pins for Trig and Echo.I defined digital pin 7 for trigPin and digital pin 8 for echoPin.
If you want you can choose other digital pins from 2 to 53..(except 0 and 1)
You need to write this code before void setup (). (Watch step Code)
#define trigPin 7
#define echoPin 8
Step 4: Wiring
When you are connecting pushbuttons you must connect resistor ( I used 10k ohm resistors) between GND and pushbutton.To ensure logical 0 on pushbutton.
Pushbutton (ON) is connected to digital pin 10
Pushbutton (OFF) is connected to digital pin 6
Buzzer is connected to digital pin 3
Red LED is connected to digital pin 4
Blue LED is connected to digital pin 5
Green LED is connected to digita pin 11
Relay is connected to digital pin 11
Wire for buzzer is firstly connected to relay module and then from relay to buzzer.I used NC contact on relay
Step 5: Code
This is code for alarm.
Just download it, plug in Arduino and upload code.