Arduino Projects Breadboard Projects Circuits Electronics Projects Learn Electronics Robotics Projects
Dustin Hodges  

How to Make an OwlBot: The Bird Intimidator – Part 1: Motion Sensing

This post may contain affiliate links which means we may receive a commission for purchases made through links. Learn more on our Privacy Policy and Terms and Conditions pages.

Reading Time: 24 minutes
Project Name:OwlBot
Project Description:Part 1 build of the OwlBot, where we start by getting the prototype of the OwlBot to sense infrared motion.
Project Difficulty:Easy
Project Note:For this first part of the project, we’ll focus on the OwlBot’s infrared sensing capabilities using a PIR sensor module.

Introduction

In this project we’re going to be performing the initial steps of what will eventually be the OwlBot. The OwlBot will be a device that can be used as a bird intimidation tool to scare away pesky birds in the yard, around the house or barn, at restaurants, or in trees, bushes, and gardens. Hence, the phrase, “The Bird Intimidator”.

The OwlBot (a.k.a. “The Bird Intimidator”) we’ll be making will be done in several parts. The OwlBot is an ambitious project. When complete, the OwlBot will sense motion. When motion is detected, the OwlBot should make owl sounds, perform varying movements, and flash its red eyes to intimidate and scare away pests. To put together all these tasks in one page would be too long and cumbersome, so we’ve decided to split each process we want the OwlBot to do into easy to accomplish chunks or parts as we continue on our goal to complete the OwlBot.

This is Part 1

This is part one. This initial part of the OwlBot project will involve setting up its ability to sense motion via a passive infrared sensor (PIR). Our goal at the end of this part of the project will be to have the PIR sensor and an Arduino Uno communicating to each other when motion is detected and to print out whether or not motion is detected.

Before we jump into prototyping our way to sensing motion, let me first discuss why there was ever a need for the OwlBot in the first place. As with anything one builds, there’s a need to be satisfied and a problem to be solved. From my personal experience, these words were more truer for what problem I needed solved.

A Problem to Be Solved

“As with anything one builds, there’s a need to be satisfied and a problem to be solved.”

Every spring brings many changes to the year. The grass begins to grow, meaning the chore of mowing the lawn begins again for the warmer months. New life is bread into the surroundings and birds begin their chore of gathering items, like twigs, twine, and other rubbish to weave their nests into homes. This may all sound fine-and-dandy, but around my home lurks a kind of bird that can actually be quite a nuisance; a bird that can actually reign terror to an unsuspecting, innocent homeowner, such as myself, who is just trying to trim the bushes and mow his lawn.

The Problem

I bring to you Exhibit A: The Northern Mockingbird (Mimus polyglottos):

The Northern Mockingbird has a range throughout North America, from southern Canada south to Mexico. It was designated as the Texas state bird in 1927, and is one of the few birds found in every kind of habitat, from desert to forest and even in the city.

In the spring they can be seen displaying their wings and often heard singing. Mockingbirds, in particular the males, can be quite territorial during the breeding season. I’ve seen them guard their territory against everything from dogs and cats, to other small birds, even larger birds, such as hawks and buzzards, as well as humans.

If a creature trespasses into the mockingbird’s territory, the mockingbird goes into attac… I mean protective mode. The mockingbird has a fearless attitude when it comes to protecting its environment and has no issue with swooping in on its victims with intense speed, repeatedly turning back for more, squawking and flogging until the trespasser has retreated far away from its area.

Every year I’m attacked by this menace. The Northern Mockingbird. Mimus polyglottos. Every year, somewhere on my territory becomes its territory, and I become the victim of their vicious attacks.

One year I was attacked while running. The next, while walking on the sidewalk to my driveway. This past year’s spring though, took the cake. While getting ready to mow my lawn, I opened my garage door to pull out my lawn mower, and before I could even pour gasoline into it I felt and heard something flutter near my head. I turned to look at what it could be, to see a mockingbird in mid-flight making its target… me!

