Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Make Your Own PIR Motion Sensor

DZone's Guide to

Make Your Own PIR Motion Sensor

Motion sensors are high-tech security devices you see in the movies, right? Of course not. Learn to make your own motion tracking device.

· IoT Zone
Free Resource

In this tutorial, we will show you how to build Wi-Fi PIR motion sensor connected to EasyIoT Cloud. We will use a ESP8266, a PIR module, and the Arduino IDE.

Introduction

ESP8266 PIR motion sensor

Materials

  • ESP8266 Wi-Fi module.
  • PIR sensor.
  • 3.3V power supply (battery or regulator).

EasyIoT Cloud configuration 

Register to the EasyIoT Cloud service. If you do not receive a registration email, check your spam folder. If it's not there, contact us and we will activate your account.

Then go to Configure->Modules->Add Module. Set Digital Input (DI) as the module type and name it PIR sensor.

Next, click on Sensor.Parameter1. Set "Description" to PIR and check UI notifications to enable real time notification in the web interface.

Then press the save button. After saving, you will see InstanceId/ParameterId. Make a note of it — you will need it later in program.


Go back to module configuration and add two more parameters (Add parameter button).  

The two parameters are to set text in the module. Name the first parameter Settings.StatusText1 and the second one Settings.StatusText2. Set the value for the first as "Motion" and for the second as "Ok".

Next, we will set a picture for the module. We add two more parameters and name them Settings.Icon1 and Settings.Icon2. For the first parameter, set the value to "siren_2.png," and for the second second parameter, set the value as "siren_1.png".

After you add all the parameters, your module configuration should look like this:

 

Program

The program is written in the Arduino ESP8266 IDE. See the Arduino ESP8266 IDE tutorial to learn how to connect your ESP8266 module to your computer to upload the program. The program is available at our GitHub. You will also need the EIoTCloudRestApi library. In the library, set the access point username and password. 

In the program, change EIOT_CLOUD_INSTANCE_PARAM_ID:

// EasyIoT Cloud definitions - change EIOT_CLOUD_INSTANCE_PARAM_ID

#define EIOT_CLOUD_INSTANCE_PARAM_ID    "xxxx"

Set the InstanceId/ParameterId in your parameter configuration.

If you change the GPIO pin on the ESP8266, then also change the GPIO pin in the program.



Hardware

In our case, we use the ESP8266 01, but you can use any other ESP8266 with the FDTI programmer. For your power supply, you can use 2 AA batteries or 3.3V regulator AMS1117 (see buying guide).

The PIR sensor is powered by 5V, but if we look at the schematic, we will see that it's 3.3V internally. Because the ESP8266 is 3.3V, we can bypass the PIR internal regulator. 

PIR sensor module

The Connection after the regulator is available at JP1 pin 3. In our case, we will connect the 3.3V power supply to this point and not to 5V power supply.

You can see it in the following picture:

ESP8266 to PIR sensor connection


PIR  ESP8266
3.3VCC after internal regulator 3.3V VCC
GND GND 
OUT GPIO2 on ESP8266

ESP8266 PIR sensor schematic 

And there you have it! Enjoy your motion sensor. See more tutorials at http://iot-playground.com/build.

Topics:
internal ,motion ,module ,pir ,sensor ,arduino

Published at DZone with permission of Igor Jarc, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

THE DZONE NEWSLETTER

Dev Resources & Solutions Straight to Your Inbox

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

X

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}