Following my previous question, I'm getting closer to thinking about putting together this mains frequency monitor. I would just like to do a sanity check on my electronics before I order the components and the board. Please keep in mind I am not qualified in this so I have had to research how all this will work.

Circuit layout

A and B inputs will accept power from a 16VAC 1.25A unregulated power pack.

C1 is a 1µF 25V 85°C ceramic capacitor. I guess this is mostly unnecessary as the power pack should filter any DC bias, but it won't hurt.

D1 is an IN4001 1A standard recovery diode.

R1 is a 300ohm 500V 3W resistor. The RMS power is 16VAC, which is half-wave rectified, so that's sqrt(2) * 16 = ~24V peak @ 300ohm = 80mA peak, and about 25mA on average (right?)

IC1 is a 4N28 optocoupler. It's weird, in one data sheet I see 80mA max forward current on inputs but in another I see 60mA. Anyway, the average should be 25mA so I guess that's probably going to be okay?

The Arduino I will use is the Arduino Micro, as it's quite small and also has a 16Mhz crystal oscillator that will provide a more stable clock than a ceramic resonator. The Arduino will be powered by USB, which I believe is 5V. The digital I/O pins I believe will also operate at 5V and are rated at 40mA max.

C will come from one of the Arduino's digital output pins, and D will go to the Arduino's GND.

R2 is a 150ohm 500mW 250V resistor, that should ensure the CD current does not exceed 40mA @ 5V.

Now, assuming the components look okay and the circuit looks okay (I assume the circuit is fine), I just had some questions:

  1. Do I need to add anything to the output of the 4N28 coming from the input? I think with a regular transistor, some of the base current gets added to the collector current?
  2. What can I expect the response on the output of the 4N28 to look like? I assumed that it would more-or-less be a square wave, where even a tiny current on the input would activate the transistor and allow the output current to flow freely on the other side, but someone has suggested that this might not be the case?
  3. The way it is set up, the Digital I/O pin can be "trying" to output or not, and that's basically irrelevant to what the transistor is doing. When the transistor is on, the output current from the pin will successfully flow to GND. I assume there is a way to detect this in the Arduino? Something like setting the output pin to 1 and check in loop when there is or is no current flowing?

Thank you!

  • 3: your circuit will not work. Think pushbutton where the optocoupler is the button.
    – Majenko
    May 25 '17 at 23:46
  • 1
    The capacitor is pointless. There can be no DC offset since there is no reference for it to be offset from. All it will do is mess with your current, screwing your power factor.
    – Majenko
    May 25 '17 at 23:49
  • @Majenko thanks, I can remove the capacitor. I don't understand your explanation about why the circuit will not work? Or how to fix it?
    – Ozzah
    May 25 '17 at 23:55
  • 1
    You make poor assumptions about how GPIOs and transistors work. In this situation the transistor is merely a switch. Treat it as such. That means pull up resistor to VCC, and GPIO set to input mode.
    – Majenko
    May 25 '17 at 23:56
  • Oh, and program it to use interrupts or, better, the Input Capture peripheral.
    – Majenko
    May 25 '17 at 23:59

You should remove the capacitor. It won't remove any DC offset because there can be no DC offset. From where would the DC offset be relative? There is only two points in the circuit, and both of them are direct from the transformer and is an AC waveform. There is no concept of a DC offset in such a circuit. All the capacitor will do is impose a phase change between the current and voltage of the AC waveform limiting the current during the conducting period of the diodes. You have a resistor for that function.

You make some incorrect assumptions about how to read the data. You talk about outputting a signal and somehow finding out if the transistor is on or not by if that signal is being output. That's completely backwards. Instead you should treat the transistor like a simple pushbutton and provide it with a pullup (or pulldown if you prefer) resistor, like this:


simulate this circuit – Schematic created using CircuitLab

You should feed the signal into an interrupt-enabled pin (such as D2 on the Uno as shown) so that an interrupt can be used for capturing the incoming edge time. Better would be to use the Input Capture peripheral, but that is harder to program for as there is no (AFAIK) library for it.

Yes, it would be possible to use the internal pullup resistor of the input pin instead of an external one, however using an external one allows you to fine tune the resistance which, coupled with the gate capacitance of the input pin, forms a low-pass filter limiting the frequency range you can monitor. At 50Hz it shouldn't be a problem though, so the choice is yours. Personally I use an external one.


I am not qualified in this

I think you will find it very beneficial to you to get qualified in this first before you try -> what you are trying to do has a real potential to kill you, especially if you aren't qualified in it.

C1 is a 1µF 25V 85°C ceramic capacitor.

Again, that's a deadly choice of components here -> it pays to be qualified, preferably well qualified, in what you do first.

you may want to think of a transformer based solution first -> the principle is the same but it is much safer, especially for someone who isn't qualified here.

the software side of it is simple: use the zero-crossing signal to gate one of the avr timers and you can measure the mains frequencies to many many bits of resolutions.

  • 4
    I'm really confused. Did you miss the part where I said I am using a 16V 1.25A power pack?
    – Ozzah
    May 26 '17 at 0:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.