Reducing current leak from interrupt pin - electric fence sensor

Good morning | afternoon | evening

I am attempting to build a LoRa connected device to detect and measure the voltage of an electric fence. The nominal maximum voltage of the fence is 10kV which is delivered in 1Hz pulses of 100µS. I will probably use a voltage divider to step this voltage down to something more palatable for the Arduino. Because analogRead() takes about 100µS per sample I am using a resistor-capacitor circuit to "stretch out" the pulse so the ADC has enough time to measure the voltage. The interrupt pin has the internal pullup enabled and will be taken LOW by the pulse via an NPN transistor.

Because of the "stretched" pulse, the interrupt pin will be taken LOW for a few hundred microseconds. Assuming the pullup resistor is 20kΩ and the pulse length is, lets say, 300µS, then (I assume) a current of 0.0000495mA ( 3.3 V / 20,000 Ω * 0.0003 S ) will leak out of the interrupt pin every second! If I've done my maths right this is 4.3mAh per day, which is significant for a low power system. I have tried to remedy this by using pinMode() in the ISR function to immediately disable the pullup resistor using the plain INPUT mode. The pullup is then re-enabled after a few milliseconds using the INPUT_PULLUP mode in readiness for the next pulse.

My questions:
Am I right in assuming that the current leak prom the interrupt pin will be stymied simply by disabling the pullup? Would a pull-down resistor be more efficient in this case?

Here is a simplified version of the code:

volatile int V;

void setup() {
  // put your setup code here, to run once:
  pinMode(2, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(2), my_ISR, FALLING);


void loop() {
  // put your main code here, to run repeatedly:
  if (V){
    pinMode(2, INPUT_PULLUP); // Re-enable pullup


void my_ISR(){
  pinMode(2, INPUT); // Disable pullup
  V = analogRead(A0);

... and the "work-in-progress" schematic:

Interesting, but I suspect you will need to use special high voltage resistors several inches long to keep the voltage from arcing from one end of the resistor to the other.


Have you tested the voltage divider? It contains a hidden low pass filter. The time constant of a 100M/100nF circuit is extremely long, in the order of a minute. That expresses the charge rate of the capacitor, so it's not going to produce more than a few millivolts after 100us.

Ah! I see, thank you. I think I'll ditch the capacitor and feed the 100 microsecond pulse straight to the ADC. High precission isn't a priority and amplification would be too draining for a low power system.

I haven't built or tested the voltage divider yet - I've been using another Arduino to simulate the 5V pulses (without the 100M resistance! Oops!). There are some inexpensive 1W resistors rated for 10kV available. I intend to connect the divider resistors "inline" and wrap them in a few layers of adhesive heatshrink. Only the 5V tap and ground will enter the enclosure. I really have no idea if this set up will work or not!

Your voltage divider may also pull the voltage down , the current capability electric fences is tiny .
Your device may also use more battery power than the fence circuit . I’d do some sums and tests first .

Thanks Hammy, I will certainly sit down tonight with a calculator. I will be happy if this circuit drops the fence voltage by less than 5%. Precission measurement is not my aim, as long as the readings are consistent then the data will be meaningful.

Regarding the power usage of the device, the ADC reading would only be made every few hundred pulses. But I am not at all sure whether setting the interrupt pin mode from INPUT_PULLUP to INPUT in the ISR would stop any current leak from that pin while it is taken to LOW by the pulse?

While you have that calculator out, have a look at the drain from the resistor current.

When the pull down is active, it draws

3.3 / 20000 = 0.165mA

However the duty cycle is 300us every second,

300 / 1000000 = 0.0003

Consequently the average current drain is

0.165mA * 0.0003 = 0.049uA = 49nA

Resistors don't have mAh, only batteries do. So if you have for example a 1Ah Li-Ion battery, this load would drain the battery in 1Ah/49nA = 20408163 hours or 2329 years.

Maybe you could also look at some of the circuits that are intended to detect pulses from an car engine ignition coil, which can sense a high voltage by a wire wrapped around a spark plug lead.


One of the later circuits here could be interesting: Inductive Spark Plug Wire Tachometer - Signal Transformation Help — Parallax Forums or something in here:

If low power on the Arduino side is also important, you could get it so sleep for X seconds, then wake and wait for a pulse within a say Y seconds timeout period, then transmit a status OK or Bad.

The 1M resistors are "pull downs". But the built-in pull-up resistor doesn't use significant current compared to the processor and other components on the board.

For "extra safety" (for the Arduino, not for you) you might want to add some Schottky "protection" diodes. There are already "small" silicon protection diodes in the chip, but lower-voltage Schottkys will insure any current passes-through the external diodes. (You already have resistors so you can leave-out the series current-limiting resistor shown in the schematics.)

The 1M resistors are "pull downs".

He's talking about D2.