It made a sharp turn maneuver like a fighter-jet not 10 feet away from me, not 10 feet in altitude, to come right back at me to attack again. Unbeknownst to me though, was that it had built a nest with its partner in the bushes right next to my garage. So, any time I tried to come outside, there it was waiting and ready to attack, which it would — every, single, time. This was the problem.

The Solution

“I turned to look at what it could be, to see a mockingbird in mid-flight making its target… me!”

As I had said, there was a couple of mockingbirds that had built their nest in a bush next to my garage and were very protective of that nest and of the whole area (i.e. the whole house and yard). Even neighbors walking down the street in front of our house were being harassed by these mockingbirds. My wife and I couldn’t even get to our vehicles before we were terrorized by their avian threats.

So, a plan had to be put to order to deal with the situation. I did have to eventually risk life and limb to reluctantly remove their nest from the bush as swiftly as I could when they weren’t around one morning. I decided though, after the fact, that I wanted to be able to take care of such situations differently for future incidents. The way my mind thought of how to deal with such situations was with a robot.

The first thing that came to mind was the great horned owl. Owls intimidate most birds and the great horned owl, in my opinion, looks like the most bad as… rather, looks like the toughest one around. They’re awesome! But, we don’t get many owls around the house though. I’d have to settle for something artificial, like this great horned owl decoy here.

We’ve all seen those plastic owls that people get, like for outdoor seating areas at restaurants, for example, hanging from the rafters in an attempt to deter birds from nesting under the cover of the deck. Those may work at times, but I needed a sure deal, and a perched plastic owl, frozen in a stare into space was not what I had in mind. I needed something that could intimidate birds, that could not only visually alarm them, but also deter them through movements and sound. I needed something with potential, something that could really intimidate birds.

The idea of the OwlBot was formed and time had come to build one to help deal with such irritations as those mockingbirds. The following part one of this project, and the proceeding parts leading up to the completion of the OwlBot are the exact steps I took to create my own bird intimidator. This would be the solution.

Goal of Part 1 of the OwlBot Project

A motionless, plastic great horned owl deterrent with a staring gaze might not do much over time. For the OwlBot to be effective enough to deter birds from nesting in an area throughout the year requires lifelike actions, like sound and movement. Our goal for part one of the OwlBot project is to first get it to detect motion, and then we’ll move on to the other stuff later, in the proceeding parts of this build series.

  • Motion Sensing: When the OwlBot is complete, we want it to be able to sense motion of a bird or other creatures, and when it does to start making owl hooting sounds, and to perform various movements. We also want it to flash its red eyes as an added effect to help deter pesky animals in the surrounding area. We’ll end up having all these actions done in sync when motion is detected, and we’ll use an HC-SR501 PIR sensor to get the OwlBot to detect such motion.

Before we get started, let’s first briefly discuss about the HC-SR051 PIR sensor we’ll be using for this part of the project, to allow ourselves to know more about it and to get an understanding of how it works.

The HC-SR501 PIR Sensor

We’ll be using the HC-SR501 PIR sensor to get our OwlBot to detect motion. PIR stands for Passive Infrared Sensor. Since the sensor detects infrared, it’ll be able to detect motion from humans, animals, and hopefully smaller animals, like birds for our project’s purpose. The HC-SR501 has three pins; a VCC or power pin, an output signal pin, and a ground pin, as shown in the image below:

The + power pin (VCC) has a wide range of input voltages, anywhere between DC 4V and 12V, although +5V is recommended. The Arduino Uno that we’ll be using can provide the 5V we need to power the PIR sensor.

The output pin is 3.3V TTL logic, so it can be used with any microcontroller platform, such as the Arduino, Raspberry, PIC, ARM, and 8051, to name a few. We’ll be using the Arduino Uno for this project for its robustness, ease of use, low cost, and availability. The output pin will send signals to the Arduino, letting it know when motion is detected.

The ground pin allows for connecting to the ground of the circuit. This is a must.

