Disclaimer: I am not an expert in any of this. There is lots of information online regarding such designs. Although this setup worked for me, do not trust any of my calculations. Please work all this out for yourself and consult many other sources, or it may spontaneously burst into flames.
The contraption is a board containing two lights and a receptacle that are controlled by a computer communicating with the Arduino microcontroller. The project grew out of a desire to learn more about microcontroller programming and some circuit design, something I had never really done before.
Below is a video of the contraption in action. In the video, I control the two light bulbs, as well as a blender, from my computer. (Note: the video does not have sound)
Principle & Hardware
The hardware was laid out on a plain wood board as shown in the photos below.
Note that all power is actually flowing through the breadboard. This is probably not a very good idea, but as we are dealing with only an amp or two at most, I thought it might be satisfactory. I’ve included both an on/off switch, and a 5A circuit breaker for safety.
The schematic below shows the main circuit used in controlling the power to the lights and the receptacle. This circuit is nearly identical to that found in the MOC3022M datasheet.
The main principle is as follows:
- The opto-isolating triac (MOC3022M) receives an input from an Arduino output pin.
- This allows bi-directional voltage on the triac side (pins 6 and 4). This voltage comes from the mains through 180Ω resistor R2 and to the gate pin on the triac T1.
- This voltage turns on the BTB08 triac (T1) through its gate pin. This allows conduction through the triac and through the load.
A few notes and equations:
- The BTB08 triac chosen is ‘snubberless’. It therefore may not be necessary to include a snubber circuit for inductive loads. I didn’t include one, and as seen in the video, it seems to work ok for the blender motor.
- The Arduino output (Vcc) is 5V. Therefore, the max current through the left side of the MOC3022M is 5V/390Ω = 12.8mA
- The peak voltage of the AC Mains is approximately 170V. Therefore, current through the right side of the MOC3022M is limited to 170V/180Ω = 0.94A. This is just under the maximum of 1A listed in the data sheet
- The triac T1 is always operating in quadrants I or III.
If no voltage is applied to the left side of the MOC3022M, the mains current flow through the T1 triac will stop when the mains voltage reaches the zero-point crossing. The solution is to leave the Arduino output on, which works only if you want the mains circuit completely on. However, for dimming, you must know when the zero cross occurs.
This circuit allows an Arduino input pin to register when the AC mains voltage is in the positive half-wave.
- The negative half-wave is removed by the diode. Therefore, the RMS voltage is 60V
- The four resistors have an equivalent resistance of 10kΩ. Therefore, the RMS current is 60V/10kΩ = 6mA. The reason for several resistors is to reduce the power at each resistor. The voltage across each resistor is 30V, therefore the power dissipation is (30V)(30V)/10kΩ = 90mW
Note that detection by the Arduino of the start of the positive half of the sine wave is delayed, and the detection of the end is too early. Below is an exaggerated diagram.
The counter in the diagram refers to the AVR timer counter that counts ticks between the rising and falling edges. The average of the rising and falling edge counters gives 60Hz. In order to dim, the triac must turn on at a specified point during the sine wave. That point is calculated in the code. Therefore, the timer for turning on the triac must be kept in sync with the timer for the zero-cross detection. This is done by modifying the phase-shifting-timer’s counter register when the microcontroller detects a rising edge. A more-accurate value for the phase-shifting counter can be approximated, assuming the symmetry present in the diagram (see the code). This could also be done for the falling edge as well, although would require more code in an interrupt routine, which is generally a bad thing.
Due to the zero-cross behavior, even if the Arduino output is left completely on, there is some delay in turning on the triac due the gate current and voltage required to trigger the triac. This delay can be calculated:
- Gate current for the triac is 50mA (from the data sheet)
- The gate voltage is 1.3V
- The opto-isolator detector on-state voltage is 3V max
- Therefore, the AC mains voltage must reach (180Ω)(0.05A)+3V+1.3V=13.3V
- Taking the inverse sine of 13.3V/170V results in a phase-shift of 4.5° or 0.0785 radians.
Read more: BennyP’s Light Contraption
Kumbuka: Mimi si mtaalamu wa mambo haya. Kuna habari nyingi mtandaoni kuhusu miundo hiyo. Ingawa utaratibu huu ulinifaidi, usitegemee hesabu zangu zozote. Tafadhali fanya kazi yote haya kwa ajili yako mwenyewe na kushauriana vyanzo vingine vingi, au inaweza ghafla kulipuka katika moto. Kifaa hicho ni bodi yenye taa mbili na chombo ambacho kinadhibitiwa na kompyuta inayosambaza na Arduino microcontroller. Mradi huo ulizaliwa kutokana na hamu ya kujifunza zaidi kuhusu programu ya microcontroller na baadhi ya kubuni mzunguko, kitu ambacho sikuwa nimefanya kabla. Chini ni video ya kifaa hicho kikifanya kazi. Katika video hiyo, ninadhibiti balbu mbili za taa, na pia blender, kutoka kwa kompyuta yangu. (Kumbuka: video haina sauti) Kanuni na vifaa vifaa vilitolewa kwenye ubao wa mbao wa kawaida kama inavyoonyeshwa katika picha hapa chini. Kumbuka kwamba nguvu zote ni kweli mtiririko kupitia breadboard. Hii ni pengine si wazo nzuri sana, lakini kama sisi ni kushughulika na tu amp au mbili zaidi, nilidhani inaweza kuwa kuridhisha. I've pamoja wote juu ya switch on-off, na 5A circuit breaker kwa ajili ya usalama. Schematic hapa chini inaonyesha mzunguko kuu kutumika katika kudhibiti nguvu kwa taa na receptacle. Mzunguko huu ni karibu sawa na ile iliyopatikana katika karatasi ya data ya MOC3022M. Mfumo wa msingi ni kama ifuatavyo: - Opto-kujitenga triac (MOC3022M) hupokea pembejeo kutoka Arduino pato pini. - Hii inaruhusu voltage bidirectional juu ya upande triac (pins 6 na 4). Mzunguko wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme wa umeme. - Voltage hii inageuka juu ya BTB08 triac (T1) kupitia pini yake ya mlango. Hii inaruhusu conduction kupitia triac na kupitia mzigo. Baadhi ya maelezo na equations: - BTB08 triac kuchaguliwa ni <unk>snubberless<unk>. Kwa hiyo inaweza kuwa si muhimu kujumuisha mzunguko snubber kwa ajili ya mzigo inductive. Mimi si ni pamoja na moja, na kama inavyoonekana katika video, inaonekana kazi ok kwa ajili ya blender motor. Arduino ya nje (VCC) ni 5V Kwa hiyo, max sasa kupitia upande wa kushoto wa MOC3022M ni 5V = 12.8mA, na voltage ya kilele ya AC ni karibu 170V. Kwa hiyo, sasa kupitia upande wa kulia wa MOC3022M ni mdogo kwa 170V 180O = 0.94A. Hii ni chini ya kiwango cha juu cha 1A kilichoorodheshwa katika karatasi ya data - Triac T1 daima inafanya kazi katika quadrants I au III. Ikiwa voltage haijawekwa upande wa kushoto wa MOC302M, mtiririko wa sasa wa mtandao kupitia T1 triac utasimama wakati voltage ya mtandao inafikia makutano ya hatua ya sifuri. Suluhisho ni kuondoka pato Arduino juu, ambayo kazi tu kama unataka mzunguko mains kabisa juu. Hata hivyo, kwa dimming, lazima kujua wakati zero msalaba hutokea. Mzunguko huu inaruhusu Arduino pembe ya kuingia kusajili wakati AC mains voltage ni katika chanya nusu-wimbi. - Negative nusu-wimbi ni kuondolewa na diode. RMS voltage ni 60V, na resistors nne ni sawa na 10kV. Kwa hiyo, RMS sasa ni 60V-10KW = 6mA. Sababu ya resistors kadhaa ni kupunguza nguvu katika kila resistor. Vipimo vya voltage katika kila resistor ni 30V, kwa hiyo dissipation ya nguvu ni 30V (30V) = 90mW.Kumbuka kwamba kugundua kwa Arduino ya mwanzo wa nusu ya chanya ya sine wave ni kucheleweshwa, na kugundua mwisho ni mapema sana. Chini ni mchoro uliozidi kiasi. Mfuatano wa AVR ni kipimo cha AVR cha wakati cha AVR, ambacho kinahesabu ticks kati ya makali ya kupanda na kushuka. Kwa mfano, kwa upande wa juu na chini counter, unaweza kupata 60Hz. Ili kupunguza mwangaza, triac lazima iwashe katika hatua maalum wakati wa wimbi la sine. Hatua hiyo inahesabiwa katika kanuni. Kwa hiyo, timer kwa ajili ya kugeuka juu ya triac lazima kuhifadhiwa katika sync na timer kwa ajili ya zero-msalaba kugundua. Hii ni kufanyika kwa kurekebisha awamu-kuhama-timer <unk>s counter usajili wakati microcontroller hugundua makali kuongezeka. Thamani zaidi sahihi kwa ajili ya awamu-kuhamisha counter inaweza kuwa takriban, kudhani symmetry sasa katika mchoro (tazama code). Hii inaweza pia kufanyika kwa ajili ya kuanguka makali pia, ingawa ingekuwa zinahitaji code zaidi katika utaratibu wa kukatiza, ambayo kwa ujumla ni kitu mbaya. Kwa sababu ya tabia ya zero-msalaba, hata kama pato Arduino ni kushoto kabisa juu, kuna baadhi ya kuchelewesha katika kugeuka juu ya triac kutokana na mlango sasa na voltage required trigger triac. "Kama ilivyoelezwa hapo juu, ""mzunguko wa mlango wa triac ni 50mA (kutoka karatasi ya data) - voltage ya mlango ni 1.3V - voltage ya hali ya detector ya opto-isolator ni 3V max - kwa hivyo, voltage ya umeme ya AC lazima ifike 180V (0.05A) + 3V + 1.3V = 13.3V - Kuchukua sinus ya 13.3V = 170V inatoa mabadiliko ya awamu ya 4.5 ° au 0.0785 radians." Soma zaidi: BennyP's Light Contraption