Arduino electric fence

Dear Arduinoers,
My electric fence unit broke down yesterday and tomorrow I'm getting two pigs. I could just but a new unit, but where's the fun in that? Then I thought I'd try something with my brand new Arduino. Being a noob in this (and many other areas) I wish to get some comments on the build before I start destroying stuff...

Basically, I'm thinking of pulsing a digital pin out for like 10ms followed by a delay for like 1000ms. The pulse will trigger the transistor, which will turn on the relay and then send a pulse to an ignition coil. Please see the attached image for details.

I've only got limited electronics skills, but what I've seen from DIY fencer circuits is that people put in capacitors between +12V and ground or over the primary coil, but I really don't know why. Is that something I should do? And why? See for example:

http://danyk.cz/ohrad_en.html

Thanks for any help or suggestions!
Finnvreten

The capacitor improves the pulse generated in the transformer primary and reduces arcing across the relay contacts. You definitely want one.

If you only want to produce a brief pulse at regular intervals, a couple of hardware timers would be a far easier and cheaper way to do it. This is not a problem that calls for a microcontroller.

Dear Peter,
You're surely correct in that it's probably cheaper with hardware timers. Problem is I don't have them at home right now and don't know how to go about designing such a circuit. The Arduino on the other hand is sitting on my bench and is just waiting and wanting to be used - maybe until I find myself a couple of timers and learn how to use them.

Regarding the cap, I should probably include one over the primary coil then. Does it matter greatly what capacitance? 220 u or 330u?

I'm not sure what capacity you need. They are probably very small capacity (a typical automotive condenser is a fraction of a uF) but will need to have a very high voltage rating because the EMF spike induced on the primary will be much higher than the nominal supply voltage. Also note that they need to be bipolar since the coil primary will oscillate when the points open. I suggest you just take a trip to your local car parts outlet and ask for an ignition condenser and hope that it has a high enough voltage rating for your fence - it will probably be OK. It would also be worth checking what's in the old driver module since it's possible that the capacitor is still usable (and it's also possible you could fix the whole thing just by replacing a blown transistor or replacing a fuse).

There's nothing wrong with doing things for the sake of it if that's what you want, but IMO the best projects to learn how to use an Arduino are ones for which an Arduino is a sensible solution - and this isn't one.

I could just but a new unit, but where's the fun in that?

Well for the pigs welfare, a reliable unit is best. If the fence fails and the pigs get out then they might get lost, hit in traffic, or become prey for dogs and other predators.

Zoomkat: Your concern about the pigs' welfare is duly noticed. There would not be any sense in using a circuit that was not properly tested. This is however (at least according to me) a given. After thorough testing, I don't see how this robust-looking circuit would fare less well or less securely compared to store-bought ones. After all, I've had both store-bought ones - as well as home-made ones going belly-up on me...

Peter: Your opinion about what constitutes a "good" Arduino project is also noticed. I happen to disagree. I believe a good project happens to be one for which there is the joy of learning and fun in doing, which causes incentive to actually and actively DO. Or I could just say sensible schmensible :wink: Let's just agree to disagree on this one.

Anyhow, with an added 220uF/35V cap over the primary coil, the circuit works like a charm. There's a definite "bite" when touching the wire. Especially when removing footwear!

I didn't add a cap according to your suggestion. Maybe there will be a price to pay for it, but 2.5 days (so far) running around the clock seems to be working just fine.

Update:

Just hours after the last post, the cap broke down. Lol. There really was a price to pay. It was replaced with a new one with 250V rating and now it really works. Only goes to show that thorough testing before putting into practice is fundamental. Which was by the way exactly what was done :slight_smile:

After having the new fencer on for a week and teaching the pigs how the fence works - indoors with no chance of escape! - they were led to an outdoor pasture surrounded by an electric fence powered by the fencer unit and live a happy outdoor life.

The link you gave:
http://danyk.cz/ohrad_en.html

Shows a 220nF capacitor. May I ask why you are using a 220uF capacitor, 1000 times as large? That is going to tend to wear your relay contacts away. The 220nF capacitor is supposed to resonate with the primary winding, 220uF is far too large. It also needs to be a nonpolar capacitor.

The pictures show a conventional old school car ignition coil, so the corresponding car ignition condenser would certainly be compatible with it. They aren't expensive or hard to get and should be very durable in this application. It doesn't strike me as sensible to compromise the solution just for the same of a cheap component like this.

Hi, I hope you realise that there are some standards in place that define the performance of an electric fence unit.
They are defined to protect the body and the environment from possible fires.
The old method of using a car ignition coil is not the way to do it, there are energy and voltage limits to adhere too.

Please check in your country if there are standards as well, car ignition coil is a very bad idea and can be lethal.

Tom...... :slight_smile:

PS An electric fence spec as per standards.
(Standards for electric fences needed in Australia to help prevent death and bush fires.)
http://www.thunderbird.net.au/pdf/instructions/universal_energiser_instruction_booklet.pdf