├── .gitattributes └── AC_Dimmer_Using_Arduino └── AC_Dimmer_Using_Arduino.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /AC_Dimmer_Using_Arduino/AC_Dimmer_Using_Arduino.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * This is the code for AC Dimmer using Arduino Board. 3 | * 4 | * To watch it's full tutorial video, head on to my YouTube Channel 5 | * 6 | * http://www.youtube.com/techiesms 7 | * 8 | */ 9 | 10 | 11 | #define triacPulse 10 12 | #define SW 7 13 | #define ZVC 2 14 | 15 | int x = 0; 16 | void setup() { 17 | Serial.begin(115200); 18 | pinMode(ZVC, INPUT_PULLUP); 19 | //digitalWrite(2, INPUT_PULLUP); // pull up 20 | pinMode(A0, INPUT); 21 | pinMode(triacPulse, OUTPUT); 22 | pinMode(SW, INPUT); 23 | digitalWrite(SW, INPUT_PULLUP); 24 | } 25 | 26 | void loop() { 27 | 28 | //if (!digitalRead(SW)) 29 | { // When the switch is closed 30 | int y = analogRead(A0); 31 | x= map(y,0,1024, 200,7200); 32 | 33 | Serial.println(digitalRead(ZVC)); 34 | attachInterrupt(0, acon, FALLING); // attach Interrupt at PIN2 35 | } 36 | //else if (digitalRead(SW)) { 37 | //detachInterrupt(0); // Detach Interrupt 38 | //} 39 | } 40 | 41 | void acon() 42 | { 43 | // Serial.println("REad"); 44 | 45 | delayMicroseconds(x); // read AD0 46 | digitalWrite(triacPulse, HIGH); 47 | 48 | // Serial.println(digitalRead(triacPulse)); 49 | 50 | delayMicroseconds(50); //delay 50 uSec on output pulse to turn on triac 51 | digitalWrite(triacPulse, LOW); 52 | 53 | // Serial.println(digitalRead(triacPulse)); 54 | } 55 | --------------------------------------------------------------------------------