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

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)


-jumper wires


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. Vcc - this pin is connected to 5V+. Trig - you need to define this pin in your program. Echo -this pin is the same as Trig you also need to define him. 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.


1021191263 made it!(author)2016-07-23

So intersting! I like it.

Nematic%21 made it!(author)2016-07-19

I think insted of relay you sholud have used mosfet

iwoox made it!(author)2016-07-20

I will try with mosfet

WannaDuino made it!(author)2016-07-20

pleace explain and with SCHEMATICS instead of relay.

That would be awesome again.

tomatoskins made it!(author)2016-07-18

This is such a great project! You can use it for so many applications!

About This Instructable




More by iwoox:Controlling DC motors with Arduino and L293Make your own development board with microcontrollerArduino simple debounce
Add instructable to: