Arduino Zero Crossing
Arduino Zero Crossing
FacebookTwitterLinkedInRedditPinterest
Partager
A lot of Arduino projects involve controlling devices running on DC voltage. The devices running on DC voltage are usually controlled by changing
logic at GPIO pins for switching control or by PWM for operational control. There are times when devices running on AC current also needs to be
controlled by the microcontroller. For switching control, the AC appliances are usually interfaced to microcontroller boards via relays or relay circuits.
For operational control over AC appliances like controlling the speed of a fan or dimming a light bulb, power electronics comes into the picture. This
project is a demonstration of operational control of AC appliances using zero voltage crossing detection.
An alternating voltage changes its sign periodically. The alternating voltage supplied to households is usually the sine
wave. An alternating voltage can be other forms of the wave also. Irrespective of the waveform, an alternating voltage
in the first half of every cycle flows in one direction reaching to a peak voltage and then drops down to zero level.
Then in the next half of each cycle, it flows in alternate direction reaching to a peak voltage and then drops down to
zero level. The rise and drop of voltage in alternate direction are graphically shown with a negative sign of voltage and
voltage curve. The cycles are repeated throughout the voltage supply. For controlling AC appliances operationally, the
peak voltage of both the halves of a cycle needs to be chopped off. For this, it is important to detect when voltage
alternates its direction. The point on voltage curve where it alternates direction is called zero voltage crossing.
De nombreux projets Arduino impliquent de contrôler des appareils fonctionnant sous tension continue. Les appareils
fonctionnant sur tension continue sont généralement contrôlés en changeant la logique au niveau des broches GPIO
pour le contrôle de commutation ou par PWM pour le contrôle opérationnel. Il y a des moments où les appareils
fonctionnant sur courant alternatif doivent également être contrôlés par le microcontrôleur. Pour la commande de
commutation, les appareils CA sont généralement reliés aux cartes microcontrôleurs via des relais ou des circuits de
relais. Pour le contrôle opérationnel des appareils à courant alternatif, comme le contrôle de la vitesse d'un ventilateur
ou la gradation d'une ampoule, l'électronique de puissance entre en scène. Ce projet est une démonstration du contrôle
opérationnel des appareils CA utilisant la détection de passage à zéro tension.
Une tension alternative change de signe périodiquement. La tension alternative fournie aux ménages est généralement
l'onde sinusoïdale. Une tension alternative peut également être d'autres formes d'onde. Indépendamment de la forme
d'onde, une tension alternative dans la première moitié de chaque cycle circule dans une direction pour atteindre une
tension de crête, puis redescend au niveau zéro. Ensuite, dans la moitié suivante de chaque cycle, il s'écoule dans une
direction alternative atteignant une tension de crête, puis redescend au niveau zéro. La montée et la chute de tension
dans une direction alternative sont représentées graphiquement avec un signe négatif de tension et de courbe de
tension. Les cycles sont répétés sur toute la tension d'alimentation. Pour contrôler les appareils à courant alternatif de
manière opérationnelle, la tension de crête des deux moitiés d'un cycle doit être coupée. Pour cela, il est important de
détecter quand la tension alterne sa direction. Le point sur la courbe de tension où il alterne la direction est appelé
passage à zéro de tension
Fig. 1: Prototype of Arduino Based AC Voltage Controller
The zero voltage crossing of AC voltage can be detected by first rectifying it using full wave rectifier and then using an
optoisolator which will switch OFF and ON upon zero voltage crossings and past zero voltage crossings respectively.
The output of optoisolator can then be passed to the microcontroller to indicate zero voltage crossings to it.
For controlling AC voltage to a load, TRIAC needs to be used. TRIAC (Triode for AC) is commonly used for power
control and switching applications. The TRIAC can be feed control using an optocoupler which itself would be driven
by a microcontroller pin.
The project is built upon Arduino UNO and 4N25 optoisolator with a full bridge rectifier is used for zero voltage
crossing detection. The 3021 optocoupler and BT136 TRIAC are used for chopping off AC voltage to the load. The
tasks of zero voltage crossing detection and switching of 3021 IC are programmatically controlled by the Arduino
board. The Arduino sketch is written on Arduino IDE and burnt to the board using AVR Dude.
Le passage de tension nulle de la tension alternative peut être détecté en le redressant d'abord à l'aide d'un redresseur à
onde pleine, puis en utilisant un optoisolateur qui s'éteindra et se mettra en marche lors des franchissements de tension
nulle et des franchissements de tension nulle respectivement. La sortie de l'optoisolateur peut ensuite être transmise au
microcontrôleur pour lui indiquer des passages de tension nulle.
Pour contrôler la tension alternative à une charge, TRIAC doit être utilisé. TRIAC (Triode pour CA) est couramment
utilisé pour les applications de commande de puissance et de commutation. Le TRIAC peut être une commande
d'alimentation à l'aide d'un optocoupleur qui lui-même serait entraîné par une broche de microcontrôleur.
Le projet est basé sur Arduino UNO et un optoisolateur 4N25 avec un redresseur en pont complet est utilisé pour la
détection de passage à zéro de tension. L'optocoupleur 3021 et le BT136 TRIAC sont utilisés pour couper la tension
alternative à la charge. Les tâches de détection de passage à zéro de tension et de commutation du circuit intégré 3021
sont contrôlées par programme par la carte Arduino. Le croquis Arduino est écrit sur Arduino IDE et gravé sur la carte
à l'aide d'AVR Dude.
Components Required
• Arduino UNO
• 16×2 LCD
• EL 3021
• 4N25
• ON-OFF Switch
• Voltage regulator -7805
• BT136
• Wire to carry 2A, 230v AC
• 12-0, 1 Amp Transformer
• Two pin plug.
• Bulb holder
• 1N4007 diode
• Terminal block: PBT-2
• 6-pin IC base-2 pieces
• Resistors-10k, 3k3, 330 and 120 ohm
• Bread Board for connection
Block Diagram
The circuit is built around Arduino UNO. There are distinct circuit sections that are interfaced to the Arduino to realize the project functioning. In the
project, following circuit sections are assembled together –
Power Supply – The Arduino and LCD module need 5V DC supply. The required DC voltage is supplied by a battery.
The supply from the battery is regulated to 5V DC using 7805 IC. The IC has three pins – pin 1 should be connected to
the anode of the battery, pin 2 and 3 with the cathode (common ground). The 5V DC should be drawn from the pin 3 of
the IC. An LED along with a 10K Ω pull-up resistor can also be connected between common ground and output pin to
get a visual hint of supply continuity.
LCD Display – The LCD display is used to show the supplied voltage reading. When the project is powered ON, it
first flashes initial messages showing the intent of the project. Once the Arduino sketch initializes the circuit, the
voltage supplied to the load is displayed on the LCD screen. The 16X2 LCD display is connected to the Arduino board
by connecting its data pins to pins 3 to 6 of the Arduino board. The RS and E pins of the LCD are connected to pins 13
and 12 of the Arduino UNO respectively. The RW pin of the LCD is grounded.
Le circuit est construit autour d'Arduino UNO. Il existe des sections de circuit distinctes qui sont interfacées avec
l'Arduino pour réaliser le fonctionnement du projet. Dans le projet, les sections de circuit suivantes sont assemblées -
Alimentation - Le module Arduino et LCD nécessite une alimentation 5V DC. La tension continue requise est fournie
par une batterie. L'alimentation de la batterie est régulée à 5V DC en utilisant 7805 IC. Le CI a trois broches - la
broche 1 doit être connectée à l'anode de la batterie, les broches 2 et 3 avec la cathode (masse commune). Le 5V DC
doit être tiré de la broche 3 du CI. Une LED avec une résistance de rappel de 10 K Ω peut également être connectée
entre la masse commune et la broche de sortie pour obtenir une indication visuelle de la continuité de l'alimentation.
Écran LCD - L'écran LCD est utilisé pour afficher la lecture de tension fournie. Lorsque le projet est mis sous tension,
il clignote d'abord les messages initiaux indiquant l'intention du projet. Une fois que l'esquisse Arduino initialise le
circuit, la tension fournie à la charge s'affiche sur l'écran LCD. L'écran LCD 16X2 est connecté à la carte Arduino en
connectant ses broches de données aux broches 3 à 6 de la carte Arduino. Les broches RS et E de l'écran LCD sont
respectivement connectées aux broches 13 et 12 de l'Arduino UNO. La broche RW de l'écran LCD est mise à la terre.
Fig. 3: Table listing circuit connections between Arduino Uno and Character LCD
The standard open-source library for interfacing LCD with Arduino UNO is used in the project. The library works as
expected and needs no changes or modifications.
ON-OFF Switch: An ON-OFF switch is provided to turn ON/OFF the supply to the load. The switch is interfaced to
Arduino by connecting between ground and pin 7 of the board. The pin 7 by default receives HIGH logic by direct
connection to VCC but on toggling the switch it receives a LOW logic. The switching of the supply voltage to the load
is controlled by detecting logic at pin 7 of the Arduino board.
Variable Resistor – A 10K ohm resistor is used to change the firing angle. It is connected to the A0 pin of Arduino
UNO. The resistance provides an analog voltage which is converted to digital reading by the in-built ADC. The
optocoupler 3021 is operated accordingly to control the firing angle.
Zero Voltage Crossing Detection Circuit – First the AC voltage from the main supply is stepped down using a
transformer to 12V. The stepped down AC voltage is feed to full bridge rectifier circuit built using 1N4007 diodes. The
rectified voltage is supplied to pins 1 and 2 of 4N25 optocoupler. The 4N25 is a phototransistor type optocoupler. At
pin 1, there is an anode of in-built LED and at pin 2 is the cathode of it. The 4N25 optocoupler has the following pin
configuration –
La bibliothèque open-source standard pour l'interface LCD avec Arduino UNO est utilisée dans le projet. La
bibliothèque fonctionne comme prévu et ne nécessite aucun changement ou modification.
Interrupteur MARCHE-ARRÊT: Un interrupteur MARCHE-ARRÊT est fourni pour allumer / éteindre l'alimentation
de la charge. L'interrupteur est interfacé à Arduino en se connectant entre la masse et la broche 7 de la carte. La broche
7 par défaut reçoit la logique HIGH par connexion directe à VCC mais en basculant le commutateur, elle reçoit une
logique LOW. La commutation de la tension d'alimentation vers la charge est contrôlée par une logique de détection à
la broche 7 de la carte Arduino.
Résistance variable - Une résistance de 10 K ohms est utilisée pour modifier l'angle de tir. Il est connecté à la broche
A0 d'Arduino UNO. La résistance fournit une tension analogique qui est convertie en lecture numérique par l'ADC
intégré. L'optocoupleur 3021 est actionné en conséquence pour contrôler l'angle de tir.
Circuit de détection de passage à zéro de tension - Tout d'abord, la tension alternative de l'alimentation principale est
abaissée à l'aide d'un transformateur à 12V. La tension alternative abaissée alimente le circuit redresseur en pont
complet construit à l'aide de diodes 1N4007. La tension redressée est fournie aux broches 1 et 2 de l'optocoupleur
4N25. Le 4N25 est un optocoupleur de type phototransistor. À la broche 1, il y a une anode de LED intégrée et à la
broche 2 se trouve la cathode de celle-ci. L'optocoupleur 4N25 a la configuration de broches suivante -
The base of the in-built phototransistor is grounded while the output is drawn from the Collector of the photo-
transistor. This way, the photo-transistor actually operates like an LED which gets forward biased when photo-diode
glows. The collector pin is connected to pin 2 of the Arduino.
La base du phototransistor intégré est mise à la terre tandis que la sortie est tirée du collecteur du photo-transistor. De
cette façon, le photo-transistor fonctionne en fait comme une LED qui est polarisée en direct lorsque la photo-diode
s'allume. La broche du collecteur est connectée à la broche 2 de l'Arduino.
Fig. 6: Circuit Diagram of Zero Voltage Crossing Detector
Opto-Isolator EL3021 – EL3021 is a photo-TRIAC type optocoupler. It should be noted that photo-transistor and
photodarlington type optocouplers are used for controlling DC devices while photo-SCR and photo-triac type
optocouplers are used for controlling AC devices. The EL3021 has the following pin configuration –
L'opto-isolateur EL3021 - EL3021 est un optocoupleur de type photo-TRIAC. Il convient de noter que les
optocoupleurs de type photo-transistor et photodarlington sont utilisés pour contrôler les dispositifs à courant continu
tandis que les optocoupleurs de type photo-SCR et photo-triac sont utilisés pour contrôler les dispositifs à courant
alternatif. L'EL3021 a la configuration de broches suivante -
Fig. 7: Table listing pin configuration of EL3021 Opto-Isolator
The pin 2 of EL3021 is connected to ground and pin 1 is connected to pin 10 of the Arduino. The Main Terminal pins
of photo-TRIAC, pins 4 and 6 of EL3021 are connected to pins 3 (Base) and 2 (Main Terminal 2) of BT136. The pin 2
of BT136 and pin 6 of EL3021 are connected to a junction with phase wire of main supplies. The pin 5 of the EL3021
is not connected so the photo-TRIAC actually operates like a photo-DIAC. The load is connected between pin 1 of
BT136 and neutral wire. The phase voltage is controlled by the BT136 which itself is controlled by the photo-TRIAC
operating as photo-DIAC of EL3021.
TRIAC BT136 – A TRIAC has three terminals – Main Terminal 1, Main Terminal 2 and Gate. TRIAC is equivalent to
two SCRs connected in inverse parallel with the gates connected together. Therefore TRIAC works as a bi-directional
switch which is triggered by the pulse on the base. The Main Terminal 1 and Main Terminal 2 of the TRIAC are used
for connecting phase and neutral wire and the triggering pulse is supplied to Gate terminal from the photo-TRIAC of
EL3021. The Gate terminal can be triggered either by a positive or negative voltage. There are four possible modes of
the operation of a TRIAC –
a) Main Terminal 2 has a positive voltage compared to Main Terminal 1 and there is positive pulse at Gate
b) Main Terminal 2 has a positive voltage compared to Main Terminal 1 and there is negative pulse at Gate
c) Main Terminal 1 has a positive voltage compared to Main Terminal 2 and there is positive pulse at Gate
d) Main Terminal 1 has a positive voltage compared to Main Terminal 2 and there is negative pulse at Gate
The TRIAC conducts current when either Main Terminal 2 gets a positive voltage with respect to the Main Terminal 1
and the Gate gets a positive trigger or Main Terminal 1 has a positive voltage compared to Main Terminal 2 and there
is a negative pulse at Gate. When the Gate current is removed, the TRIAC switches off. BT136 is the TRIAC used in
the circuit and has following pin configuration –
La broche 2 de EL3021 est connectée à la masse et la broche 1 est connectée à la broche 10 de l'Arduino. Les broches
de la borne principale du photo-TRIAC, les broches 4 et 6 de l'EL3021 sont connectées aux broches 3 (base) et 2
(borne principale 2) du BT136. La broche 2 de BT136 et la broche 6 de EL3021 sont connectées à une jonction avec le
fil de phase des alimentations principales. La broche 5 de l'EL3021 n'est pas connectée donc le photo-TRIAC
fonctionne en fait comme un photo-DIAC. La charge est connectée entre la broche 1 du BT136 et le fil neutre. La
tension de phase est contrôlée par le BT136 qui lui-même est contrôlé par le photo-TRIAC fonctionnant comme photo-
DIAC de l'EL3021.
TRIAC BT136 - Un TRIAC a trois terminaux - Terminal principal 1, Terminal principal 2 et Gate. TRIAC équivaut à
deux SCR connectés en parallèle inverse avec les portes connectées ensemble. Par conséquent, TRIAC fonctionne
comme un commutateur bidirectionnel qui est déclenché par l'impulsion sur la base. La borne principale 1 et la borne
principale 2 du TRIAC sont utilisées pour connecter la phase et le fil neutre et l'impulsion de déclenchement est
fournie à la borne de porte à partir du photo-TRIAC de l'EL3021. La borne Gate peut être déclenchée par une tension
positive ou négative. Il existe quatre modes de fonctionnement possibles d'un TRIAC -
a) La borne principale 2 a une tension positive par rapport à la borne principale 1 et il y a une impulsion positive à la
porte
b) La borne principale 2 a une tension positive par rapport à la borne principale 1 et il y a une impulsion négative à la
porte
c) La borne principale 1 a une tension positive par rapport à la borne principale 2 et il y a une impulsion positive à la
porte
d) La borne principale 1 a une tension positive par rapport à la borne principale 2 et il y a une impulsion négative à la
porte
Le TRIAC conduit le courant lorsque la borne principale 2 obtient une tension positive par rapport à la borne
principale 1 et que la porte obtient un déclenchement positif ou la borne principale 1 a une tension positive par rapport
à la borne principale 2 et qu'il y a une impulsion négative à la porte. Lorsque le courant Gate est supprimé, le TRIAC
s'éteint. BT136 est le TRIAC utilisé dans le circuit et a la configuration de broche suivante -
The project controls the AC voltage by sending pulses to the Gate pin of BT136 TRIAC. When the circuit is powered
ON, the Arduino sketch initializes the circuit and start reading analog voltage supplied through variable resistance at
A0 pin. The zero voltage crossing is detected by the 4N25 circuit. The AC voltage from main supplies is stepped down
to 12V AC by the transformer and rectified by the 1N4007 diode full-wave rectifier. The AC voltage once converted to
DC voltage drives the IR diode of 4N25 forward biasing it for voltage levels greater than 1.1 Volt.
When the voltage level of the rectified wave is above zero voltage crossing, phototransistor of 4N25 remains in forward biased condition, short-
circuiting the VCC supply at pin 2 of Arduino to ground. Therefore, for a majority of the waveform, a LOW logic is received at pin 2 of Arduino.
When voltage level approaches zero voltage crossing, the IR diode of 4N25 does not get the required voltage for forward biasing. So, the
phototransistor of 4N25 switches to unbiased condition and the pin 2 of Arduino get a HIGH pulse upon zero voltage crossing.
The Arduino detects the zero voltage crossing and determines a firing angle based on the voltage supplied through
variable resistance at pin A0. The analog voltage at A0 pin is read by the Arduino and converted to a digital reading
using in-built ADC channel. A time interval based on digitized voltage reading is calculated in the Arduino Sketch. An
interrupt routine shooting a HIGH pulse for 50 microseconds after the delay of the resultant time interval is activated at
pin 10 of the Arduino. The HIGH pulse drives the IR diode of an EL3021 optocoupler with the same delay of the
calculated time interval. This, in turn, drives the triggering pulse at the Gate terminal of BT136 TRIAC with the same
delay equivalent to the calculated time interval.
In power control application using TRIAC, the voltage pulse before the emergence of triggering pulse at Gate terminal
of TRIAC gets chopped off while the part of AC voltage wave after the emergence of triggering pulse at Gate terminal
of TRIAC remains available for supply to the load.
Check out the Arduino program which is detecting zero voltage crossing based on digital logic at pin 2, calculating a
time delay for triggering pulse by digitizing analog voltage through variable resistance at A0 pin and generating a
triggering pulse at pin 10 in an interrupt routine.
L'Arduino détecte le passage à zéro de la tension et détermine un angle d'allumage basé sur la tension fournie via une
résistance variable à la broche A0. La tension analogique à la broche A0 est lue par l'Arduino et convertie en lecture
numérique à l'aide du canal ADC intégré. Un intervalle de temps basé sur la lecture de tension numérisée est calculé
dans Arduino Sketch. Un sous-programme d'interruption tirant une impulsion HAUTE pendant 50 microsecondes
après le retard de l'intervalle de temps résultant est activé à la broche 10 de l'Arduino. L'impulsion HIGH entraîne la
diode IR d'un optocoupleur EL3021 avec le même retard de l'intervalle de temps calculé. Ceci, à son tour, entraîne
l'impulsion de déclenchement à la borne Gate du BT136 TRIAC avec le même retard équivalent à l'intervalle de temps
calculé.
Dans une application de contrôle de puissance utilisant TRIAC, l'impulsion de tension avant l'émergence de
l'impulsion de déclenchement à la borne de porte de TRIAC est coupée tandis que la partie de l'onde de tension
alternative après l'émergence de l'impulsion de déclenchement à la borne de porte de TRIAC reste disponible pour
l'alimentation de la charge.
Découvrez le programme Arduino qui détecte le franchissement de tension zéro basé sur la logique numérique à la
broche 2, calculant un délai pour déclencher l'impulsion en numérisant la tension analogique à travers une résistance
variable à la broche A0 et en générant une impulsion de déclenchement à la broche 10 dans une routine d'interruption.
Programming Guide
First of all, the standard library for LCD needs to be imported. An object of LCD class is declared with pins interfaced
to LCD mapped with the object. A constant triacPulse is declared and mapped to pin 10 of the Arduino where the
triggering pulse to the Gate terminal of TRIAC has to be generated. Similarly, a variable SW is declared and mapped
to pin 7 of Arduino where the toggle switch is connected. A counter variable is declared and initialized to 0.
Tout d'abord, la bibliothèque standard pour LCD doit être importée. Un objet de classe LCD est déclaré avec des
broches interfacées avec LCD mappées avec l'objet. Un triacPulse constant est déclaré et mappé sur la broche 10 de
l'Arduino où l'impulsion de déclenchement vers le terminal Gate de TRIAC doit être générée. De même, une variable
SW est déclarée et mappée sur la broche 7 d'Arduino où l'interrupteur à bascule est connecté. Une variable de compteur
est déclarée et initialisée à 0.
A setup() function is called in which the baud rate for serial transmission of data to the LCD is set to 9600 bits per
second using [Link]() function and the LCD is initialized using [Link]() function. The pin 2 where zero
voltage crossing is detected by digital logics is configured to digital input using pinMode() function and is pulled up by
writing a HIGH logic to it using digitalWrite() function. Similarly, the pin where the triggering pulse is to be generated
is set digital output and pin where toggle switch is connected is set digital input. Some initial messages are displayed
on the LCD screen showing the intent of the application project.
Une fonction setup () est appelée dans laquelle le débit en bauds pour la transmission série de données vers l'écran
LCD est réglé à 9600 bits par seconde à l'aide de la fonction [Link] () et l'écran LCD est initialisé à l'aide de la
fonction [Link] (). La broche 2 où le franchissement de tension zéro est détecté par la logique numérique est
configurée en entrée numérique à l'aide de la fonction pinMode () et est tirée vers le haut en y écrivant une logique
HIGH à l'aide de la fonction digitalWrite (). De même, la broche sur laquelle l'impulsion de déclenchement doit être
générée est réglée sur la sortie numérique et la broche sur laquelle l'interrupteur à bascule est connecté est réglée sur
l'entrée numérique. Certains messages initiaux s'affichent sur l'écran LCD indiquant l'intention du projet d'application.
void setup() {
[Link](9600);
[Link](16,2);//LCD 16×2 initialization
pinMode(2, INPUT);
digitalWrite(2, HIGH); // pull up
pinMode(triacPulse, OUTPUT);
pinMode(SW, INPUT);
digitalWrite(SW, HIGH);
[Link](0,0); //Initially set the cursor position of LCD to 1st Columb 1st row.
[Link](“Engineers Garage”);//After initialising print data
[Link](0,1); //Initially set the cursor position of LCD to 1st Columb 2nd row.
[Link](” “); //print blank to clear all the data on LCD
delay(3000);
[Link](0,0);
[Link](” SPEED CONTROL “);
[Link](0,1);
[Link](” AC MOTOR “);
delay(3000);
[Link](0,1);
[Link](” “);
}
The loop function is called where the initial messages are replaced on the LCD and status of the toggle switch is read
to proceed the application. If a LOW logic is detected at the pin connected to toggle switch, the Arduino reads analog
voltage at pin connecting variable resistance using analogRead() function and calls an interrupt routine. The analog
reading is digitized to the proper format and displayed on the LCD screen. If the toggle switch is released and a HIGH
logic is detected at the pin, interrupt routine is detached at pin 10 using detachInterrupt() function and a message
showing OFF status of supply to the load is displayed on the LCD screen.
La fonction de boucle est appelée là où les messages initiaux sont remplacés sur l'écran LCD et l'état de l'interrupteur à
bascule est lu pour poursuivre l'application. Si une logique FAIBLE est détectée à la broche connectée à l'interrupteur à
bascule, l'Arduino lit la tension analogique à la broche connectant une résistance variable à l'aide de la fonction
analogRead () et appelle une routine d'interruption. La lecture analogique est numérisée au format approprié et affichée
sur l'écran LCD. Si l'interrupteur à bascule est relâché et qu'une logique HIGH est détectée au niveau de la broche, la
routine d'interruption est détachée à la broche 10 à l'aide de la fonction detachInterrupt () et un message indiquant l'état
OFF de l'alimentation de la charge s'affiche sur l'écran LCD.
void loop() {
[Link](0,0);
[Link](” AC MOTOR “);
// check for SW closed
if (!digitalRead(SW)) {
x=analogRead(A0);
// enable power
attachInterrupt(0, acon, FALLING);
[Link](11,0);
[Link](“ON “);
[Link](6,1);
[Link]((analogRead(A0) * 7) + 200);
} // end if
else if (digitalRead(SW)) {
detachInterrupt(0); // disable power
[Link](11,0);
[Link](“OFF “);
[Link](0,1);
[Link](” “);
} // else
} // end loop
The interrupt routine in the loop() function calls an acon() function. In the acon() function, a time interval is calculated
according to the analog reading at pin A0. The reading digitized to 10-bit value is passed as an argument to
delayMicroseconds() function generating a time delay of an equivalent interval. During this interval, a LOW pulse
remains on the pin 10 of Arduino. After the calculated delay, a HIGH pulse for 50 microseconds is generated at pin 10
of Arduino.
La routine d'interruption de la fonction loop () appelle une fonction acon (). Dans la fonction acon (), un intervalle de
temps est calculé en fonction de la lecture analogique sur la broche A0. La lecture numérisée à une valeur de 10 bits est
transmise comme argument à la fonction delayMicroseconds () générant un délai d'un intervalle équivalent. Pendant
cet intervalle, une impulsion LOW reste sur la broche 10 d'Arduino. Après le délai calculé, une impulsion HIGH
pendant 50 microsecondes est générée à la broche 10 d'Arduino.
This completes the Arduino sketch for AC voltage control using zero voltage crossing detection.
//Program to
#include <LiquidCrystal.h>//import the LCD library
#define triacPulse 10
#define SW 7
int x=0;
void setup() {
[Link](9600);
pinMode(2, INPUT);
pinMode(triacPulse, OUTPUT);
pinMode(SW, INPUT);
digitalWrite(SW, HIGH);
[Link](0,0); //Initially set the cursor position of LCD to 1st Columb 1st row.
[Link](0,1); //Initially set the cursor position of LCD to 1st Columb 2nd row.
delay(3000);
[Link](0,0);
[Link](0,1);
delay(3000);
[Link](0,1);
[Link](" ");
void loop() {
[Link](0,0);
if (!digitalRead(SW)) {
x=analogRead(A0);
// enable power
[Link](11,0);
[Link]("ON ");
[Link](6,1);
[Link]((analogRead(A0) * 7) + 200);
} // end if
else if (digitalRead(SW)) {
[Link](11,0);
[Link]("OFF ");
[Link](0,1);
[Link](" ");
} // else
} // end loop
void acon()
digitalWrite(triacPulse, HIGH);
delayMicroseconds(50);
digitalWrite(triacPulse, LOW);
###
Circuit Diagrams
C
i
r
c
u
it
-
D
i
a
g
r
a
m
-
A
r
d
u
i
n
o
-
B
a
s
e
d
-
A
C
-
V
o
lt
a
g
e
-
C
<=""
o
n
t
r
o
ll
e