The jumper wire of the HC-SR501 PIR sensor has two positions that it can be placed in. Position L or Position H:

  • Position L: When the jumper wire is in Position L, it locks the high signal to approximately 2 minutes. This is the position we’ll set for the OwlBot. This means that when motion is detected, it’s set in single-trigger mode, meaning that when something crosses its path and triggers it, it’ll lock itself into the on or high output position for approximately 2 minutes. Any motion does not reset the time.
  • Position H: When the jumper wire is in Position H, this puts the sensor into repeat trigger mode, meaning that when something crosses its path and triggers it, the 2 minute countdown begins. If something crosses its path again within that 2 minute countdown, the timer will restart the countdown over again for 2 minutes. Any motion resets the 2 minute timer.

Looking at the image below, we can see the HC-SR501 PIR sensor at another angle. In this image, we see that there are two potentiometers labeled for the time-delay and sensitivity.

The time-delay knob controls the delay time. The delay time is for when motion is detected how long the sensor stays in the high output (3.3V) or motion detected position. When no motion is detected the sensor stays in the low output (0V), idle or no motion detected position. Turning the knob all the way counter-clockwise decreases the delay to approximately 3 seconds. Turning the knob completely clockwise increases the delay to approximately 5 minutes.

The sensitivity knob controls the sensitivity of the PIR sensor or how easily it can detect infrared based on how far something is away from it. Turning the knob all the way counter-clockwise increases the sensitivity to allow the PIR sensor to detect motion up to approximately 7 meters (approx. 23 feet) away. Turning the knob completely clockwise decreases the sensitivity of the PIR sensor to detect motion up to approximately 3 meters (approx. 10 feet) away.

It’ll be up to you to choose how you set your time-delay and sensitivity knobs. This will be things you’ll have to play around with to get everything to do how you want it to. Next, we’ll briefly go over the Arduino Uno.

The Arduino Uno (ATmega328P)

The Arduino Uno is a development board developed to make prototyping your electronic ideas into reality more easily. It’s simplicity allows for people new to the world of making with electronics create things without needing tons of formal training. This development board is based on the ATmega328P microcontroller, and programming it is easy to do in the Arduino IDE, once you get the hang of the coding rules. You can download the newest release of the Arduino IDE here.

We won’t be doing an in depth setup of the Arduino IDE here, or go over the programming language syntax during this project. If you need to know how to setup your computer for the Arduino IDE, then you can visit the Arduino web-page on how to Download and install the Arduino IDE here. Below, I’ve provided some recommended video content to help you get started using the Arduino:

For part one of the OwlBot project, we’ll be using the Arduino Uno to help control the PIR sensor. In later parts of the OwlBot project, we’ll use the help of the Arduino Uno to control things like an MP3 player to play owl sounds, solenoids for wing movement, flashing red LEDs for eyes, and a DC motor to rotate a propeller.

The Arduino Uno has 14 digital I/O pins, 6 of which can be used as PWM outputs, 6 are analog outputs, a USB connector, a power jack, and other features. Later in part one of this project, there will be an image labeling which pins and features we’ll be using for the OwlBot.

Let’s Be Methodical

I like to be very methodical about things, so we’ll go step-by-step — in detail — on the entire build of this project: the parts we’ll need, why we’re using them, how to connect them, how they work, and more! First, we’ll start with the following parts list:

Parts List

ItemQuantityDescription
Solderless Breadboard1We’ll be using The Ultimate DIY 3220-Point Breadboard for prototyping this project. You can use an 830-point breadboard or some other 3220-point breadboard available to you.
Male-to-Male Jumper WiresVarious Colors and SizesWe’ll use these to make solderless connections to our
components on the breadboard.
Male-to-Female Jumper WiresVarious Colors and SizesWe’ll use these to make connections to header pins of the PCB module boards.
HC-SR501 PIR Sensor1The PIR sensor is what is used to detect infrared motion.
Arduino Uno1We’ll use this microcontroller board to connect the devices we want to control, to make our project come alive!
Male Barrel Jack Adapter with Screw Terminals (5.5mm x 2.1mm)1We’ll use the barrel jack adapter with screw terminals for our power jack for the Arduino.

