No interrupt on falling voltage

Hi All, I can get an interrupt on a rising voltage but not a falling voltage. The voltage is not floating when low so I don't need the 'pullup' coding. Can anybody suggest perhaps a change to my hardware so that I can use an interrupt on a FALLING voltage.
Here is the hardware circuit which has been tested on a Ltspice simulation.

Do not even think of using that circuit to detect household AC voltage. It is EXTREMELY dangerous, as it is likely you will connect the hot side of the line to circuit ground.

1 Like

@jremington is perfectly correct, in order to use this circuit it needs to be isolated to the mains, maybe with a isolation transformer. Without one it is not legal. Even with one it is highly dangrous because of the voltages involved.

Having said that, your thinking on this is wrong:-

The transistor is used in the open collector mode, so despite what you think you do need a pull up resistor.

If you are making such a fundamental mistake in your thinking then please question if you have the skill to do this project safely.

Perhaps you could tell us what you are trying to do. Are you only simulating or is there a final goal?

From you simulation circuit I see there is no Arduino. An Arduino interrupt can be programmed to trigger on either rise or fall.

No chance of that with the large dropping resistor. The isolation is via the large dropping resistor. How could anybody except a complete idiot make the mistake of connecting the mains to the circuit ground. There is only .7v at the base of the transistor normally until at zero crossing it drops to .5v.

I was bought up on analog electronics before I went digital. You would have been first familiar with digital(software) and very lacking in analog electronics skills. My other forum is ‘all about circuits’ and here the emphasis is more on analog electronics. Never had any criticism about the circuit on this forum.

You are quite wrong there is nothing at all dangerous about the circuit.

But it is connected to circuit ground, via D3. I don't know how the mains is configured in your part of the world, but you seem to be relying on the '-' terminal of your sine wave generator remaining at or around ground potential (the neutral line, here in the UK).

But if you reverse the mains wiring, then negative-going voltages will pull the circuit ground negative via D3. Then you can get a shock if you touch the circuit ground. Remember, the current from the live wire of the mains doesn't have to travel back along the neutral via the 220k resistor - it can go back via the earth. So yes, it is dangerous.

Or at least, that's how I see it. Am I wrong?

I can only get the interrupt to trigger on an rising pulse. Interrupt not working on a falling pulse. I think I now know why. In the case of the rising pulse a low exists for about 9ms before a high spike of 84us length. To work on a falling pulse you would want a high for 9ms and then a low going pulse. Arduino is not fast enough to pick out the falling pulse in a spike of only 84us.

I think this is where you would install a diac between the bridge rectifier and Q1 base, in order to prolong the off period of Q1.

As I said to someone else why would you want to stick your fingers on the circuit while it is working. The circuit works great but obviously don’t go sticking your fingers on to it. Why would you want to?

But presumably your circuit is connected to other stuff - including an Arduino. That might have a display, keypad, or whatever. You might even be tempted to plug it into your PC whilst you are updating the software.

"Live chassis" devices were used in the past, but they had to comply with various rules about double insulation, and so on. Personally I'd be looking at using opto-isolation after the bridge rectifier. Or better, a transformer to isolate and step down in one convenient step.

All we can do is give advice on this forum - I would just ask that you consider it carefully.

Use an optocoupler e.g. microcontroller - How to drive optoisolator from Mains - Electrical Engineering Stack Exchange

Quite clearly you do not understand what isolation means. This is total rubbish. Isolation is NOT protection which is all a dropping resistor provides.

I too started with analogue electronics back in the 1960s. And as I said this would be an illegal circuit in the UK and EU and the US.

The lack of criticism may be because all the people who followed your advice are dead.

1 Like

Absolutely a very real and life-threatening chance (electrocution and fire). Standard resistors are not mains-rated at all, or anything like. Perhaps you should learn about insulation classes, creepage and clearance distances, high voltage resistors, fusible resistors & component failure modes, flashover, and the actual peak voltage transients you get on the mains (measured in kilovolts).

BTW 240V/220k ~ 1mA, which is definitely a noticable shock that might make you jump or drop something - not good.

1 Like
  1. Your circuit may be dangerous.
  2. If you can get interrupt on rising edge you must be able to get interrupt on falling edge as well - there is a bug in your (hidden) code.
  3. 84 us is plenty of time. Arduino should be able to catch a pulse longer than 1 CK (so even 84 ns should be possible).
  4. A single resistor(*) is all that is needed for ZC detection if you are not afraid of mains voltage.
    AVR182 Zero Cross Detector.pdf (229.7 KB)

EDIT (*) the "single resistor" should be 2 or 3 physical resistors in series for safety reasons.

You are quite correct, as long as it remains a simulation only.

Welcome to my ignore list!

I prefer my much simpler circuit which works ok in Arduino for a rising voltage interrupt. If some of the people on this forum are concerned about electric shock when using a mains voltage there is a device that can be fitted to the mains input of the house that prevents this. Get this fitted by an electrician. Its expensive.

Where do you get this rubbish from?

I am always using a random phase triac opto to fire a triac. Plenty of isolation there for those concerned with isolation. At some point you have to bring in your mains if you are going to control mains operated devices. If you are concerned about electrocution you had better stay clear of working with it.

Don’t need it.