In the spring every year, we have a group of robins who start making nests around the house. We also have lots of windows in a patio area that when the robins see their reflection they think it’s a rival bird. They attack the windows repeatedly for months. They land on the chairs, railing and poop over everything. They also make a mess on the windows. We tried to cover the windows, place decals over them with some improvement, but now our windows have stuff covering them and ruins the view. So, I got to thinking, what if I take an Arduino, hook up a PIR sensor, add a motor connected to a flag of some sort. When a bird flies into the patio the PIR sensor will detect the bird and then the motor will wave a pomp-pomp and shoo that bird away. I rigged up a prototype in about an hour and IT WORKED!! It automatically scared the birds away, they built their nests in the trees, had babies but no more poop in the patio and chairs and the windows are not smudged! We had a few rains and the electronics got a bit of the weather, so this year I made an enclosure. Let the fun begin!
The Arduino is hooked to a Passive Infrared (PIR) sensor. I set the PIR jumper to auto-reset (Some PIR’s do not have this jumper installed). I adjusted the PIR Pulse duration for just long enough for the Arduino to easily detect the pulse, but short enough so that the system can reset and shoo the next bird away. I used the AdaFruit Motor shield on the Arduino. I used a stepper motor (all stuff I had on hand). When the PIR detects movement, the Arduino drives the stepper in one direction and then the other. Once that sequence finished, I release the motor, I put a delay in the code and then reset the system to start looking for another detection. For grins I also added a three-color LED – I had a few on hand.
- Arduino Uno
- Adafruit Motor Shield V2
- PIR sensor
- Stepper Motor 112090, 5 VDC
- three color LED
- 1/8 steel rod, ~18″ long
- 3 – 1 kOhm resistors
- Connector wires
- 3D Printed Enclosure
- Flashy ribbon for pom-poms
Step 1: The Circuit
I used a 12 VDC wall mount power supply. It was one I had on hand. The Adafruit Motor shield has an input of 6-12 VDC. Make sure it has enough current to drive the motor. There are lots of ways to power this. You could even use battery(s). Depends how many birds you have but you’ll have to do a but of recharging…..
I wired the jack to the Motor Shield terminal block (JP2). The motor Shield has a jumper that connects the power supply input down to the Arduino before the regulator. The Arduino regulated the 12 VDC to 5 VDC and is used for the logic. Above is a small schematic showing how this works.
I wired the PIR to the 5 VDC and GND pins on the motor shield header. I also connected the PIR output to pin 2 (D2). To drive the LED, I wanted to current limit the Arduino outputs using 1 K resistors. The Motor Shield has a prototyping board area for that. I could have soldered the resistors to the LED, but I thought this is cleaner. I wired D3, D4, D5 to these resistors and connected the other side to a soldered-in 3 pin header to the shield proto area (I called it J1). I wired J1 to the anodes (+) side of the LED. J1-1 is Green LED, J1-2 is the Blue LED and J1-3 is the red LED. (Ha – I ran out of blue wire so I used yellow wire). I connected the LED cathode common (-) to GND.
Next, I wired the stepper motor to Port 1. Make sure you check the coloring of your motor wires for the two windings, M1 and M2.
Step 2: PIR Sensor
Imagine this: Let’s say the entire motor animation loop code takes 10 seconds before it returns to the start and then resumes the loop looking for another PIR event. If your PIR pulse is 11 seconds or gets restarted because it’s too short, then the code will return to the start and sample the PIR, but the previous pulse is still active continually seeing a PIR event and will loop forever! How do you say? Remember the pom-poms are waving right in front of the PIR and will trigger another PIR event (and the too long pulse). Yikes!
Step 3: Code Walk-Through
You don’t need “#include “utility/Adafruit_MS_PWMServoDriver.h”. This is if you use PWM servo. I used a stepper motor for greater torque. If you have a beefy servo, at lease that library is called. (NOTE: for some reason my libraries for the PWM driver did not have “…_MS_..” in the filename. I changed the filename and it works)
I created the motor shield object with the default I2C address by adding: Adafruit_MotorShield AFMS = Adafruit_MotorShield(). I only had one shield so I used the default indexing leaving the “()” blank.
I used the Kysan 112090 stepper motor. These are very common and about $12. Whatever one you pick, look up the specs on it. For this motor the specs are:
- Four Wire: ED=M1; GRN=M1; YEL=M2; BLU=M2
- V = 4.2V
- I = 1.5A
- Step = 1.8 deg (step = 360/1.8 = 200 steps per revolution)
I connected my motor to port #1 (M1 and M2) and it has 200 steps so I put (200, 1) into the variables:
Adafruit_StepperMotor *myMotor = AFMS.getStepper(200, 1);
Step 4: Define Pins and Variables
I defined the PIR input (D2), the three color LED output pins (D3, D4, D5). I gave them names: GreenLED, RedLED, BlueLED. I also pre-set the sensorValue to 0, assuming that there is no detection yet so animation doesn’t start once the loop begins.
Step 5: Void Setup()
Step 6: Loop() Function
Step 7: Continuing With the Code and the IF Loop:
Step 8: OK, I Like Das Blinkenlights:
Step 9: Continuing With the Code Within the IF Loop and Make the Motor Move:
I first move the motor forward and backward. Wait a second and do it again. I arbitrarily selected the steps (365 and 226). No real reason for the numbers, I was goofing with different stepper modes and I ended up just leaving those in. See the Adafruit documentation on stepper motors and pick what you like. I picked Double, there are Single, Interleave and Microstep modes as well).
Step 10: Next Part of the Code:
Step 11: Else Loop
And the whole thing starts all over.
Step 12: Enclosure
To keep the elements from frying my electronics I made an enclosure for the whole thing. Internal to the enclosure, I made some mounting tabs for the Arduino/Motor Shield stack. I like to use metal inserts so I can use screws. I could have made the standoffs with a small hole and force a screw into it, but you need to pre-drill so you don’t break them off or split them. There are lots of sites how to do this. Once you do it enough it gets easy.
Step 13: Enclosure Mounting
Read more: Arduino Bird Shoo!