-1

I am in grade 6. I have a very nice pet dog in my house but it often enters Mom's kitchen to spoil all the foods. So I am thinking of a device to attach with him which can locate its position. But I am totally new to arduino programming. I have found some tutorials of arduino UNO to locate position with GPS. But I don't know how to set up the alarm when my dog reaches the position of our kitchen and what will be the code for it. If I wanna set alarm for different position, like kitchen and two toilets, what would be the code then? I know Java a very little bit. C too. Nothing else. Is there any altruist to help me out, please?

2 Answers 2

2

First things first: do you know that a GPS can locate your dog accurately enough in your home?

Basically, even with a good GPS receiver, the best accuracy you can expect (using off-the-shelf receivers, non-military or DGPS) is maybe 3 m. Typical performance is maybe 4 m, and indoors it will be even worse. The point is, your dog could be 5 m away from your intended location, and you will get an alarm. 5 m in a house might be the room over, two rooms over, or outside the house!

However, if you want to go forward with this, get yourself a GPS module, connect it to your Arduino, install the TinyGPS++ library (one of the better Arduino GPS libs IMO), and play with it. It's easy to figure out how to perform an action when the GPS coordinates are in range of a given coordinate set.

You might have better luck using a different form of dog location detection.

1
  • FYI, you might be interested in my library, NeoGPS. It's smaller and faster, the examples are more robust, and the docs (hopefully) help new users avoid the many pitfalls in the TinyGPS examples.
    – slash-dev
    Jun 10, 2016 at 0:45
2

A more low-tech solution might be better. For example, a couple of light beams across the doorway to the kitchen. An human would block both of them as they passed, and a dog only the lower one. You could sound an alarm if the lower one is broken, and the upper one is not broken (within a second).


Or do something with infra-red transmitters / receivers. There are lots of Arduino projects using those. You could have a transmitter in the kitchen pointing towards the doorway, sending some code (eg. 1234). Mount on the dog an Arduino with an IR decoder sketch. When the dog enters the kitchen it will get the code, and then you could sound a beeper. The beeper alone might make the dog change its mind about going in, especially if you go after it yelling "bad dog!" every time the beeper goes off.

Since the IR beam is just light, it would only go in a straight line, and if properly positioned would flood the kitchen, but not hit anywhere else.


Proof of concept

I made up a test of my idea of the IR transmitter.

