Interface Hidden dog fence with Arduino

Hello to all,

I've bought an electric dog fence since I want to use it with my mobile robot.

The system I've bought has a transmitter, a buried wire and a receiver with two connector and one led.

Now, when the receiver is near the wire, the led blinks, the receiver beeps and gives pulsed shocked through the connectors.
Pulses and beeps are proportional to the distance from the buried wire.

Surely, the receiver outputs an alternate signal and I'd like to be able to read it with my Arduino: do you think it's possible?

I want to detect the output signal because in this way I can know when my robot is near the area border and if this happens I can make it change direction.

What I have to do to read this signal in Arduino?
Should I have to convert the alternate signal to a DC one? It is possible to check the pulses delay? This can help the robot to know the distance from the wire: pulses increase when distance decrease.

You could use the flashing led as your sensor and read it with a photocell such as this: Mini Photocell - SEN-09088 - SparkFun Electronics or you could read the pulses, although I assume they're not directly readable by the arduino or they'd be ineffective on dogs - what voltage does the device generate?

I think the best idea is to directly read the led output voltage or the buzzer one instead of reading the pulses because I think they should be between 3,3 and 5V at max since LED is very small and so the buzzer.

What do you think about this solution?

Before you do anything else, DISABLE that shock generator, Could be conducive to a lot of things... including a 'bricked' operator. Are the shock and LED blink co-incident ? if so why not 'affix' a photo transistor to the LED in such a manner as to exclude incident light (a small black tube as shield for the photo-transistor and some opaque resin to 'glue it together, or you might use an LDR or 'Light Dependent Resistor' and do something similar with a pullup resistor or pot for a sensitivity adjust. For the resin, generally I use 'sealing wax' because it can be easily chipped off for re-use...
I cannot emphasize how important it is to isolate or better eliminate the "Shock Device"...
Remember The Last Corollary to Murphy's Law... from his Wife, "poor sod", She said, 'He was Ever the Optimist"


Yes, it's the first thing I'll do today since I want to avoid any possible damage and I don't want to get shocked by it! :slight_smile:

About the LED, I think the best idea is to sold wires directly on the LED pins in order to avoid false readings.
It's not a problem to disassembly the collar because I've bought it only to do this thing.

Why do you suggest me to use the photo-transistor? Are you thinking to something in particular?

If you fence is like most then you should grab an AM radio and see if you can pick up the signal from your fence with it. Your owner's manual probably describes this procedure for troubleshooting purposes.

Assuming it is an AM signal then you might be able to build a small receiver, and luckily enough there's another thread discussing this.

Yes, I was. The Photo-transistor provides perfect isolation. You will measure about 2 - 2.5 Volts across the LED when it is on (LED's make fair low voltage zener diodes) and that is a 'digital' grey area, neither a 'high or a low... so either you use an Analog input with the LED or a digital input with the photo-transistor. The digital one is to be preferred as you only want to detect it's state... High or Low. Much easier to interface. The main warning here is to exclude external light, thus my comments about an opaque resin or my fav... sealing wax. Each to what works best for him/her.


The problem is that the LED blinks very fast, does the light sensor has a good timing? :~

I tried to read voltage output from the buzzer and the little led but it's too low, something like 0,3V at maximum.

Then, I realized a diodes rectifier and I connected it to the shock pins (AC side) and I added the LED to the DC side: the LED blinking change as I move closer to the fence.
I tried to measure the DC voltage with a multimeter and it seems to be something like 1,8V with 2,2V peaks even if the receiver battery is almost discarged.

When the receiver approaches to the wire, the number of blinking between each pause increases.
For example, at 1 meter from the wire, I have three blinkings and then a pause; at 30 centimeters, I have nine blinkings with the same pause.
It would be important for me to detect the different time between the blinkings in order to know how close to the wire my robot is.

Can you help me to know how to read this DC voltage with Arduino, please?
Do I have to connect Arduino GND to DC GND side and the analog input to the positive DC side?
(I tried in this way, but analog input changes randomly)

the multimeter is a relatively big load (1MOhm or so)...
the arduino is a very tiny load (appr. 100MOhm)...

maybe u should use a zener diode and a resistor (like here: How to determine sensor is compatible with Arduino UNO? - #9 by system - Sensors - Arduino Forum )...
or a schottky diode from the positive DC side of the rectifier to GND and a schottky diode to +5V...

the LEDs should have about 2V (300mV is not enough for a LED, i think)...

connecting the ground of both circuits (arduino&receiver) is a good idea, i think...

I think you have some things confused. Most good quality DVM's have an input impedance of > 10 megohms. on a good dry day I doubt that the input impedance of ANY Arduino is more than a 100K ohms... or so.

Marcus as to the light blinking frequency, yes I should think that the Uno is good at least up to 5 Khz or so repetition rate... much too fast to be considered anything less than continuous light and the same would be perceived by the animal. One long shock not the graded warnings (more frequent as the dog approaches the fence) that the collar now delivers.
This is still most advantageous as I would think that your circuitry doesn't need warnings but rather sure sensing of the boundaries. Unless you want to 'calibrate' the distance to the edge of the robot's boundaries, for example to be sure of a safe turning radius... or more likely the possibility of 'false' detection of the fence area. For that reason you might make several measurements looking for the difference in pulse spacing to indicate a real event from... perhaps a sprinkler pipe conducting/re-radiating the sensor information (Fence Transmitter). IMO


Unfortunately, I also need warnings since I have to consider the distance between by robot and the fence.
This can help to avoid false readings when the robot is a little far away from the fence and also if I'm able to detect, for example, two zones (one with a high pulse frequency and another with a medium pulse) I can be able to make my robot stay between this two region in order to force it to follow a particular path.

For example, I can do these operation modes:

  • first one: avoid collision with the boundaries; in this case, it needs to detect just a pulse to change direction
  • second one: follow the boundaries to return at home; in this other case, it needs to move between two pulses region.

The problem is: is there any possibility to implement a sketch which can count the pulses frequency in a easy way? If yes i could use it to do the tests.
I'm asking this since I'd like to use a reliable sketch to avoid errors during the readings.

@Docedison: do you think the phototransistor or the photocell or the photodiode is ok to read fast blinkings?

Because i tried to read LED voltage and shock output voltage with no suitable results, so I think the last thing to do is to read values with a phototransistor.

@Docedison: 1. didnt we talk about flashing LEDs? that looks to me like a digital input... and according to the datasheet the atmegas have 100MOhm input pin impedance... IIRC... 2. then my DVMs r not good... :slight_smile:

@marcus: that's unexpected... if u can c a flashing LED, the arduino pin should c HIGH+LOW... u could try a 5KOhm pull-down resistor... but that galvanic separation sounds good, 2... or a self-made EMF-meter (an antenna connected to a digital input pin of the arduino with a 1MOhm (or 10MOhm) pull-down resistor should react different when u approach that hidden fence line...)...

Yes I do for the reasons I stated before... isolation and the ability to get a "Clean" interface... The Arduino is more that fast enough to read pulses that look like continuous light to you or anyone else. Yes the inputs are (Digital) Very high impedance but remember there is a sampling capacitor in the ATMega328 IC analog inputs as long as the input is analog that is true. Unfortunately that capacitor needs to be Charged in order to measure the Analog Voltage... This current is drawn from the input, Therefore it is Not an Infinite Impedance. Electrometer's typically have input impedance's that exceed 100 Meg-ohms, 1Giga ohm to 1 Tera ohm are more in line. Consider the first one... Look up a Gold Leaf Electroscope it is the basis for an electrometer Picture link here courtesy of Wiki <File:Electroscope showing induction.png - Wikipedia). Then go look for an electrometer and look at it's specifications... devices like them are the "front End" of all the early PH meters.. of necessity for probe loading. I have been a technician and later engineer for a long time now (50) years. Remember I have no one here to impress with my knowledge... I just want to help to the best of my ability. There is an article in this Forum about Voltage Followers, Please read it sometime, it might help the next time you need to make a "Sensitive" Voltage Measurement. When I started into electronics there were NO Transistors, some funky Selenium and Germanium diodes... It has been an interesting 50 years...