How to Build Dog Detection Systems with Arduino

If you love technology and dogs like me, then you’ve probably at some point wondered how to combine the two. With Arduino modules becoming ever more affordable and accessible, this blog post gives an account of using Passive Infrared (PIR), ultrasound and Infrared (IR) range sensors with these microcontrolers to enable technology to detect their pet pooch. I call this crazy techno-dog adventure Doguino!

Before setting off on a mad buying rampage, I researched and found that others had similar ideas to me, such as dog food/treat dispensers, dog petters, pet controlled doors and ball launchers. These devices seem to use a number of different sensors, such as potentiometer which allows for variable voltage as a switch, automated devices using gears and shafts based on time sensors (servo device), Radio-frequency Identification tags (RFID) on collars and buttons etc. However, I noticed that none of these devices allowed the senses of the dogs normal activities without training your pup to use buttons or clipping a device to him/her. So instead, I decided to start exploring sensing the dogs normal behaviour as an input device. By using an Ardunio Lenardo my dogs movements could become keyboard commands. These keyboard commands could then trigger videos to be played to my dog allowing my dog to become his very own TV remote. But first I had to detect my pup…

Prefer just to see the code? Skip to the bottom for download links. 

Passive Infrared sensor (PIR)

Firstly I explored using PIR electronic sensors which measured the IR light, often used in motion detection systems. PIR work by detecting temperature, heat energy, in the form of radiation given off, or reflected by, objects. For my Doguino project, I thought maybe I could use two PIRs, one to detect a dogs movement and one to detect an owner. This idea was so that a system would only work if a dog was detected so as not to distract from our play time. The device I chose to use was an HC-SR501 body sensor module (below) which has adjustable sensitivity and output timing (signalling) modules (the orange bits!).

Image result for HC-SR501

As this device has a 110 cone angle range, one of the modules would need to have cones to reduce this range so that two could be used together: one for dog and one for human. The summary of the code (full version can be downloaded below) is that when PIR labelled ‘human’ is triggered that human motion is present, when PIR labelled ‘dog’ is triggered dog motion is present.

Building

pir_dog-e1504299617296.jpg

Whilst testing this device, it was found that often the two PIRs would often not signal at the same time resulting in a series of quick switches between the human and/or dog states. To combat this the system was debounced, which means the dog and/or human had to be detected for a certain period of time. This system was then tested further by building cardboard cones so that the two could sense at different heights – one at low dog height and one at a higher human height to distinguish between the two different motions.

Testing

testing_PIR

This system was then tested with my dog Zack. It was noticed that when my dog was watching the TV device he would often pause whilst watching (not move) which would turn off the device as it made the presumption that without movement the dog was not there. For this reason, the device created as not suitable for DCI with media but could be used in other projects where movement is necessary as an input. Drats – onto ultrasound!

Ultrasound Detection

ultrasoundThe second input method I tried was Ultrasound detection with a 4 meter range. Ultrasound work on sound waves with higher frequency than the upper audible limit of human hearing. For dogs the hearing range is variable on the breed and age, and is thought to be 67 Hz to 40 kHZ but has been argued to be as high as 50 kHz and 45 kHz. Most ultrasonic sensors worked on 40 kHZ, including the one I got hold of (HC-SR04). This means that some dogs may be able to hear this sound.

Building

For this reason, the ultrasound device was tested with my dog first to see if his ears pricked at the sound. As Zack was almost six his hearing had lessened slightly with age and my dog, outwardly, appeared to not react to the device – but I was still precarious. The HC-SR04 device used, has a ranging angle of 15 degrees which was rather small cone comparable to the above PIR. For this reason, the device was placed at, once again, the dog’s body height to achieve maximum refraction from a solid object.

Testing

zack.jpg

Whilst testing this device it was noticed, suspected due to my dogs fur, the device would often present null (nothing detected) even though my dog was there. To combat this, I then set the program to take five readings and average these out to give an average reading, which due to Arduinos fast speed loops (program running the code) was fast enough for real-time detection. This however, was slowed down when the null reading was given to 1 per second which reduced the accuracy of the detection. This was then, once again, tested with my dog.

It was found that even with the averaging of the code, because the program was running so fast the null readings still resulted in a flicker effect (quick on and off change) crashing the program with too fast keyboard commands. This is suspected, as above, due to the dogs’ fur muffling the sound refractions. This could have been reduced by materials that absorb sound like steel and plastic but short of building my dog a reflective vest I did not see this as a plausible solution.

Infrared (IR) Range Detection

Lastly, Infrared (IR) Range Detection was explored to try to sense my dog. I decided to use a Sharp GP2Y0A02YK analog system with a range of 20-150 cm as it had a fixed detector and accurate distance calculations.

Building

I noticed that IR is reduced by a dogs fur retaining heat and thus the IR waves, but I did not think this would be an issue as the PIR sensors (above) had already successfully detected my dog. The only issue I did think might occur is that due to the lack of fresnel lens, the angle of reflection is minimal and smaller that the previous two options – so I doubled up with two sensors!

ir.jpg

Testing

zacktestDuring testing it was found once again, that occasionally the detector would give misfired readings (12% of readings give values with an error up to 42% over actual distance). So as with PIR and Ultrasound, the readings were averaged out, following the guidelines of the last 25 readings with an average of 93 difference. To ensure a fast reaction, in this program no delays, were used. In testing, with this setup worked but due to the small angle of the range finder this meant there was only a precise width that the dog could stand in which was extended by putting the two sensors so that they exactly fit the dogs largest part of his shoulders to give the largest detection area. However, a new problem was now discovered: my dog’s tail! I found that Zack’s wagging tail would result in the dog being quickly detected and then undetected. To fix this I made the Arduino program to maintain detection for a minimum period of time (3 seconds) to mitigate against the quick waggs.

Success! This system worked perfectly allowing the dogs own movements to be translated into keyboard commands as a detection system. However, more importantly a number of guidelines were formed for mine and Zacks  future Doguino adventures.

Guidelines

  • Average Out Results. Within sensing products there is always an element of false readings, as discussed above with debouncing and error readings. To combat this  I would advise Doguino devices which use sensing products to average out the ir readings. There is however, no firm number to average by, as seen here the range is 2 – 25, as the averaging of the readings is dependent on the speed of the reading input (the loop). This averaging out is even more important if the sensing device is to act like a switch which relies on accurate readings.
  • Test first in laboratory settings, then with a test dog: User testing is key! When building Doguino products, it became important to first test the set up in an artificial setting (with myself!). As proven above, this is where a majority of problems in the systems built were spotted. Whilst this does not devalue user testing with a dog, this method ensures that during user testing the system is up to specification.
  • Sensors work best at dogs’ body height. As sensors work by detecting some form of waves (IR, Ultrasound and RF) which either required reflection or omission, the sensors within these projects was found to work best at the height of the body of the dog. This provided the biggest static area.
  • Taking into account the dogs physiology. As Arduino products and projects are often built for humans the dogs physiology needs to be taken into account in Doguino projects. Instances in these projects which affected the design was the dogs fur, hearing and tail waggs.

 

Download Links

Dog detection using PIRs: Arduino or text file format

Dog detection using ultrasonic: Arduino or text file format

Dog detection using IR: Arduino  or text file format

 

Working on any quirky Arduino or technology projects with your dog? I would love to hear from you! 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s