Thursday, June 20, 2024

Motion Sensor With Voice Alarm Using Arduino

Motion sensor alarms are readily available in the market, but these are expensive. Here is a simple and inexpensive Arduino based motion sensor alarm with voice alert. It can be used for security purposes.

Typically, for outdoor monitoring, motion sensor alarm consists of a PIR (passive infrared) sensor that detects the movement of human beings in the vicinity. The author’s prototype is shown in Fig. 1. The block diagram of the motion sensor alarm is shown in Fig. 2.

Fig. 1: Author’s prototype
Fig. 1: Author’s prototype
Block diagram of motion sensor alarm
Fig. 2: Block diagram of motion sensor alarm

Circuit and working

The circuit diagram of the motion sensor alarm is shown in Fig. 3. It consists of a PIR motion sensor (MS1), Arduino Nano (Board1), LM386 audio amp (IC1), and 8-ohm speaker. You can use any Arduino board in place of the Arduino Nano board.

Circuit diagram of motion sensor alarm
Fig. 3: Circuit diagram of motion sensor alarm

Install the required library in Arduino IDE by downloading the library from SketchInclude libraryManage Libraries options, as shown in Fig. 4. Search the PCM library from Library Manager (refer Fig. 5) and install it. Similarly, follow the above steps and install the PIR sensor library.

Manager Libraries in Arduino IDE
Fig. 4: Manager Libraries in Arduino IDE
Search PCM library from Library Manager
Fig. 5: Search PCM library from Library Manager

Coding Arduino

Arduino code (Motion_Detection.ino) is written in the Arduino programming language.
Initialise the libraries in the code and also declare the sensor and indicator pins as given below:

- Advertisement -

#include int sensorpin = 4; //sensor pin
Int led =13; //indicator pin

Initialise the audio file with encoded samples:
const unsigned char sample[] PROGMEM =

{ 126, 127, 127, 126, 127, 126, 127, 127,
126, 126,….… };

- Advertisement -

Define the pinMode using following instructions:

pinMode (sensorpin,INPUT);

Create a variable that reads the sensor value in digital form:
int sensorValue = digitalRead (sensorpin);

Now, create a condition that compares with the sensor value. If the condition is true, it performs the task accordingly. Here the task is to play the sample audio file and turn on the LED indicator (LED1). Otherwise, the condition is false, with no audio alert and LED1 off. The following code performs these tasks:

if (sensorValue == 1)
else if (sensorValue == 0)

Construction and testing

A PCB layout for the motion sensor alarm is shown in Fig. 6 and its components layout in Fig. 7.

PCB layout for motion sensor alarm
Fig. 6: PCB layout for motion sensor alarm
Fig. 7: Components layout of the PCB

Download PCB and Component Layout PDFs: click here

Download Source Code

Before assembling the circuit, do not forget to upload Motion_Detection.ino on the Arduino Nano board. After assembling the circuit on the PCB, connect the PIR sensor across CON1 and 12V across CON2.

Crosscheck the wiring/connections as per the circuit diagram. Then, power on the circuit with a 12V DC supply or 12V battery.

You can install this project in your backyard or any other appropriate location in your house. Then extend the speaker and wires to your room. Alternatively, you can connect it to your mini speaker amplifier through an audio jack.

When you power on the circuit, and if someone is in front of the PIR sensor, you will hear ‘alert motion’ voice alert in the speaker continuously till the person moves away from the sensor. This sensor will detect a human in the range of up to ten metres based on the sensitivity of the sensor module. You can change the sensitivity by adjusting the inbuilt potmeter in the sensor module.

Venkatesh T. is an electronics hobbyist. His areas of interest include microcontrollers, embedded systems and the Internet of Things



Unique DIY Projects

Electronics News

Truly Innovative Tech

MOst Popular Videos

Electronics Components