Arduino not picking up falling voltage

Status
Not open for further replies.

Thread Starter

denison

Joined Oct 13, 2018
328
Hi All, I am trying to use Arduino interrupts to pick up a falling voltage. It is working ok to pick up a rising voltage. Cannot get it to work with a falling voltage. Here is my hardware circuit which I have posted before. It is much simpler than other designs I have seen. I have a positive zero voltage(not floating). In the Ltspice simulation the voltage goes to nearly 5v at zero crossing of the mains voltage and the rest of the time the output voltage is close to zero. Can't see why Arduino not picking up the falling voltage. Something wrong with the circuit perhaps?
1638851356903.png
 

DickCappels

Joined Aug 21, 2008
10,169
In real life, this circuit would probably be dangerous and probably would not work. Consider that both of the AC lines (one Neutral and one Line?) are alternately connected to "ground" and the base of the transistor. You should probably use an optical isolator like most of us use.

Does your BC337 ever turn off? You may need a resistor from the base to the emitter. I would take care of optical isolation first since not being isolated is dangerous for you and your electronics.
 

ericgibbs

Joined Jan 29, 2010
18,841
hi den,
Post your LTS asc file, we can then compare.

As Dick points out, this type of non isolated supply is potentially lethal.

E
 

Thread Starter

denison

Joined Oct 13, 2018
328
In real life, this circuit would probably be dangerous and probably would not work. Consider that both of the AC lines (one Neutral and one Line?) are alternately connected to "ground" and the base of the transistor. You should probably use an optical isolator like most of us use.

Does your BC337 ever turn off? You may need a resistor from the base to the emitter. I would take care of optical isolation first since not being isolated is dangerous for you and your electronics.
Not dangerous at all unless you are sticking your fingers on various parts of the circuit while it is operating. But why would you want to do that. The transistor is connecting to ground for approx 10ms.
The circuit works very well in Arduino for picking up an interrupt on a high going pulse.
The bc337 turns off at zero crossing of the mains voltage thus sending a high pulse to arduino for an interrupt program or ISR. Interrupt service routine they call it.
You don't need the resistor at the base of the transistor.
 

DickCappels

Joined Aug 21, 2008
10,169
I am only intersted in your safety. What does the ground symbol in your schematic represent? In real life some AC systems have one of the power lines grounded somewhere and it is referred to as "Neutral". Some places you just get ungrounded two two wire 220 VAC (or so I have been told). In any case, neither Line (one or both) nor Neutral should be connected to ground. All too often the Line and Neutral wires are reversed. Do you see what I am concerned about?
 

ScottWang

Joined Aug 23, 2012
7,398
We do not encurrage to use this kind of curcuit, but if you need to use it then please don't forget to insert the fuse, whatever you put it in the AC side or the pulse DC side.

When the input resistor R1(220K) because any reason to causes it shorted and then the transistor, the 5V circuit and your Arduino will all damages, it also could be feedback to the 330Vac side, so danger is there.
 

Reloadron

Joined Jan 15, 2015
7,515
There is a very good selection of opto couplers available for doing what you want to do. The Optocoupler, Phototransistor Output, AC Input, Low Input Current SFH628A, SFH6286 come to mind but there are plenty more.

Opto Coupler AC 1.png

This affords you a nice high level of isolation between your mains power and your uC. The mains power isolation makes AC Opto Coupling for uC controllers a good choice for detecting mains power loss.

Ron
 

djsfantasi

Joined Apr 11, 2010
9,160
Way back, SamR commented that it was likely the code. But we have yet seen that code.

I’d like a chance to look at your code. I’d also want to know what Arduino is being used and which Interrupt pin is connected to the TS’ circuit?
 

Thread Starter

denison

Joined Oct 13, 2018
328
This circuit I have previously posted was called dangerous and illegal from some on this forum. Here is the circuit;
1639041275018.png
If this is dangerous and illegal here is a circuit to trigger a triac from the book "power electronics" by noted engineer B.W.Williams.
1639041645791.png
Note the ground in the low voltage circuit connected to the neutral of the mains power supply. Then according to those who consider the first circuit (zero voltage crossing detector) dangerous and illegal because of no isolation then this circuit by a noted engineer is also dangerous and illegal.
 

ericgibbs

Joined Jan 29, 2010
18,841
Hi den,
Whose post says the circuit is illegal.?

I would repeat: this type of non isolated supply is potentially lethal.

E

As a footnote you say: Note the ground in the low voltage circuit connected to the neutral of the mains power supply.

Can you guarantee that the mains connection is always the 'correct' polarity to ensure that the 0V is connected to Neutral.?
 

