Monday, 22 October 2018

Crow-O-Matic


While pursuing the Halloween tat in Poundland recently, I saw an empty bird cage.   This gave me an idea, could I reuse the two creepy Halloween crow’s I brought and modified last year.

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


  1. import piconzero as pz, time
  2. def sensor_activated():
  3.     return pz.readInput(0)
  4.    
  5. def initialise():
  6.     # Setup
  7.     pz.init()
  8.     pz.setOutputConfig(0, 2)   # pin 0 servo output  
  9.     pz.setOutputConfig(1, 2)   # pin 1 servo output
  10.     pz.setOutputConfig(2, 0)   # pin 2 digital output
  11.     pz.setInputConfig(0, 0)    # pin 0 digital input
  12. def deactivate_defences():   # Centre servos and turn off relay
  13.     print ("Crows on standby")
  14.     pz.setOutput(0, 90)
  15.     pz.setOutput(1, 90)
  16.     pz.setOutput(2, 0)
  17. # main loop
  18. try:
  19.     initialise()
  20.     while True:
  21.         deactivate_defences()
  22.         time.sleep(5) # Avoid rapid retriggering
  23.         while not sensor_activated():
  24.             time.sleep(0.2)
  25.             print("Motion detected")
  26.             pz.setOutput(2, 1)
  27.             pz.setOutput(0, 40)
  28.             pz.setOutput(1, 150)
  29.             time.sleep(5)
  30.             pz.setOutput(0, 150)
  31.             pz.setOutput(1, 40)
  32.             time.sleep(5)
  33.             pz.setOutput(0, 90)
  34.             pz.setOutput(1, 90)
  35.             time.sleep(5)
  36. finally:
  37.     pz.cleanup()