(Please don't report me to the moderators for being off-topic. I know the question was about a GPS, but the real question is how to detect that the dog has come into the kitchen).

You can get IR (infra-red) LEDs cheaply at any electronics supplier (or eBay). They are like normal LEDs except that they transmit in the IR light range. They can also usually handle higher currents, like 80 mA.


Sender

So, to drive that from the Arduino we need a transistor to boost the output from the Arduino pin, like this:

IR driver

Note that the positive pin of the LED will have a longer lead. The positive pin goes to the 39 ohm resistor, and the negative (shorter) lead goes to the transistor collector. In the schematic the negative pin (cathode) is at the bottom and has a horizontal line (think of the horizontal line as a minus sign).

The 39 ohm resistor limits current through the LED to 74 mA. Assuming a LED forward voltage of 2.1V we have:

 (5V - 2.1V) / 39Ω = 74 mA

The 470 ohm resistor limits current through the transistor base.


Sender code

Then some simple code to send a IR code (using PWM modulation like TV remotes do). There is a library for that, so the code is very simple:

#include <IRLib.h>

IRsend My_Sender;

const unsigned long DOG_ALERT_CODE = 0xBADA;

void setup()
  {
  }

void loop() 
  {
  My_Sender.send (NEC, DOG_ALERT_CODE, 20); 
  delay (1000);
  }

That sends the code 0xBADA (which I just picked at random) every second using the NEC IR protocol.

The objective would be to have this plugged into the power somewhere in the kitchen, and aimed at the doorway. The IR library uses digital pin 3 (on the Uno at least). That happens to be the Timer 2 "B" output to send 38 kHz PWM (pulse-width-modulated) signal, which it interrupts from time to time to encode the code into it.


Receiver

Now we need something on the dog to detect the IR code. The objective is to notice the code above (eg. 0xBADA) and if found, sound a tone on a speaker, otherwise ignore it. That way we can still use remotes in the kitchen, and the speaker won't sound.

IR Receiver

The code for the receiver is a bit more complex, but not much:

#include <IRLib.h>
#include <TonePlayer.h>

const byte SPEAKER = 9;  // output pin is fixed (OC1A)
const byte IR_READER = 11;
const unsigned long BEEP_WIDTH = 50;
const int BEEP_FREQUENCY = 880;  // Hz
const unsigned long DOG_ALERT_CODE = 0xBADA;

// pin D9 (Uno), D11 (Mega)
TonePlayer tone1 (TCCR1A, TCCR1B, OCR1AH, OCR1AL, TCNT1H, TCNT1L);  

IRrecv My_Receiver(IR_READER); 
IRdecode My_Decoder;

void setup()
  {
  My_Receiver.enableIRIn(); // Start the receiver
  pinMode (SPEAKER, OUTPUT);  
  }

unsigned long lastTone;

void loop()
  {
  if (My_Receiver.GetResults(&My_Decoder)) 
    {
    My_Decoder.decode();
    if (My_Decoder.decode_type == NEC)
      {
      if (My_Decoder.value == DOG_ALERT_CODE)
        {
        tone1.tone (BEEP_FREQUENCY);
        lastTone = millis ();
        }  // end of wanted code
      }  // end of NEC type
      My_Receiver.resume();
    }  // end of if we got a result

    // if time up, stop the beep
    if (millis () - lastTone >= BEEP_WIDTH)
      tone1.noTone ();

  } // end of loop

This also uses the IR library, this time to detect an incoming code. You wire the "Data" pin of the IR detector to digital pin 11 on the Arduino (Uno or similar). The other two pins of the IR detector go to Ground and +5V as marked.

To play a sound get a small piezo speaker and wire that to digital pin 9 (one side) and Ground (other side).

Because of the way that the IR library uses interrupts, I had to use my own Tone library to generate a tone. You can download that from:

http://www.gammon.com.au/Arduino/TonePlayer.zip


Testing

How well did it work? Certainly at short distances (like three feet or one metre) we got a positive result. There could be variance based on the light conditions in the room, and the exact parts you get.

You might want to read the design notes for TV B Gone where they discuss the technicalities of sending IR beams. In particular for their design they used four IR LEDs to give adequate range. You could add more LEDs by duplicating the transistor driver shown above a few times. In other words, duplicate the transistors, LEDs and resistors. They could all be driven from the same output pin.

As mentioned in the TV B Gone article, you can get different IR LEDs. Some have a narrow beam, but go further, others have a wider beam, but go less far.

Also you could arrange them to point in slightly different directions to cover more of the room.

You could also change the length of the beep when the code is detected (BEEP_WIDTH) in milliseconds. And also the frequency (BEEP_FREQUENCY) which I had at 880 Hz. A higher frequency might annoy the dog more but be less audible to humans. I suppose it depends if you want the dog to hear it or the people in the house.


Hardware size and power

You probably want a small Arduino (like a Nano) which is physically quite small. Also powering it could be an issue. You could get 3 x AA batteries, which would nominally output around 4.5V, and connect them directly to the +5V pin of the Arduino.

To save battery power you could have the Arduino sleep for (say) a second, wake and eheck for a code, and then sleep again. See my post about power savings for more details about that sort of thing.


Hardware photos

IR Transmitter and receiver

Piezo speaker

2
  • I needed the GPS coding but thank you for it. Could you help me with the GPS coding and how to set up the buzzer?
    – user74219
    Jun 10, 2016 at 5:33
  • There are many posts by people who have connected a GPS to an Arduino. Asking to "provide code" goes beyond the scope of this site. We are here to answer questions, and be helpful as much as we can. Writing code from scratch isn't really our purpose. If you find code and have trouble getting it to work, by all means ask about that. I would find something that gets the current position, work out what that position is, for the kitchen, and then detect if you are in the kitchen or not.
    – Nick Gammon
    Jun 10, 2016 at 6:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.