Build Your Own PIR Motion Detector With Wia




You will need:

Connecting the Components

Insert the PIR Motion detector module on top of the Wia Dot One. Take care to connect the module pointing in the correct direction, as shown in the picture above. You will notice that the rounded corners of the boards correspond to each other when inserted correctly.

Now, connect the Wia Dot One to your computer with the micro USB cable. A solid red light should appear on the board. We are finished connecting everything we need!

Configuring Your Dot One Device

Follow these steps to set up your Dot One:

  • On your smartphone, head to the App Store. Search for the Wia App and install it on your phone.
  • Once the app is installed, create an account or sign in and select one of your Lab spaces. Navigate to the Devices tab and click on Add Device.
  • Select Wia as the device manufacturer and click on Next. Select Dot One as the device model and continue. If requested by the app, press allow for Bluetooth and Location access.
  • Click the Scan button to begin the search for your device. You should now be able to see your device listed on the list — click on it and give complete Wi-Fi access details so the Dot One can be controlled remotely later. Enter a name for your Dot One and head to your email — you should soon receive an invite to begin programming!

That’s it configured!

Programming Your Dot One

Navigate to the Code tab on the left sidebar and select Create Code Project.

For this tutorial, we demonstrate the Blocks Project feature. We recommend this option for all beginners as it is simpler and faster for our project. Wia will then translate your blocks into the code for the Dot One. Feel free to select Code Project if you are more advanced and are comfortable with writing the code yourself.

You can now drag blocks onto the diagram to express what actions you would like the Dot One to perform. In this tutorial, we want to send a Wia Event each time motion is detected — later, we will make the Wia Dashboard send us a notification each time motion is detected.

  1. Go to the Comms tab and drag the block Connect to WiFi onto your diagram.
  2. In the Logic tab, you will find an If/Do block. This allows us to express a condition. Drag this block and connect it underneath your Wi-Fi block.
  3. Open Wia > Modules and drag the block Motion Detected onto your diagram. Connect it to the right side of the [If] word. You’re almost there!
  4. Now, in Wia > Cloud, drag the Create Event block and connect it just right of the Do word.
  5. Then, change the event name from “my-event” to “motion-detected”. Complete!

You can compare your diagram with our version below. You will notice that while you were adding the blocks to the control diagram, Wia translated them in real time on the right to the code, which will soon be uploaded to the Dot One.


Uploading Your Program

Still in the block editor, press on the rocket icon on the top right of the window. Select your device from the given options and hit the upload button.

When the platform confirms the code is deployed, press the Reset button — the button left of the USB cable — and wait until the LED stops flashing.

If the Dot One is still connected to the Wi-Fi, the code will be automatically uploaded and start running automatically. That’s it!

Configuring Flows — Sending Notifications

First, let’s confirm that you are receiving an event when motion is detected. Navigate to the Wia Dashboard and select your Dot One in the Devices tab. Go to the Debugger, make some motion near the motion detector, and wait a few seconds for the event to come in. Try refreshing the page to update the list. Once the first event comes in, you can view the Event history in the Events tab. Great!

Now, head to the Flows tab and create a new Flow for this project. A flow is a program that defines how the Wia platform will respond to incoming events.

Let’s start with placing the “Event Created” block. What this block allows us to do is start the flow each time that an event is created by a device. As we already sent an event previously called motion-detected, we select this event from the dropdown list. Next, we select the device that will send the event and press Update. This block is now ready.

The next block we want to place is found in the Action tab. We will use the Notification block to specify that a notification should be sent each time an event is created. After filling out all the details of the notification block, we connect the two blocks. Once you leave the Flow page, your new configuration will become active.


Congratulations! Your new IoT device is up and running!


Why Are Events Sending Even When Motion Should Not Be Detected?

Make sure the board is connected in the correct way — remember, the corners of the module and the Dot One should correspond with each other.

Make sure you are not touching the bottom of the Dot One with your fingers — you may accidentally lead to electrostatic discharge, which will impact the proper operation of the devices. Some things that can happen include resetting the device, sending a false motion detection input, or even permanently damaging the device.

Also, note that this motion detector is very sensitive so any sort of motion within a short distance of it could result in an event being sent. Try moving to a more controlled area where there is less motion.

Dot One Device Is Not Appearing During the Scan?

It is possible that your device needs to be reconfigured to a new Wi-Fi. Try the steps below:

  • Hold down both buttons on the Dot One for 1 second
  • With the USB cable pointing towards you, release the left button and keep pressing the right button for 12 more seconds
  • Click on the “Refresh” button to scan for your device.

That’s all for now! Hopefully, you learned something new. Please leave any thoughts or questions in the comments below. 

This UrIoTNews article is syndicated fromDzone