Home Arduino Projects Arduino Projects: PIR Motion Sensor

Arduino Projects: PIR Motion Sensor

by Nikodem Bartnik

Alarms are very common nowadays, a lot of people have alarms in the whole house. But what if you want your internal alarm? For example, you may want to stop your siblings from entering your room, this project will help you build a simple PIR motion sensor using the Arduino Uno board.

This project won’t have any type of switch to turn it off so the only way to stop it is to get out of the room where it is installed or turn down the power. This project will also provide a glimpse of how the tone function works.

Arduino Projects: PIR Motion Sensor

Parts needed

You will need just 3 main parts:

What is a PIR sensor?

passive infrared sensor (PIR sensor) is an electronic sensor that measures infrared (IR) light radiating from objects in its field of view.

Wikipedia

PIR sensors allow you to sense motion and is mostly used to detect whether a human has moved in its range.

PIR sensor project with Arduino

First thing we have to do, before uploading the program is getting the connections ready. You will need 5 Jumper wires to connect everything, all of these wires should have male-female connectors.

Arduino Projects: PIR Motion Sensor
Arduino Projects: PIR Motion Sensor
Arduino Projects: PIR Motion Sensor

Now it’s time to upload the program to Arduino. In the comments, you can find explanation of the whole code. I set the frequency to 3000 Hz because I found on the internet that most alarms use this frequency. The PIR sensor is basically movement sensor so whenever it detects movements, it sets OUT to HIGH, you can control the time of this HIGH state and the sensitivity of your sensor with the 2 potentiometers shown on the image below.

Arduino Projects: PIR Motion Sensor

This project creates beep sounds (work similar to blink but with buzzer instead of an LED) when movements are detected. You can easily change the time of the beep by changing the delay time at the end of for loop.

The Code

So as you can see we use tone() in this code, how does it work?

[code language=”cpp”] tone([pin_number], [frequency]); [/code]

In our case we use pin 3 and 3000 Hz of frequency, so for us this function will looks like:

[code firstline=”26″] tone(3, 3000); [/code]

There is also an option to add time at the end so it looks like this:

[code language=”cpp”] tone(3, 3000, 1000); [/code]

The example above will produce a sound of 3000 Hz on pin 3 and this sound will last for 1 second. So it works the same as this:

[code language=”cpp”] tone(3, 3000); delay(1000); noTone(3); [/code]

But it is shorter.
So let’s see how the alarm system works.

You might also like:

Related Posts

Leave a Comment

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More

Privacy & Cookies Policy