# How to test if zero crossing is working?

I used circuit like this:

On led I get: 3.3 mA and 1.3V

What is the best way to test if zero crossing works with arduino or multimetar?

• An oscilloscope. – Andy aka Feb 3 '16 at 13:59
• I don't have... – Vladimir Djukic Feb 3 '16 at 14:07
• There are some cheap ones on ebay for less than 25$USD ebay.com/itm/PC-Computer-Digital-USB-Oscilloscope-1MS-Sampling-/… you may be able to find them cheaper coming directly from china. They even have some based off of PIC's for 13$ USD You really need something to look at time. – Voltage Spike Feb 3 '16 at 17:38
• just don't start probing high voltage circuit ( like the mains side of the circuit above ) until you have learned about the ground paths from your scope lead through the building wiring and back to the circuit your testing. The issue is shorting the supply through the scope / pc / earth to live...the result is a burned mess. – Spoon Feb 3 '16 at 20:46

A simple test is to use a multimeter to measure the voltage on the output. Since it should be PWM you should see something between 5V and 0V. If you see 5V or 0V, then it's not working, but if you see something between the two, it's probably working.

Another option is to connect an LED with an appropriate resistor between 5V and the output, then sweep your eyes across the LED. 100Hz is very low frequency, and it should appear that instead of a solid light streak in your vision there should be a dotted line of light pulses if the zero crossing is working correctly.

Another option is to connect a small, low power speaker and series resistor between 5V and the output. You can then hear the 100Hz zero crossings if it's working correctly.

If you have an arduino, though, it's easy enough to count the number of pulses per second and verify correct operation.

Does your multimeter have any sort of frequency counter function? Some do, and that would be simplest — verify that the output of the detector matches your line frequency.

Otherwise, program the Arduino to be a frequency counter and look at the results there. It isn't hard to do. Just count the rising edges for one second and print out the value.

• Could you provide me some simple code for arduino? – Vladimir Djukic Feb 3 '16 at 14:12
• I'm not an Arduino programmer, but see the link I added above. – Dave Tweed Feb 3 '16 at 14:15
• But the output of that detector would output pulses at 100Hz on 50Hz 230V mains (two zero crossings for each period). – jms Feb 3 '16 at 15:07
• The H11AA1 uses two LEDs in inverse parallel to excite the phototransistor, so the output frequency will be twice the line frequency. – EM Fields Feb 3 '16 at 15:13
• OK, fair enough. I didn't look up the part; I just assumed that one of the diodes was not an LED. In that case, you don't get any phase information (rising vs. falling edge), and the Arduino needs to be fast enough to catch the relatively narrow output pulses. – Dave Tweed Feb 3 '16 at 15:22

Here's a simple Arduino program for measuring the AC crossing interrupt:

#define ZERO_DETECT   2     // Your arduino interrupt pin
#define BOARD_LED     13    // on board LED

// volatile required if you are going to reference this variable
// outside of the interrupt procedure
volatile  byte zeroCrossCounter = 0;

void setup() {
// You don't need a pullup since you can use the Arduino pullup
pinMode(ZERO_DETECT,INPUT_PULLUP);
pinMode(BOARD_LED,OUTPUT);
digitalWrite(BOARD_LED,LOW);
attachInterrupt(digitalPinToInterrupt(ZERO_DETECT),AcZeroCrossingInterrupt,RISING);
}

void loop() {
// put your main code here, to run repeatedly:
// Nothing to do here
}

void AcZeroCrossingInterrupt () {

if ( ++zeroCrossCounter == 60 ) {     // blink LED approx every 1/2 second
zeroCrossCounter = 0;