Arduino Alarm With Ultrasonic Sensor




About: Student at Faculty of Electrical Engineering and Computer Science. ...

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.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

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.

Be the First to Share


    • Made with Math Contest

      Made with Math Contest
    • Multi-Discipline Contest

      Multi-Discipline Contest
    • Robotics Contest

      Robotics Contest

    7 Discussions


    Question 1 year ago on Step 5

    Hi there

    Can I use the S4A to code this? If so, please advise. Thank you!


    1 answer

    Answer 1 year ago

    Sure you can. Just look at some tutorials on youtube. That is the quickest way to learn something fast.


    3 years ago

    So intersting! I like it.


    Reply 3 years ago

    pleace explain and with SCHEMATICS instead of relay.

    That would be awesome again.


    3 years ago

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