DickCappels

Joined Aug 21, 2008
10,169
First of all, I am greatly relieved to learn that you do not intent to return current from Line through the ground conductor.

To ericgibbs' post above, there is often a voltage drop on neutral lines. This might cause a problem or a failure at the interface between the circuit referenced to neutral and your Arduino or computer, provided the socket is properly wired (some aren't).

There are some easy techniques that minimize the dangers involved in working from the AC Line. @Reloadron show one of the better zero crossing detector circuits I've seen in his post #9 in this thread. I recommend his circuit, though you can do well using on of many other optical isolators. If you send me your postal address by private message I will mail a couple different types to you to try out.

As they say, "Keep one hand in your back pocket.", be safe and have fun with your projects.
 

Thread Starter

denison

Joined Oct 13, 2018
328
I am only intersted in your safety. What does the ground symbol in your schematic represent? In real life some AC systems have one of the power lines grounded somewhere and it is referred to as "Neutral". Some places you just get ungrounded two two wire 220 VAC (or so I have been told). In any case, neither Line (one or both) nor Neutral should be connected to ground. All too often the Line and Neutral wires are reversed. Do you see what I am concerned about?
The circuit posted is from the book "power electronics" by B.W. Williams. He is Professor of electrical engineering at a university in Edinburgh,Scotland. The book is a reference for students of electrical engineering. Do you think he is going to include dangerous circuits in his book that students are going to build?
 

ronsimpson

Joined Oct 7, 2019
3,037
Do you think he is going to include dangerous circuits in his book that students are going to build?
Yes
We see examples all the time where the Professor draws some thing on the board and students come here asking why they can not make it work.

It is one thing to sit in a class room and teach. It is another to build this stuff for a life time. Look at the experienced advice offered here. Probably 200 years of sparks. As stated before Line and Neutral get mixed up and will blow up your project. Neutral is not really at "0V". It might be but probably not. Could easy be at 3V.

Build any way you want. We are just saying be careful. It will not work everywhere but it will work for you in your house.
 

Reloadron

Joined Jan 15, 2015
7,515
The circuit posted is from the book "power electronics" by B.W. Williams. He is Professor of electrical engineering at a university in Edinburgh,Scotland. The book is a reference for students of electrical engineering. Do you think he is going to include dangerous circuits in his book that students are going to build?
Nobody is saying your original circuit is illegal or going to kill you instantly ruining your whole day. What is being pointed out is that circuits like this have no true isolation from your mains voltage this is why they are not suggested to young or inexperienced electronics enthusiast.. It's about isolation and common safety more than much else. You want to simply detect a loss of mains voltage using a micro controller, in this case an Arduino board. Using an Arduino or similar uC I think you will find most suggested circuits look to use isolation which is why an optical coupler design is commonly used effectively and problem free. How to detect mains voltage with a microcontroller is one of many examples.

If you want a very simple quick and simple way to detect mains power loss or failure use a relay with a 220 VAC coil and an internal pullup on your Arduino. Allow for any switch bounce on your relay contacts in your code.

As to the professor of engineering? If you are comfortable with his circuit then use it but if it has any functional problems working with your Arduino I suggest you take it up with him. Many of my college course books were written by the professor teaching the course. While some were quite well written some were terrible and the mandatory book was lining a professors pockets. The fact that a professor can write a book means nothing. I don't know this professor. I gave you an alternate suggestion I was comfortable with. Now if what I suggested is not what you want to hear by all means run with something else.

Finally have you run the actual simulation on your circuit? Take a look at the signal between the R2 and the Q1 collector which is what would be fed to the uC. I would also change R2 to 10K as a pullup but same results. Run the simulation and tell us why you see what you will see.

Ron
 
Last edited:

DickCappels

Joined Aug 21, 2008
10,169
This thread was started with a question about the circuit and I would like to get back to that, something keeps bothering me.
1639116905134.png
This goes back to the question of where "ground" is. In particular, the emitter of Q1. If "ground" for this circuit is Neutral, then one of the connections to V1 should also be grounded. This circuit might work!

Looking at when each diode would conduct, I have come to the conclusion that D3 and D4 do nothing. D1 and D2 permit forward biasing of Q1 but prevent avalanche breakdown of the base-emitter junctions (which is a good thing in a low power circuit). Conclusion is that D3 and D4 are not needed.

Getting back to compatibility:
Because this circuit is not isolated from the line, indeed the "ground" is connected to Neutral, the only safe application of this circuit (and under this condition it is safe, I have done this myself) the entire circuit should be isolated from the user and external circuits.
 
Last edited:
Status
Not open for further replies.
Top