Tools Used in Project (Optional)

ItemDescription
The Ultimate DIY 3220-Point BreadboardIf you haven’t built your own, go to our page here to do so! Otherwise, you can use another type of 3220-point breadboard or 830-point breadboard.

Prototyping the Circuit

Since we’re only working with motion sensing for part one of prototyping for the OwlBot project, all we need are our parts and optional tools listed above.

Using The Ultimate DIY 3220-Point Breadboard (TUDIY)

Although we’re only starting with a few components for part one of the OwlBot project, for each of the proceeding parts for this build we’ll eventually be adding more and more components and jumper wires during the prototyping process.

I’ll be using The Ultimate DIY 3220-Point Breadboard that I made on a previous project, so that I have plenty of space and portability for this OwlBot project, as well as having the built-in 9V battery power supply to make things much easier during the build process. You can use whatever breadboard you have available to you if you’d like, or if you’re interested in making your own Ultimate DIY 3220-Point Breadboard, you can visit our page here.

DON’T WORRY! Even though I’ll be discussing how to make connections on The Ultimate DIY 3220-Point Breadboard throughout the following prototyping steps, I’ll provide images of how to hook up items on a generic breadboard, so you can still follow along!

From now-on, I’ll refer to The Ultimate DIY 3220-Point Breadboard as “TUDIY” to save me from having to say “The Ultimate DIY 3220-Point Breadboard” every time.

Step 1 – Connecting 9V Power to the Breadboard:

I’ll be using The Ultimate DIY 3220-Point Breadboard or TUDIY for prototyping this project. TUDIY has a built-in 9V battery power supply that we’ll use for our power source during the OwlBot’s prototyping process.

If you did not make your own 3220-point breadboard, you can use any type of breadboard you like and still follow along. If you’re unfamiliar with using a solderless breadboard, then you can check out our page on breadboards here. Let’s take two male-to-male jumper wires, a red one and a black one.

  • Take the red jumper wire and connect a male end of it to the red binding post for the 9V battery power supply of TUDIY.
  • Take the black jumper wire and connect a male end of it to the black binding post for the 9V battery power supply of TUDIY.
  • Next, connect the other male end of the red jumper wire to a positive (+) rail of TUDIY’s main power rail supply at the top section of TUDIY.
  • Now, connect the other male end of the black wire to the negative (-) rail of TUDIY’s main power rail supply at the top section of TUDIY, next to the positive rail you chose for the red jumper wire earlier.

If you’re using a breadboard other than TUDIY, then you won’t be connecting a 9V battery supply to the breadboard. All you’ll need to do is connect a 9V battery snap connector to a 9V battery, for now, as shown in the image below:

Step 2 – Setting up the Arduino for Power:

For the Arduino to get power for our prototype build, we’re going to use a male barrel jack adapter with screw terminals to make connections from the power rail of TUDIY to the Arduino. Let’s grab another pair of male-to-male jumper wires, a red one and a black one, to make connections from the screw terminals of the barrel jack to TUDIY’s 9V power rail we just set up in step 1:

  • Take a male end of the red jumper wire and place it into the + screw terminal of the barrel jack adapter. Now, tighten the screw terminal.
  • Take a male end of the black jumper wire and place it into the – screw terminal of the barrel jack adapter. Now, tighten the screw terminal.
  • Now, take the other male end of the red jumper wire and place it into a point on the positive (+) power rail of our 9V battery power supply we set up in step 1.
  • Next, take the other male end of the black jumper wire and place it into a point on the negative (-) power rail of our 9V battery power supply we set up in step 1.

If you’re using a breadboard other than TUDIY, then all you’ll need to do is connect the wires of the 9V battery snap connector from step 1, to a DC barrel jack adapter with screw terminals, as shown in the image below:

Step 3 – Setting up 5V Power from the Arduino:

