├── .gitattributes └── AC_Dimmer_using_Blynk └── AC_Dimmer_using_Blynk.ino /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /AC_Dimmer_using_Blynk/AC_Dimmer_using_Blynk.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 BLYNK_PRINT Serial 12 | #include 13 | #include 14 | 15 | #define triacPulse 4 //D2 16 | #define ZVC 12 //D6 17 | 18 | int Slider_Value; 19 | int dimming; 20 | int x = 0; 21 | 22 | char auth[] = "AUTH TOKEN"; // You should get Auth Token in the Blynk App. 23 | // Go to the Project Settings (nut icon) in the Blynk app or check your email for auth token. 24 | 25 | char ssid[] = "SSID"; // Your WiFi credentials. 26 | char pass[] = "PASS"; // Set password to "" for open networks. 27 | 28 | 29 | BLYNK_WRITE(V1) // function to assign value to variable Slider_Value whenever slider changes position 30 | { 31 | Slider_Value = param.asInt(); // assigning incoming value from pin V1 to a variable 32 | } 33 | 34 | 35 | void setup() 36 | { 37 | 38 | pinMode(ZVC, INPUT_PULLUP); 39 | //digitalWrite(2, INPUT_PULLUP); // pull up 40 | pinMode(triacPulse, OUTPUT); 41 | Serial.begin(9600); 42 | Blynk.begin(auth, ssid, pass); 43 | attachInterrupt(digitalPinToInterrupt(ZVC), acon, FALLING); // attach Interrupt at PIN2 44 | } 45 | 46 | 47 | 48 | void loop() 49 | { 50 | Blynk.run(); 51 | // When the switch is closed 52 | dimming = map(Slider_Value, 0, 100, 7200, 200); //0.2ms 7.2 ms 53 | 54 | } 55 | 56 | void acon() 57 | { 58 | // Serial.println("REad"); 59 | 60 | delayMicroseconds(dimming); // read AD0 61 | digitalWrite(triacPulse, HIGH); 62 | 63 | delayMicroseconds(50); //delay 50 uSec on output pulse to turn on triac 64 | digitalWrite(triacPulse, LOW); 65 | 66 | // Serial.println(digitalRead(triacPulse)); 67 | } 68 | --------------------------------------------------------------------------------