– Owl-duino

January 2011

My first arduino project: A light-sensitive model owl.

When the lights go down (night), it “comes to life”

I was inspired by a ‘Birdmobile’ model of a ‘Little owl’ which I had constructed over the New Year period.  Such a beautiful thing and very life-like given it’s made only from cut-and-glued printed card.

I wanted to use simple arduino functions and basic electronic components to add some further unexpected characteristics to the Little Owl such as an authentic hooting call, light-sensitivity and flashing eyes.  OK, so the eyes of a real-life owl don’t “flash”, but are the eyes not the owls most appealing feature?

As with learning many new concepts and processes, I realised I would better understand the arduino micro-processor system when applying its potential functionality to my own project, rather than just copying verbatim from an exercise book (which I also did)*

It was frustrating and I tried and tried to make the most simple things happen.  At a point of apparent impasse, I consulted a clever friend of mine who had been using arduino fairly extensively for his PhD thesis and he pointed out where I was going wrong.

Now the Owl-duino lives! …sort of.

–  A light dependant resistor embedded in the owl’s forehead senses when the light levels drop and activates the functions.

–  Bright White LEDs flash behind the translucent eyes made of yellow cellophane ‘Quality Street’ wrappers.

–  A piezo speaker emits a sequence of (rather unconvincing) tones to imitate a “Twit-Twoooooo-oo-oo!”

–  The eyes flash again, triumphantly and this loop continues until the light returns.

I will expand on this by adding electro-mechanical components to add movement such as flapping wings and head movements.  I also like the idea (suggested by my arduino-fixing friend) of adding an RFID tag reader so that the owl can recognise and respond to objects within range e.g. a small yellow chicken toy (containing a tag) could prompt the excited hunter instinct in the owl whereas the presence of a human (perhaps with a tag concealed in a ring) could cause the owl to retreat in caution.

*”Getting Started with Arduino”; Make Projects; ISBN-10: 0596155514

Here is the arduino code:

#define LEFT_EYE 13
#define RIGHT_EYE 8
#define LDR 7
int speakerPin = 9;
int val = 0;
int length = 14; // the number of notes
char notes[] = ” a aCba”; // a space represents a rest
int beats[] = {2,1,1,1,5,1,1,};
int tempo = 100;
///////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
void setup() {
pinMode(LEFT_EYE, OUTPUT);
pinMode(RIGHT_EYE, OUTPUT);
pinMode(LDR, INPUT);
pinMode(speakerPin, OUTPUT);
}
void loop(){
val = digitalRead(LDR);
if (val == LOW) {
//digitalWrite(LEFT_EYE, HIGH);
//digitalWrite(RIGHT_EYE, HIGH);
flash_eyes();
playing();
} else {
digitalWrite(LEFT_EYE, LOW);
digitalWrite(RIGHT_EYE, LOW);
}
}
///////////////////////////////////////////////////////////////////////////////////
/*functions from this point forward */
///////////////////////////////////////////////////////////////////////////////////
void playTone(int tone, int duration) {
for (long i = 0; i < duration * 1000L; i += tone * 2) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void playNote(char note, int duration) {
char names[] = { ‘c’, ‘d’, ‘e’, ‘f’, ‘g’, ‘a’, ‘b’, ‘C’, ‘O’, ‘W’, ‘L’ };
int tones[] = { 1915, 1700, 1519, 1432, 1275, 1136, 1014, 956, 980, 700, 600,};
// play the tone corresponding to the note name
for (int i = 0; i < 8; i++) {
if (names[i] == note) {
playTone(tones[i], duration);
}
}
}
void playing(){
for (int i = 0; i < length; i++) {
if (notes[i] == ‘ ‘) {
delay(beats[i] * tempo); // rest
} else {
playNote(notes[i], beats[i] * tempo);
}
// pause between notes
delay(tempo / 2);
}
}
void flash_eyes(){
digitalWrite(LEFT_EYE, HIGH);
digitalWrite(RIGHT_EYE, HIGH);
delay(50);
digitalWrite(LEFT_EYE, LOW);
digitalWrite(RIGHT_EYE, LOW);
delay(50);
digitalWrite(LEFT_EYE, HIGH);
digitalWrite(RIGHT_EYE, HIGH);
delay(50);
digitalWrite(LEFT_EYE, LOW);
digitalWrite(RIGHT_EYE, LOW);
delay(50);
digitalWrite(LEFT_EYE, HIGH);
digitalWrite(RIGHT_EYE, HIGH);
delay(50);
digitalWrite(LEFT_EYE, LOW);
digitalWrite(RIGHT_EYE, LOW);
delay(50);
}