Now, let’s take our Arduino Uno and a couple more male-to-male jumper wires, a red one and a black one, to make connections from the Arduino’s 5V power supply and ground to another pair of power rails on the breadboard to get set up for 5V DC power for the modules we’ll be using.

  • Connect the male end of the red jumper wire to the 5V pin of the Arduino Uno. Next, connect the other male end of the same red jumper wire to a point on a positive (+) power rail of a breadboard on TUDIY. In this case, I’ve chosen the far left breadboard on the 3220-point breadboard.
  • Now, connect the male end of the black jumper wire to the GND pin of the Arduino Uno. Next, connect the other male end of the same black jumper wire to a point on the negative (-) power rail on TUDIY, next to the positive power rail we previously chose for the red jumper wire.

If you’re using a breadboard other than TUDIY, then you’ll make your connections from the Arduino’s 5V power and ground to a power distribution rail on your breadboard, as shown in the image below:

Step 4 – Connecting the PIR Sensor:

Next, let’s grab our HC-SR501 PIR sensor and some jumper wires to make connections from the sensor to the breadboard and Arduino. Starting with the HC-SR501, lets grab a few male-to-female jumper wires; a red one, a black one, and a yellow one. Before we connect our jumper wires to the PIR sensor, let’s first remove the Fresnel lens cover from it so we can see the labeling of the pins on the board.

  • Remove the HC-SR501’s Fresnel lens cover, so that we can see the pin labels on the board.
  • Connect the female end of the red jumper wire to the VCC pin of the HC-SR501.
  • Connect the female end of the yellow jumper wire to the OUT pin of the HC-SR501.
  • Connect the female end of the black jumper wire to the GND pin of the HC-SR501.

Now that we have the red, yellow, and black jumper wires connected to the HC-SR501 PIR sensor, we can now connect the male ends of the jumper wires to the 5V power and ground we set up in step 2, and to one of the header sockets of the Arduino Uno.

  • Connect the male end of the red jumper wire to a point on the Arduino’s 5V positive (+) power rail we set up on the breadboard in step 3.
  • Connect the male end of the black jumper wire to a point on the Arduino’s negative (-) power rail we set up on the breadboard in step 3.
  • Connect the male end of the yellow jumper wire to pin 12 of the Arduino.

If you’re using a breadboard other than TUDIY, then you’ll connect the PIR sensor’s VCC or + power pin to the positive (+) rail of the breadboard (this is the 5V supply rail from the Arduino we set up in step 3). You’ll then connect the GND pin of the PIR sensor to the negative (-) rail of the breadboard (this is the ground supply rail from the Arduino we set up in step 3). Then, you’ll connect the OUT pin of the PIR sensor to pin 12 of the Arduino, as shown in the image below:

Programming the Arduino to Sense Motion

Now that we have our prototype circuit set up for motion sensing for the OwlBot, it’s time to create a program in the Arduino IDE to get the Arduino Uno to detect when the PIR sensor senses infrared motion.

In keeping full transparency, I will be using the help of some fantastic people who have offered their knowledge of Arduino freely on the internet, and will be referencing those sources as we continue with this project. As the program evolves, any sources used will be added into the Arduino code comments. It is encouraged that you go check out any person mentioned for yourself.

PIR Sensor Reference: Rachel De Barros (YouTube): “Motion-activated Sound Effects with Arduino, PIR Sensor & MP3 Player

The following is the code we’ll write for the Arduino Uno to accomplish the tasks needed for our OwlBot prototype, so far:

/* ------------------------------------------------------------------------------
 * Project: OwlBot: The Bird Intimidator - Part 1: Motion Sensing
 * Written by: Dustin Hodges (Motbots)
 * Date Created: 10/11/2024
 * Date Last Modified: 12/08/2024
 * Description: This is part one of the OwlBot project and its prototype process. Here, we
 * are starting out getting the OwlBot to sense infrared motion from its surroundings
 * using an HC-SR051 PIR sensor. The following is the code written for an Arduino Uno.
 *
 * Microcontroller Board: Arduino Uno R3
 * IDE Version: Arduino IDE 2.3.4
 * Modules Used: HC-SR501 PIR sensor
 *
 * PIR Sensor Code Reference: Rachel De Barros (YouTube): "Motion-activated Sound Effects with
 * Arduino, PIR Sensor & MP3 Player"
 * ------------------------------------------------------------------------------
 */

