Monday, 17 March 2014

From sketch to reality


Sid the garden protector


This project is a part of my university's prototype course. Please read my earlier posts about the topic:
Project plan: the garden protector and Building the prototype.

The components:
Piezo speaker, alligator clips, PIR motion sensor, servo, Arduino UNO, breadboard, 2 x yellow leds-

PIR motion sensor connected.
I built this project step by step. At first I wanted to make sure that all the components work individually before putting them work together. 

 


Why there is just one wing you may ask. The answer simple - I have hunting dogs who love feathers and they got poor Sid in their mouth. The wings were destroyed and so was the other Servo... Sid also lost half of his feathers. But at least he survived.

The circuit


The code

Originally I had a problem to get all these three actions to work at the same time (blinking of LED lights, alarm sound, flapping of wings.) The solution was rather simple though, I just changed the values of the delay codes and got it work smoothly.

This code is based on PIR Sensor Arduino Alarm tutorial and Arduino's own examples of blinking lights and rotation of Servo.

#include <Servo.h> 

Servo myservo;  // creating a servo object 

int ledPin = 13;          // Led is placed to the pin 13.
int inputPin = 7;         // Another led places in the pin 7.
int pirState = LOW;       // we start, assuming no motion detected
int val = 0;              // variable for reading the pin status
int pinSpeaker = 10;      //Set up a speaker on a PWM pin.
int pos = 0;              // variable to store the servo position 

void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(inputPin, INPUT);     // declare sensor as input
  pinMode(pinSpeaker, OUTPUT);
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object 
  Serial.begin(9600);
}

void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    digitalWrite(ledPin, HIGH);  // turn LED ON
  delay(100);               // wait for a second
  
  digitalWrite(ledPin, LOW);    // turn the LED off by making the voltage LOW
  delay(100);                   // wait for a second
    playTone(300, 160);         // play the alarm
    delay(15);
    
     for(pos = 0; pos < 180; pos += 1)  // goes from 0 degrees to 180 degrees 
  {                       // in steps of 1 degree 
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(1);                       // waits 1ms for the servo to reach the position 
  } 
  for(pos = 180; pos>=1; pos-=1)     // goes from 180 degrees to 0 degrees 
  {                                
    myservo.write(pos);              // tell servo to go to position in variable 'pos' 
    delay(1);                       // waits 1ms for the servo to reach the position 
  } 

    //for the serial monitor
    if (pirState == LOW) {
      // we have just turned on
      Serial.println("Motion detected!");
      // We only want to print on the output change, not state
      pirState = HIGH;
    }
  } else {
      digitalWrite(ledPin, LOW); // turn LED OFF
      playTone(0, 0);
      delay(300);    
      if (pirState == HIGH){
      // we have just turned of
      Serial.println("Motion ended!");
      // We only want to print on the output change, not state
      pirState = LOW;
    }
  }
}
// duration in mSecs, frequency in hertz
void playTone(long duration, int freq) {
    duration *= 1000;
    int period = (1.0 / freq) * 1000000;
    long elapsed_time = 0;
    while (elapsed_time < duration) {
        digitalWrite(pinSpeaker,HIGH);
        delayMicroseconds(period / 2);
        digitalWrite(pinSpeaker, LOW);
        delayMicroseconds(period / 2);
        elapsed_time += (period);
    }
}

The result



Based on the prototype course by Tero Karvinen and the book Karvinen 2011: Make Arduino Bots and Gadgets. 
Sources: http://makezine.com/projects/pir-sensor-arduino-alarm/ and Arduino's own example codes.

Building the prototype

This prototype project grew up to be extreme personal to me. Rather than using a pre-made model or a plush I wanted to build it from scratch.

And what are little owls made of? Plastic, glue, tape and feathers!


First things first. The garden protector (named Sid) needs it's shape. I started by cutting the bottom away from a white bucket and glued the shreds of dog's e-collar all around it. Then I started to bend them together to reach the roundness of the crow and used tape to keep it together.


When the form was finished it was time to think about the position of the eyes and wings. I made the holes with the help of a drilling machine and scissors. At this point I needed to take some measurements so the servos could easily move the wings.

Need some eyes?
Sid and his unnamed cyclops brother to whom I tested the drill.
Almost done! But the owl is not really complete without a nice layer or feathers or two. The black beak is made of plastic.

After 4 hours the shell was done. It would be time to power up my gear and wake him up...

Notifications and improvement ideas

Since Sid the owl is a prototype it is not suitable for the outdoor use. The final product don't contain real feathers but plastic. You can also scroll the head off and it is waterproof. 


Based on the prototype course by Tero Karvinen and the book Karvinen 2011: Make Arduino Bots and Gadgets.

Sunday, 2 March 2014

Project plan: The Garden protector


The idea

I wanted to make something funny but useful as my project in our prototype course; so it came up with the idea of a "garden protector."

The basic idea is to keep all the birds and animals (and people) away from your harvest. When the garden protector detects these unauthorized persons it starts to flap it's mighty wings, sounds a fierce voice and it's large eyes will blink red. If this is not enough to shoo the intruders away I am not sure what is!

I will build this prototype (Snowy the Owl) mostly from old plastic candy boxes. The feathers will be also plastic, or real feathers, or the combination of both. I could enlarge this owl-serie with different kind of owl species.

The components

  • Arduino UNO
  • Breadboard
  • Jumper wires
  • LEDs
  • Resistors
  • 2 x Servo
  • Motion sensor
  • Piezo Speaker
  • Battery


Based on the prototype course by Tero Karvinen (http://terokarvinen.com/and the book - Karvinen 2011: Make Arduino Bots and Gadgets