I came up with the
idea of putting them in the bird cage and making them move, using servos. So I duly purchased an excellent Picon Zero
board and some servos from 4tronix. When the board arrived I did some testing to see if my idea worked.
The Picon Zero board and servos are available from 4tronix, links below
Step 1.
I temporarily Blu tacked the crows on top of the servos
and tried the example servotest Python code that was included with the PiCon Zero board library to see how well they moved, well it worked it treat.
Step 2.
I added a PIR sensor so that when it detected movement it
would trigger the movement of the crows, turn the on the glowing red eyes
and annoying crowing noises when you pass in front of the crows.
Step 3.
I finalised the Python code and then set about putting it
into the birdcage I had brought. After
much glueing and cutting of black card I had a finished project.
The completed project
Complete Code Listing
- import piconzero as pz, time
- def sensor_activated():
- return pz.readInput(0)
- def initialise():
- # Setup
- pz.init()
- pz.setOutputConfig(0, 2) # pin 0 servo output
- pz.setOutputConfig(1, 2) # pin 1 servo output
- pz.setOutputConfig(2, 0) # pin 2 digital output
- pz.setInputConfig(0, 0) # pin 0 digital input
- def deactivate_defences(): # Centre servos and turn off relay
- print ("Crows on standby")
- pz.setOutput(0, 90)
- pz.setOutput(1, 90)
- pz.setOutput(2, 0)
- # main loop
- try:
- initialise()
- while True:
- deactivate_defences()
- time.sleep(5) # Avoid rapid retriggering
- while not sensor_activated():
- time.sleep(0.2)
- print("Motion detected")
- pz.setOutput(2, 1)
- pz.setOutput(0, 40)
- pz.setOutput(1, 150)
- time.sleep(5)
- pz.setOutput(0, 150)
- pz.setOutput(1, 40)
- time.sleep(5)
- pz.setOutput(0, 90)
- pz.setOutput(1, 90)
- time.sleep(5)
- finally:
- pz.cleanup()