#include <SoftwareSerial.h>  // The SoftwareSerial library allows serial communication on
                             // other digital pins of an Arduino board.

/* The follwing is the initial setup of variables for the HC-SR051 PIR sensor. */
const int PIR = 12;          // Signal pin from PIR sensor to pin 12 on Arduino
int motionStatus = LOW;      // Current motion status or signal pin reading (0 = LOW, 1 = HIGH).
                             // Initially set to 0 or LOW.
int pirState = LOW;          // The state of the PIR signal pin (HIGH/LOW). Initially set to LOW.

/* The setup function does all the initial setting up of everything we need. When code is
 compiled and ran, the setup function is only entered into during processing once. */                                    
void setup() {
    // Pin modes
    pinMode(PIR, INPUT);      // Pin 12 on Arduino (signal line from PIR) is set as an input pin.
    
    // Serial setup
    Serial.begin(9600);       // Want to be able to use Serial Monitor for debugging purposes.
    
    delay(2000);              // Delay for two seconds to allow everything to calibrate before
                              // proceeding.
}

/* The loop function is an infinite loop, meaning once the code is compiled and ran, the
 processes of the code will continually run what's within the loop, until the processes are
 stopped, either within the code, or by the user, or by some other act of God. */
void loop() {
    motionStatus = digitalRead(PIR);  // Get the motion status from pin 12 (Is the signal HIGH
                                      // or LOW?)
    
    /* If there's motion detected by the PIR sensor, do what's inside the loop. */
    if(motionStatus == HIGH) {
        // If the pirState is LOW (it's initially set to LOW)
        if(pirState == LOW) {
            Serial.println("Motion has been detected!");  // Print message to serial monitor.
            /* Going to need to change the pirState to HIGH, since motion has been detected. */
            pirState = HIGH;
        }
    }
    /* Else, if no motion has been detected by the PIR sensor, do what's inside here: */
    else {
        // If the pirState is HIGH
        if(pirState == HIGH) {
            Serial.println("No motion detected.");        // Print message to serial monitor.
            /* Going to need to change the pirState to LOW, since no motion has been detected. */
            pirState = LOW;
        }
    }
}

The Program Explained

Referring to the code above, let’s walk through it line-by-line (other than the comments), to understand what’s going on:

Importing the SoftwareSerial Library

#include <SoftwareSerial.h>  // The SoftwareSerial library allows serial communication on
                             // other digital pins of an Arduino board.

We need to import the SoftwareSerial library to use the serial communication on other digital pins of an Arduino board.

Creating and Initializing the Variables

The following is the initial setup of variables for the HC-SR051 PIR sensor:

const int PIR = 12;          // Signal pin from PIR sensor to pin 12 on Arduino

The PIR variable will be associated with the signal pin (output pin) from the PIR sensor to pin 12 on the Arduino Uno.

int motionStatus = LOW;      // Current motion status or signal pin reading (0 = LOW, 1 = HIGH).
                             // Initially set to 0 or LOW.

The motionStatus variable is the current motion status or signal pin reading. The value of 0 is a LOW reading, and the value of 1 is a HIGH reading. The value is initially set to 0 or LOW, meaning initially we don’t want this variable showing the PIR sensor as reading motion right when the code is compiled, ran, and everything is on.

int pirState = LOW;          // The state of the PIR signal pin (HIGH/LOW). Initially set to LOW.

The pirState variable is the state of the PIR sensor signal pin; HIGH or LOW. It is initially set to LOW because we’ve set our motionStatus variable to LOW, initially. We don’t want the pirState telling us, “Hey, motion is detected“, when the motionStatus is initially saying, “There’s no motion right now.

Inside the Setup

In the setup, we’ll initialize the pin mode for the pin we’re using on the Arduino Uno for the PIR sensor module:

