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 

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
     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);
      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) {
        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: 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 ( the book - Karvinen 2011: Make Arduino Bots and Gadgets 

Sunday, 9 February 2014

Building Love-O-Meter by using a temperature sensor

This "Love-O-Meter" is based on the tutorial by Arduino and it comes with the starter kit. It uses a temperature sensor to measure the warmth of your skin and then starts to turn on (or off) the LEDs  indicated by the temperature.

The components
  • Arduino UNO
  • Breadboard
  • Jumper wires
  • LEDs
  • 220 ohm resistors
  • TMP36 temperature sensor

Building the Circuit

At first I ran the "Hello World" for Arduino to make sure the environment would work as expected. Now I could start to connect the jumper wires between Arduino UNO and the breadboard.

As usually I connected the breadboard to power (5V) and to the ground (GND). I inserted the TMP36 on the breadboard so the rounded part of the sensor would face away from Arduino.

I attached 3 LED lights and the resistors and connected them with Arduino. The lights should react to the heat of the finger and if the temperature would get hot enough all the lights would be on and would also tell you if you are a hot lover or not...

The circuit

The result and the code

Everything worked like a charm and my love-o-meter was ready for action. The components worked fine together and I was happy with the result. When I held my finger on the sensor the blue LED turned on and after a while the yellow started to shine too.

  Arduino Starter Kit example
 Project 3  - Love-O-Meter
 This sketch is written to accompany Project 3 in the
 Arduino Starter Kit
 Parts required:
 1 TMP36 temperature sensor 
 3 red LEDs
 3 220 ohm resistors
 Created 13 September 2012
 by Scott Fitzgerald
 This example code is part of the public domain 

// named constant for the pin the sensor is connected to
const int sensorPin = A0;
// room temperature in Celcius
const float baselineTemp = 20.0;

void setup(){
  // open a serial connection to display values
  // set the LED pins as outputs
  // the for() loop saves some extra coding
  for(int pinNumber = 2; pinNumber<5; pinNumber++){
    digitalWrite(pinNumber, LOW);

void loop(){
  // read the value on AnalogIn pin 0 
  // and store it in a variable
  int sensorVal = analogRead(sensorPin);

  // send the 10-bit sensor value out the serial port
  Serial.print("sensor Value: ");

  // convert the ADC reading to voltage
  float voltage = (sensorVal/1024.0) * 5.0;

  // Send the voltage level out the Serial port
  Serial.print(", Volts: ");

  // convert the voltage to temperature in degrees C
  // the sensor changes 10 mV per degree
  // the datasheet says there's a 500 mV offset
  // ((volatge - 500mV) times 100)
  Serial.print(", degrees C: "); 
  float temperature = (voltage - .5) * 100;

  // if the current temperature is lower than the baseline
  // turn off all LEDs
  if(temperature < baselineTemp){
    digitalWrite(2, LOW);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  } // if the temperature rises 2-4 degrees, turn an LED on 
  else if(temperature >= baselineTemp+2 && temperature < baselineTemp+4){
    digitalWrite(2, HIGH);
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
  } // if the temperature rises 4-6 degrees, turn a second LED on  
  else if(temperature >= baselineTemp+4 && temperature < baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
  } // if the temperature rises more than 6 degrees, turn all LEDs on
  else if(temperature >= baselineTemp+6){
    digitalWrite(2, HIGH);
    digitalWrite(3, HIGH);
    digitalWrite(4, HIGH);

Sources , Arduino Projects Book
Based on the prototype course by Tero Karvinen ( the book - Karvinen 2011: Make Arduino Bots and Gadgets 

Sunday, 2 February 2014

Using a button to control the LED light

This time my project was to configure how to build a button that would turn on and off depending if the user is pushing it or not. While holding the button down the LED should stay on until removing the finger.

For this assignment I used the fallowing components:

  • Arduino UNO and USB
  • Jumper wires
  • LED light
  • Breadboard
  • Button
  • 10k ohm resistor

At first I run the "Hello World" for Arduino and made sure that the LED I was using worked properly (read my previous post).

I attached the button in the middle of the breadboard so the legs were touching the both "sides" of it.

Now I started to connect the jumper wires between the Arduino UNO and the breadboard. In order to get it working like in the sample code (Ardoino > Examples > 02.Digital > Button)
I linked the wires with Arduino's 5V (red wire, positive) and ground (black wire, negative) to the equal holes on the very corner of the breadboard (+ and -). I put the white jumper wire to connect the positive circuit to the button and used 10k ohm resister between the same line with grounds wire (violet) and the other leg of the button.

Finally I connected the LED to digital pin 2 and attached the push button with the green wire to Ardoino's pin 2. I ran the code and tested my device successfully. While pressing the button down I was able to keep the light on but when I took my finger away the light turned off immediately.

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

Sunday, 26 January 2014

Getting known with Arduino

This year started with an interesting new course that is all about building a prototype. I have always found robots fascinating and now I have an opportunity to build something with my own hands.

The very first project - traffic light controller

Our first assignment was to build a small project from the following components:
  1. Arduino (UNO) and USB
  2. Jumper wires
  3. Led lights
  4. Breadboard

1. Hello world, can you hear me?

I downloaded the programming environment for Arduino from (My operation system is Windows 8.1). 

Once the software is installed it is necessary to test if the Arduino is responding to it by blinking a light, in other words this is Arduino's way to say "Hello World".
Connect Arduino to your computer with USB and open the programming environment. Choose File > Examples > 01.Basics and run it. If everything is fine Arduino will now blink it's led. Just to be sure I changed the running loop's delay times to see the resorts in action before going any further.

2. Testing the led light

I like to build everything in small steps. Instead of trying to attach all the led lights on the breadboard at once I start with one.

Led has two legs - the shorter one is "negative" and the longer one "positive". This must be remembered when connecting the jumper wires between Arduino and breadboard.

For example I connected one jumper wire on the gnd pin of Arduino and put the other end vertically to the same line where I had attached my negative leg of the led light (GND > J61). After that I connected the other jumper wire between LED light pin 13 and other end vertically to the same row on breadboard where the positive side of the led leg was attached. I ran the Arduine Blink code again and the little miracle happened - the green led light started blinking!

3. The final result

I attached the second led light with the same method as I did the first one but this time I had to connected the ground wire differently. I put it through the the same row where the first (green) led's negative leg was to the second's (yellow) negative leg row. The lights worked but in order to make them some short of traffic light I needed to change the code - When the green light is on the road is free to go for 2 minutes. When the light is off there is still two minutes time to use the road until the users of the "yellow" road are allowed to drive.

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