
Fig. 1
Zero-Crossing Detectors Circuits and Applications
Updated circuits: Improved AC Zero Crossing Detectors for Arduino.
A zero-crossing detector is used to generate a sync pulse related to the AC voltage phase angle often used in power control circuits. Fig. 1 shows the relationship of a zero-crossing pulse to a sine wave. The pulse occurs at 0, 180, and 360 degrees.

Fig. 2
Fig. 2 shows how to use a H11AA1 opto-coupler to generate a TTL level pulse. During most of the time the photo transistor output is LOW except when the voltage is near zero when the collector goes HIGH. The dual LED emitters of the H11AA1 assures both half-cycles are utilized.

Fig. 3
Fig shows a more common opto-coupler such as a 4N25, but to use both half-cycles will require a diode bridge input.

Fig. 4
Fig. 4 shows a direct application of a zero-crossing detector using an Arduino micro-controller to control the power output to a lamp. This variation still uses the H11AA1 but can be directly connected to 120VAC. The sketch is shown below.
The output of the H11AA1 is connected to Arduino DP2 to use its internal interrupt INTR0. When the switch on DP4 is closed a LOW is detected and the program connects interrupt 0 turning on a interrupt service routine acon.
The ISR reads the value of the potentiometer on AN0, divides by 4, then calculates a delay based on that value. The longer the delay (between 200uSec. and 8.3mSec.) the less power delivered to the load. The circuit will act as a lamp dimmer.
When the switch is opened the interrupt is detached and the lamp goes off. See the following related pages:
- Hardware Interrupts Tutorial for Arduino
- Basic Triacs and SCRs
- Solid State AC Relays with Triacs
- Light Activated Silicon Controlled Rectifier (LASCR)
- Arduino AC Power Control Using Interrupts
- In Depth Look at AC Power Control with Arduino
/* Purpose: to detect zero crossing pulse at INT0 digital pin 2, which after delay switches on a triac. Power activate by external switch */ #define triacPulse 5 #define SW 4 #define aconLed 13 int val; void setup() { pinMode(2, INPUT); digitalWrite(2, HIGH); // pull up pinMode(triacPulse, OUTPUT); pinMode(SW, INPUT); digitalWrite(SW, HIGH); pinMode(aconLed, OUTPUT); digitalWrite(aconLed, LOW); } void loop() { // check for SW closed if (!digitalRead(SW)) { // enable power attachInterrupt(0, acon, FALLING); // HV indicator on digitalWrite(aconLed, HIGH); } // end if else if (digitalRead(SW)) { detachInterrupt(0); // disable power // HV indicator off digitalWrite(aconLed, LOW); } // else } // end loop // begin ac int routine // delay() will not work! void acon() { delayMicroseconds((analogRead(0) * 7) + 200); // read AD1 digitalWrite(triacPulse, HIGH); delayMicroseconds(50); // delay 50 uSec on output pulse to turn on triac digitalWrite(triacPulse, LOW); }
Hobby Electronics Homepage and Webmaster Homepage (Off site.)
- Web Master
- Gen. Electronics
- YouTube Channel
- Arduino Projects
- Raspberry Pi & Linux
- PIC18F2550 in C
- PIC16F628A Assembly
- PICAXE Projects
- Bristol VA/TN
- Environmentalism
- US Constitution
- Religious Themes
- Religion Archive 1
- Comparator Theory Circuits Tutorial
- Analog Solar Panel Battery Charge Controller
- Better Arduino Rotary Encoder Sensor
- Simple 3-Wire MAX6675 Thermocouple ADC Arduino Interface
- TA8050P H-Bridge Motor Control
- All NPN Transistor H-Bridge Motor Control
- Basic Triacs and SCRs
- Comparator Hysteresis and Schmitt Triggers
- Comparator Theory Circuits Tutorial
- Photodiode Circuits Operation and Uses
- Optocoupler MOSFET DC Relays Using Photovoltaic drivers
- Connecting Crydom MOSFET Solid State Relays
- Photodiode Op-Amp Circuits Tutorial
- Optocoupler Input Circuits for PLC
- H11L1, 6N137A, FED8183, TLP2662 Digital Output Optocouplers
- Optical Isolation of H-Bridge Motor Controls
- All NPN Transistor H-Bridge Motor Control
Optical Isolation of H-Bridge Motor Controls YouTube
Optical Isolation of H-Bridge Motor Controls
Opto-Couplers Theory and Circuits YouTube
Opto-Isolated Transistor Drivers for Micro-Controllers
All NPN Transistor H-Bridge Motor Control YouTube
All NPN Transistor H-Bridge Motor Control
- Experiments with TL431 Shunt Regulator
- TL431 Precision Current Regulator Circuits
- LM317 Adjustable Voltage current Boost Power Supply
- LM317 High Power Constant Current Source Circuit
- Constant Current Circuits with the LM334
- LM317 Constant Current Source Circuits
- Introduction Hall Effect Switches, Sensors, and Circuits
- Basic Transistor Driver Circuits for Micro-Controllers
- Opto-Isolated Transistor Drivers for Micro-Controllers
- Geiger Counter Basics Radioactivity
- ULN2003A Darlington Transistor Array with Circuit Examples
- Tutorial Using TIP120 and TIP125 Power Darlington Transistors
- Driving 2N3055-MJ2955 Power Transistors with Darlington Transistors
- H-Bridge Motor Control with Power MOSFETS
- Build a High Power Transistor H-Bridge Motor Control