pinMode(PIR, INPUT);      // Pin 12 on Arduino (signal line from PIR) is set as an input pin.

The PIR variable was designated as pin 12 on the Arduino (the signal line from the PIR sensor). It is set as an input pin because the Arduino will receive input at pin 12 from the PIR sensor. This input to the Arduino from the PIR sensor is the 3.3V signal the PIR sensor outputs from its output pin when motion is detected.

The following is for our serial setup:

Serial.begin(9600);       // Want to be able to use Serial Monitor for debugging purposes.

We want to be able to use the serial monitor for debugging purposes. Here, it is set at a typical baud rate of 9600.

Next, we want to add a delay:

delay(2000);              // Delay for two seconds to allow everything to calibrate before
                          // proceeding.

We set our delay to 2000 milliseconds or 2 seconds. We set this delay to allow for our PIR sensor, and later, other modules, to settle once things are powered on, so that they’re ready to go.

Inside the Loop

motionStatus = digitalRead(PIR);      // Get the motion status from pin 12 (Is the signal HIGH
                                      // or LOW?)

Get the motion status from pin 12 of the Arduino. Is the signal HIGH or LOW?

/* If there's motion detected by the PIR sensor, do what's inside the loop. */
if(motionStatus == HIGH) {
    // If the pirState is LOW (it's initially set to LOW)
    if(pirState == LOW) {
        Serial.println("Motion has been detected!");  // Print message to serial monitor.
        /* Going to need to change the pirState to HIGH, since motion has been detected. */
        pirState = HIGH;
    }
}

If the motionStatus is HIGH, meaning the sensor detects motion, and the pirState is LOW (remember we initialized the pirState to be LOW), then print to the serial monitor that motion was detected. Then, change the pirState to HIGH, because the motionStatus is telling us that motion was detected, so we need to reflect that on our pirState variable.

/* Else, if no motion has been detected by the PIR sensor, do what's inside here: */
else {
    // If the pirState is HIGH
    if(pirState == HIGH) {
        Serial.println("No motion detected.");        // Print message to serial monitor.
        /* Going to need to change the pirState to LOW, since no motion has been detected. */
        pirState = LOW;
    }
}

Else, if the motionStatus is LOW, meaning no motion is detected, and the pirState is HIGH, then print to the serial monitor that motion is not detected, then reflect that on our pirState variable by setting the pirState to LOW.

Compiling and Uploading the Code to Arduino

Now, that we’ve gone over the program we’re going to use to get the PIR sensor and Arduino to talk to each other, you can either tediously write the code yourself, or just copy-and-paste it into your file on the Arduino IDE. I’ve named my file owlbot_part-1.ino. You can name yours whatever you want.

Copying the Code

The image below shows you how to copy the code above:

Pasting the Code

Once you copy the code above, paste it into your file in the Arduino IDE, then save your file.

Connecting the Arduino Uno to Your Computer

Now that you’ve copied and pasted the code into the IDE, go ahead and connect the Arduino to your computer using its USB cable.

Choosing the Board and Port Under Tools in Arduino IDE

Before we move on to verify the code and upload it to the Arduino, we need to go ahead and choose the board and port for our Arduino under the Tools dropdown menu in the toolbar of the IDE. Before we do this, we must have our USB cable connected to the Arduino Uno and to our computer. Click on Tools, then under the Board selection, choose Arduino AVR Boards, then choose the Arduino Uno as your board. Again, click Tools, then under the Port selection, choose the port that shows up on your computer for your Arduino. The image below shows these steps:

Verifying the Code

Once you’ve copied and pasted the code into your file in the Arduino IDE, it’s now time to verify the code. You verify the code by pressing the check-mark at the top-left corner of the toolbar.

If you were to copy the code as explained above, you may receive an error in the code during verification. Below, I explain how to easily fix this. As an alternative, you can copy the code from our GitHub account for error free code and skip the fixing errors part.

Possible Errors and How to Fix Them

