Light dimming using triac and 8051 microcontroller

Discussion in 'The Projects Forum' started by raghurocks, Jul 30, 2012.

  1. raghurocks

    Thread Starter New Member

    Jun 26, 2012
    Hai every one,

    I have been working under varying the brightness of the ac loads using the triac and a microcontroller.
    I have written code for it and I tried for the output on the simulator as we cannot see the dimming on the simulator I have seen the output voltage which is varying for different levels but practically I am not getting the output which I am getting on the simulator

    Here is the schematics I have done......


    and the code I have written is........

    Code ( (Unknown Language)):
    2.  org 00h
    3.  MOV P2,#00H
    4.  MOV P1,#00H
    5.  MOV TMOD,#01H
    6.  MOV SCON,#50H
    7.  MAIN:
    8.     MOV A,P1;// to take data from the switches into the accumulator
    9. LOOP1:
    10. CJNE A,#01H,LOOP2
    11.     S1:JNB P2.1,S1
    12. SETB P2.0
    13. MOV TL0,#0A4H//0.1MSEC  ON
    14. MOV TH0,#0FFH
    15. CALL DELAY
    16. CLR P2.0
    17. MOV TL0,#3DH//9.1MSEC  OFF
    18. MOV TH0,#0DFH
    19. CALL DELAY
    20. LJMP MAIN
    23. LOOP2:
    24. CJNE A,#02H,LOOP3
    25.     S2:JNB P2.1,S2
    26. CLR P2.0
    27. MOV TL0,#07BH//0.7mSEC   OFF to set delay angle for 0.7msec
    28. MOV TH0,#0FDH
    29. CALL DELAY
    30. SETB P2.0
    31. MOV TL0,#0A4H//0.1MSEC ON trigger for 100us
    32. MOV TH0,#0FFH
    33. CALL DELAY
    34. CLR P2.0
    35. MOV TL0,#0E1H//9.2MSEC OFF
    36. MOV TH0,#0DEH
    37. CALL DELAY
    38. LJMP MAIN
    40. LOOP3:
    41. CJNE A,#03H,LOOP4
    42.     S3:JNB P2.1,S3
    43. CLR P2.0
    44. MOV TL0,#0F6H//1.4MSEC   OFF to set delay angle for 1.4msec
    45. MOV TH0,#0FAH
    46. CALL DELAY
    47. SETB P2.0
    48. MOV TL0,#0A4H//0.1MSEC ON trigger for 100us and so on
    49. MOV TH0,#0FFH
    50. CALL DELAY
    51. CLR P2.0
    52. MOV TL0,#066H//8.5MSEC OFF
    53. MOV TH0,#0E1H
    54. CALL DELAY
    55. LJMP MAIN
    57. LOOP4:
    58. CJNE A,#04H,LOOP5
    59.     S4:JNB P2.1,S4
    60. CLR P2.0
    61. MOV TL0,#71H//2.1MSEC    OFF
    62. MOV TH0,#0F8H
    63. CALL DELAY
    64. SETB P2.0
    65. MOV TL0,#0A4H//0.1MSEC ON
    66. MOV TH0,#0FFH
    67. CALL DELAY
    68. CLR P2.0
    69. MOV TL0,#0ECH//7.8MSEC OFF
    70. MOV TH0,#0E3H
    71. CALL DELAY
    72. LJMP MAIN
    74. LOOP5:
    75. CJNE A,#05H,LOOP6
    76.     S5:JNB P2.1,S5
    77. CLR P2.0
    78. MOV TL0,#0ECH//2.8MSEC   OFF
    79. MOV TH0,#0F5H
    80. CALL DELAY
    81. SETB P2.0
    82. MOV TL0,#0A4H//0.1MSEC ON
    83. MOV TH0,#0FFH
    84. CALL DELAY
    85. CLR P2.0
    86. MOV TL0,#71H//7.1MSEC OFF
    87. MOV TH0,#0E6H
    88. CALL DELAY
    89. LJMP MAIN
    92. LOOP6:
    93. CJNE A,#06H,LOOP7
    94.     S6:JNB P2.1,S6
    95. CLR P2.0
    96. MOV TL0,#66H//3.5MSEC    OFF
    97. MOV TH0,#0F3H
    98. CALL DELAY
    99. SETB P2.0
    100. MOV TL0,#0A4H//0.1MSEC ON
    101. MOV TH0,#0FFH
    102. CALL DELAY
    103. CLR P2.0
    104. MOV TL0,#0F6H//6.4MSEC OFF
    105. MOV TH0,#0E8H
    106. CALL DELAY
    107. LJMP MAIN
    109. LOOP7:
    110. CJNE A,#07H,LOOP8
    111.     S7:JNB P2.1,S7
    112. CLR P2.0
    113. MOV TL0,#0E1H//4.2MSEC   OFF
    114. MOV TH0,#0F0H
    115. CALL DELAY
    116. SETB P2.0
    117. MOV TL0,#0A4H//0.1MSEC ON
    118. MOV TH0,#0FFH
    119. CALL DELAY
    120. CLR P2.0
    121. MOV TL0,#7BH//5.7MSEC OFF
    122. MOV TH0,#0EBH
    123. CALL DELAY
    124. LJMP MAIN
    126. LOOP8:
    127. CJNE A,#08H,LOOP9
    128.     S8:JNB P2.1,S8
    129. CLR P2.0
    130. MOV TL0,#5CH//4.9MSEC    OFF
    131. MOV TH0,#0EEH
    132. CALL DELAY
    133. SETB P2.0
    134. MOV TL0,#0A4H//0.1MSEC ON
    135. MOV TH0,#0FFH
    136. CALL DELAY
    137. CLR P2.0
    138. MOV TL0,#00H//5.0MSEC OFF
    139. MOV TH0,#0EEH
    140. CALL DELAY
    141. LJMP MAIN
    143. LOOP9:
    144. CJNE A,#09H,LOOP10
    145.     S9:JNB P2.1,S9
    146. CLR P2.0
    147. MOV TL0,#7BH//5.7MSEC    OFF
    148. MOV TH0,#0EBH
    149. CALL DELAY
    150. SETB P2.0
    151. MOV TL0,#0A4H//0.1MSEC ON
    152. MOV TH0,#0FFH
    153. CALL DELAY
    154. CLR P2.0
    155. MOV TL0,#0E1H//4.2MSEC OFF
    156. MOV TH0,#0F0H
    157. CALL DELAY
    158. LJMP MAIN
    160. LOOP10:
    161. CJNE A,#0AH,LOOP11
    162.     S10:JNB P2.1,S10
    163. CLR P2.0
    164. MOV TL0,#0F6H//6.4MSEC   OFF
    165. MOV TH0,#0E8H
    166. CALL DELAY
    167. SETB P2.0
    168. MOV TL0,#0A4H//0.1MSEC ON
    169. MOV TH0,#0FFH
    170. CALL DELAY
    171. CLR P2.0
    172. MOV TL0,#066H//3.5MSEC OFF
    173. MOV TH0,#0F3H
    174. CALL DELAY
    175. LJMP MAIN
    177. LOOP11:
    178. CJNE A,#0BH,LOOP12
    179.     S11:JNB P2.1,S11
    180. CLR P2.0
    181. MOV TL0,#71H//7.1MSEC    OFF
    182. MOV TH0,#0E6H
    183. CALL DELAY
    184. SETB P2.0
    185. MOV TL0,#0A4H//0.1MSEC ON
    186. MOV TH0,#0FFH
    187. CALL DELAY
    188. CLR P2.0
    189. MOV TL0,#0ECH//2.8MSEC OFF
    190. MOV TH0,#0F5H
    191. CALL DELAY
    192. LJMP MAIN
    194. LOOP12:
    195. CJNE A,#0CH,LOOP13
    196.     S12:JNB P2.1,S12
    197. CLR P2.0
    198. MOV TL0,#0ECH//7.8MSEC   OFF
    199. MOV TH0,#0E3H
    200. CALL DELAY
    201. SETB P2.0
    202. MOV TL0,#0A4H//0.1MSEC ON
    203. MOV TH0,#0FFH
    204. CALL DELAY
    205. CLR P2.0
    206. MOV TL0,#71H//2.1MSEC OFF
    207. MOV TH0,#0F8H
    208. CALL DELAY
    209. LJMP MAIN
    211. LOOP13:
    212. CJNE A,#0DH,LOOP14
    213.     S13:JNB P2.1,S13
    214. CLR P2.0
    215. MOV TL0,#66H//8.5MSEC    OFF
    216. MOV TH0,#0E1H
    217. CALL DELAY
    218. SETB P2.0
    219. MOV TL0,#0A4H//0.1MSEC ON
    220. MOV TH0,#0FFH
    221. CALL DELAY
    222. CLR P2.0
    223. MOV TL0,#0F6H//1.4MSEC OFF
    224. MOV TH0,#0FAH
    225. CALL DELAY
    226. LJMP MAIN
    228. LOOP14:
    229. CJNE A,#0EH,LOOP15
    230.     S14:JNB P2.1,S14
    231. CLR P2.0
    232. MOV TL0,#0E1H//9.2MSEC   OFF
    233. MOV TH0,#0DEH
    234. CALL DELAY
    235. SETB P2.0
    236. MOV TL0,#0A4H//0.1MSEC ON
    237. MOV TH0,#0FFH
    238. CALL DELAY
    239. CLR P2.0
    240. MOV TL0,#7BH//0.7MSEC OFF
    241. MOV TH0,#0FDH
    242. CALL DELAY
    243. LJMP MAIN
    246. LOOP15:
    247. CJNE A,#0FH,LOOPE
    248.     S16:JNB P2.1,S16
    249. CLR P2.0
    250. MOV TL0,#00H//10MSEC OFF
    251. MOV TH0,#0DCH
    252. CALL DELAY
    253. LJMP MAIN
    255. LOOPE:
    256.     LJMP MAIN
    258. DELAY:
    259. SETB TR0
    260. L1:JNB TF0,L1
    261. CLR TF0
    262. RET
    264. END

    The concept I have used is that if I want a less brightness the I will increase the delay time for the triac to trigger where we are increasing the delay angle and decrease the conduction there by decreasing the rms output so like wise I for example if I want 20% brightness I will give zero pulse for 8 ms and will give high pulse for 100us(0.1 ms) and then off for the remaining time like wise I have divided into 16 levels where the input I give from the switches(based on the basic concept of the TRIAC) which you can see on the above code


    The problems I am facing in the hardware are the

    1.In the schematic I am grounding the ac neutral and the T1 of the triac to the circuit ground so if I do that on the bread board the lamp is lighting at only one level and the 220 ohm resistor is burning

    2.If I don't do the grounding like that the lamp is not at lighting on

    I am unable to know where the problem persist
    1.whether am I going wrong in detecting zero or
    2.producing pwm which indeed depend on the zero crossing


    1. I don't have the CRO so how to check whether my zerocrossing detector is producing the zero crossing or not
    2. And how to check whether my microcontroller is producing the desired pwm wave or not

    Any help is very much valuable for me.......
    Thanks in advance
  2. n1ist

    Senior Member

    Mar 8, 2009
    It's hard to tell if this is just a simulation excercise or if you are really building this circuit. If the latter, be extremely careful before you kill yourself, others, or your equipment.

    No part of the high voltage circuit should be connected to ground. That includes the triac and the primary of your power transformer. The whole purpose of the transformer and optoisolator is to separate the hazardous high voltage parts of the circuit from the low voltage parts. Breadboards are not rated to handle the voltages or currents involved in AC-powered dimmers.

    Also, remember that the ground of a scope probe and the ground or negative of many power supplies are tied to the mains ground.

  3. raghurocks

    Thread Starter New Member

    Jun 26, 2012
    so instead of that we can use ac neutral as the ground for the triac side right??? @mike
  4. praondevou

    AAC Fanatic!

    Jul 9, 2011
    Just put the triac in series with the load.

    Do not connect ANY part of the circuit before the optocoupler (uC part) directly to the AC side.

    Check your zero-crossing circuit first. You need an oscilloscope for that. How does the signal look like?
  5. Sensacell


    Jun 19, 2012
    No scope makes it almost impossible to troubleshoot such a circuit.

    Waving a stick in the dark to determine what color the walls are is easier.
  6. raghurocks

    Thread Starter New Member

    Jun 26, 2012
    Thanks for all replies I have done everything in the right manner the only problem is that I don't have a CRO to trouble shoot. It is very difficult to know where I am going wrong like "am I able to detect the zero cross detection or not" ,"am I able to produce the desired output from my controller or not" that is it
  7. raghurocks

    Thread Starter New Member

    Jun 26, 2012
    I don't know why different errors are coming when I am dealing with the hardware as I stated earlier I got the desired output on the simulator but when I am doing it on the bread board it is showing different errors like I am using the port 1 for input but as per my code it should become zero first and when I give input its value should as of my input but my port values are not changing the entire port1 is high irrespective of input I give so I think this might be the reason for no dimming can anyone help me out
  8. raghurocks

    Thread Starter New Member

    Jun 26, 2012
    I have a doubt regarding the zero detection for the microcontroller..
    can we give the zerodetection output to one of the port pin and use that for further purpose or use some interrupt routine for giving the zero detection output to the microcontroller