220V detector - again

I have no difficulties letting sites writing / reading their cookies as sessions becomes statefull and hence more user friendly

A strange new usage of the word friendly. This is why we have rules about going off site. I don’t want my computer infected with this spam.

Grumpy_Mike:
A strange new usage of the word friendly. This is why we have rules about going off site. I don't want my computer infected with this spam.

Ok dear, of you call cookies spam i prefer to stop here the conversation.

It does not encourage to insert pics: ext site tabou, own site refuse to upload. I wanted to share and possibly help and be helped and i end up with this sad conversation. Again I won't come back in this subj

Ok dear, of you call cookies spam i prefer to stop here the conversation.

Fine by me you are not being particularly respectful to the rules we have here about posting images. Maybe you can find a place where they don't mind you ignoring rules. Rules designed to make exchange of ideas flow smoothly.

own site refuse to upload

Then you are doing something wrong but simply can't be bothered to find out what. Images upload fine here, we do it hundreds of times a day.

Again I won't come back in this subj

Good bye.

herbschwarz:
Hi All,
I suggest the 1N4007 diode should be used as a half wave rectifier
so that only one 120K resistor is required. You do not need the
integrating capacitor(s). Just go with the square wave output.
Herb

after some more thinking, why? 'normal' 1/4W resistors are rated 300V and pick of 220rms is 311...

But this lade me to envisage a diode bridge: the output transistor would saturate every smaller time intervals so that the exponential charge would last less and as a result the positive pulses would be smaller. Furthermore, as their frequency would double, the filtering capacitor can be smaller and as a consequence the detection of switch off condition can be faster. Critics please?

If you really don't want to do in software (which is pretty straight forward), yes, a full bridge will give you extra on time. But it also makes the hardware more complex as a trade off :wink:

septillion:
If you really don’t want to do in software (which is pretty straight forward), yes, a full bridge will give you extra on time. But it also makes the hardware more complex as a trade off :wink:

Thank you Septillion,

First do we agree that the half rectification suggested above does not alleviate the need for tp series resistors
Second, regarding sw implementation, imagine a source generating noise in sync with the mains, e.g. a stuff injecting a pulse every zero cross, this may even be a dimmer. The software who’s looking for a 50Hz signal will find it and will consider the switch as being closed. Now suppose you write your code, test it and find it rock robust. One day you (or you neighbor) buy a new appliance which, during night (e.g.) sometimes has it’s synced noise exceeding a threshold. Should the switch in question command stores or a gateway (my case) they will open while I am away and this is really undesirable and should justify spending some more drachmas on the hw . The reason I said I won’t go this way is that I have no mean to insure that my algorithm will remain valid in the future.

But that pulse will not last as long as "real mains" :wink: So simply check that. Like suggested in reply #19 :slight_smile:

Aka, check for x pulses in y time with minimum duration of z.

septillion:
But that pulse will not last as long as "real mains" :wink: So simply check that. Like suggested in reply #19 :slight_smile:

Aka, check for x pulses in y time with minimum duration of z.

Heumm yes.
I must postpone the the discussion until Sunday. Meanwhile thanks for your involvement

So we need to wake up in sync with the middle - to make sure its not too early nor too late - of the square pulse at the collector's and then wake up, say every millisec five times to make sure we have the 'real mains' and not synced parasit. The location of the mid of the pulse - assuming 50% duty cycle - can be found by sampling the wave say every milli to find five 'lows' followed by five 'highs' and adding 2.5ms to the previously found transition. Now we are well centered and if all - or most, say 3 out of 5 are high and that this occurs for 100 ms (5 mains cyclec) then we decide 'switch closed'. Conversely, if centered, by a 20ms translation of above center we find mostly 'lows' then we decide that the switch is open. While the switch is closed, We will need to redo the centering every now and then to compensate for the drift of cpu's clock relative to the 50 Hz and do the all thing for every switch. I said wake up because obviously, it must be done in interrupts. This may work but, then, why not going the orthodox way with a DSP and replace the unfortunate capacitor by an FIR low pass? Say with constant coefficients all ones and one bit ADC? Could be implemented as circular buffer where samples are inserted at the head pointer and extracted from the tail=head+1 (modulo) and FIR output = sum + *head -*tail is compared to a threshold [edit: with hysteresis] and the results is the switch state?

I don't really get the complex approach and the need for the middle. But if you want to put the uC to sleep then you, external filtering might be preferred to wake it up less frequency. Although it might still benefit from software filtering as well. And you don't need the middle and stuff. Just keeping time between a rising and a falling edge and counting them.

septillion:
I don't really get the complex approach and the need for the middle. But if you want to put the uC to sleep then you, external filtering might be preferred to wake it up less frequency. Although it might still benefit from software filtering as well. And you don't need the middle and stuff. Just keeping time between a rising and a falling edge and counting them.

Sorry, I don't know what is it that you call 'middle'

guy_c:
Sorry, I don't know what is it that you call 'middle'

this:

guy_c:
So we need to wake up in sync with the middle [...]

, check for x pulses in y time with minimum duration of z.

To check the minimum duration we need to sample in the middle. Eg 50% duty 10ms pulse we want to sample say at ms# 4, 5, 6. And find, say, >=2

Mm, not really. IF you think of it as sampling then you would at least need the Nyquist frequency. And you might say the second sample is the middle but that's as far as it has anything to do with the middle.

But you may assume the Arduino is orders of magnitude faster than mains. Aka, timing of the polling or sampling isn't really an issue. And to make it accurate, just use the interrupt on state change. Now you just have two events for a puls, a rising event and a falling event. And you can just apply the usual time keeping practices (hint: millis() / micros()) to determine z and y.

But we agreed that just meayrrng rising an falling will give false positive for noise synced to main

If you let THAT trigger the output directly, yes. Not if you put that into an algorithm which can detect a falls positive (or negative even!) and let that drive whatever-you-want.

septillion:
if you put that into an algorithm which can detect

yes, sure