If you copied the code exactly from above without changing it, and pasted it into your file and verified it, you may receive some errors. My errors showed up on lines 23, 24, and 26, as it was copied exactly from above. I believe this error has something to do with the IDE thinking that there’s some stray characters within the code on the lines for the variables that were made. One of the errors I received, in part, looks somewhat like the following: “error: stray ‘\302’ in program

To fix these particular errors, all you need to do is backspace the gaps between the comments and the initialized variables on the lines. Once you do that, save your code and verify again; these errors should be fixed. Once verified, and you have no errors showing, make sure you have your Arduino Uno plugged into your computer to upload the code to it by pressing the upload right-pointing arrow button on the top-left corner of the toolbar in the Arduino IDE. All these processes are shown in the video clip below:

Testing What We’ve Done

At this point, you have your prototype for step one of this project complete and you have completed writing your code for this step of the prototyping process. You’ve also copied the code, verified it, and fixed what errors you may have had after doing so. You’ve then compiled and uploaded the code to the Arduino Uno to see if what you’ve done so far even works! Here are the steps again, to test what you’ve done up to this point in the project:

  1. Prototype the motion sensing circuit of the OwlBot project.
  2. Create the code you’ll use for the Arduino Uno in the Arduino IDE.
  3. Verify the code and fix any errors.
  4. Compile and Upload the code to the Arduino Uno using the provided USB cable that came with your Arduino.
  5. Leave the Arduino connected to your computer once you’re done compiling and uploading the code to the Arduino, because you want to be able to see what’s printed out to the serial monitor on the Arduino IDE (the “Motion has been detected” or “No motion detected” printouts).
  6. Open up the serial monitor in the Arduino IDE. In the video clip below, I’ve highlighted with an orange box what gets printed out to the serial monitor. If nothing is in line of sight of the PIR sensor, then “No motion detected.” gets printed out. If I wave my hand in front of the PIR sensor, then “Motion has been detected!” gets printed out to the serial monitor.

Once you’ve compiled and uploaded your code to the Arduino, and have opened the serial monitor, you may be seeing “No motion detected.” being printed out to the serial monitor. If you start waving your hand in front of the PIR sensor, you should see “Motion has been detected!” printed out to the serial monitor.

If everything is working as it should, then congratulations! You’ve successfully completed the initial step of the OwlBot prototype. Check out the video below to see the full prototyping process, as well as to see this part of the project working!

In step 2 of the OwlBot project, we’re going to be adding an MP3 player module to our circuitry, to allow the OwlBot to be able to let its voice be heard through an MP3 file we’ll download onto the MP3 module. When motion is detected we’ll be able to hear owl hoot sounds! So, stick around for more!

Video Build of the OwlBot: Part 1 – Motion Sensing

Overview

This has been Part 1 of the build for the OwlBot project. At this point, we started prototyping for our OwlBot. We’ve gone over the HC-SR051 PIR sensor and its functionality, and we’ve discussed about the Arduino Uno and how we’re going to use it to control our modules for the OwlBot. We’ve also made connections from the PIR sensor to the breadboard and to the Arduino Uno, and have coded the functionality into the Arduino for our prototype module to detect infrared motion.

What’s Next

Now that we have implemented motion sensing with the help of an HC-SR051 PIR sensor module, the next step in prototyping the OwlBot will be to have the OwlBot make owl sounds when motion is detected. We’ll do this using a DFPlayer Pro Mini MP3 Player, we’ll add it to our prototype circuit, and then add to our code for the Arduino to be able to control the MP3 player sounds when motion is detected by the PIR sensor. All this will be in Part 2 of the OwlBot project!

Click here to go to “How to Make an OwlBot: The Bird Intimidator – Part 2: Making Sounds”, the next step of this project!

Thank you for participating in this project. We hope that you have enjoyed the build thus far. Let us know by giving a comment in the comments section below. Share the link to your friends and family. Let them know how much you’ve enjoyed the process of prototyping the OwlBot!



Newsletter Signup Form

Newsletter Signup Form

Please enable JavaScript in your browser to complete this form.
Name

Leave A Comment