AC Dimmer ESP8266 Shield Arduino Pro Micro

That’s very good.I like it and I want to get full project for case study.Please sent the detail of the project to my e-mail pokamon66@gmail.com.Thank you.

i Successfully make it but the Bulb is having Voltage fluctuation once i try to dim it, is there any solving for this issue

i am using ardunio UNO REV3 in my project, and the ESP8266 i am not using it as below

#define BLYNK_PRINT Serial // Enables Serial Monitor
#include SPI.h
#include Ethernet.h
#include BlynkSimpleEthernet.h
#include SoftwareSerial.h
SoftwareSerial SwSerial(10, 11);
#include TimerOne.h
volatile int i=0; // Variable to use as a counter volatile as it is in an interrupt
volatile boolean zero_cross=0; // Boolean to store a “switch” to tell us if we have crossed zero
int AC_pin = 6; // Output to Opto Triac
int brightness = 128; // Dimming level (0-128) 0 = on, 128 = 0ff
int freqStep = 75; // This is the delay-per-brightness step in microseconds.

char auth[] = “711f298ad82742d2af1ae4c8c00d0076”; // Put your A.th Token here. (see Step 3 above)

IPAddress server_ip (10, 0, 0, 10);

// Mac address should be different for each device in your LAN
byte arduino_mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDA, 0x02};
IPAddress arduino_ip ( 192, 168,1, 180);
IPAddress dns_ip (8, 8, 8, 8);
IPAddress gateway_ip ( 192, 168, 1, 1);
IPAddress subnet_mask(255, 255, 255, 0);

void setup() {
pinMode(AC_pin, OUTPUT); // Set the Triac pin as output
attachInterrupt(1, zero_cross_detect, RISING); // Attach an Interupt to Pin 3 (interupt 0)
Timer1.initialize(freqStep); // Initialize TimerOne library
Timer1.attachInterrupt(dim_check, freqStep);
Serial.begin(9600); // See the connection status in Serial Monitor
delay(10);
SwSerial.begin(9600);
delay(10);
Blynk.begin(auth, “blynk-cloud.com”, 8442, arduino_ip, dns_ip, gateway_ip, subnet_mask, arduino_mac);
delay(10);

}

BLYNK_WRITE(V1)// slider brillo
{
int brillo = param.asDouble();
brightness = 128./1023.;
brightness=brillo;
Serial.print("V1 Slider value is: ");
Serial.println(brightness);
}

void zero_cross_detect() {
zero_cross = true;
i=0;
digitalWrite(AC_pin, LOW); // turn off TRIAC (and AC)
}

// Turn on the TRIAC at the appropriate time
void dim_check() {
if(zero_cross == true) {
if(i>=brightness) {
digitalWrite(AC_pin, HIGH); // turn on light
i=0; // reset time step counter
zero_cross = false; //reset zero cross detection
delay(500);
}
else {
i= i+1; // increment time step counter
}
}
}

void loop() {
Blynk.run();
}

Hi @msamiryusuf,
Delay(500)??
Try to avoid delays in your code.

i will try your code with my arduino yun but it doesn’t work. Could you advise me for arduino yun. Ii will change to another code. It’s work, it can dim but it has to change “dimming” by myself. i will try put blynk_write to void zero cross to inside blank write. but it doesn’t work.

#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Bridge.h>
#include <BlynkSimpleYun.h>
#include <SimpleTimer.h>

int AC_LOAD = 7; // Output to Opto Triac pin
int dimming; // Dimming level (0-128) 0 = ON, 128 = OFF

char auth = “”;

void setup()
{
Serial.begin(115200);
Blynk.begin(auth);
delay(10);
pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
attachInterrupt(0, zero_crosss_int, RISING); // Choose the zero cross interrupt # from the table above
}

BLYNK_WRITE(V1)// slider brillo
{
int dim = param.asInt();
dimming = dim;
}

//the interrupt function must take no parameters and return nothing
void zero_crosss_int() //function to be fired at the zero crossing to dim the light
{
// Firing angle calculation : 1 full 50Hz wave =1/50=20ms
// Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle)
// For 60Hz => 8.33ms (10.000/120)
// 10ms=10000us
// (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65

int dimtime = (75*dimming); // For 60Hz =>65
delayMicroseconds(dimtime); // Wait till firing the TRIAC
digitalWrite(AC_LOAD, HIGH); // Fire the TRIAC
delayMicroseconds(10); // triac On propogation delay (for 60Hz use 8.33)
digitalWrite(AC_LOAD, LOW); // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop() {
Blynk.run();
}

Please, use < / > for code formatting. This way I will be able to read your code properly.

thank you for quick response and sorry make mistake about put coding.

#define BLYNK_PRINT Serial 
#include <SPI.h>
#include <Bridge.h>
#include <BlynkSimpleYun.h>
#include <SimpleTimer.h>

int AC_LOAD = 7;    // Output to Opto Triac pin
int dimming;  // Dimming level (0-128)  0 = ON, 128 = OFF

char auth[] = "";

void setup()
{
  Serial.begin(115200);
  Blynk.begin(auth);
  delay(10);
  pinMode(AC_LOAD, OUTPUT);// Set AC Load pin as output
  attachInterrupt(0, zero_crosss_int, RISING);  // Choose the zero cross interrupt # from the table above
}

BLYNK_WRITE(V1)//      slider brillo
{
 int dim = param.asInt();
 dimming = dim;
 Serial.print("Got a value: ");
 Serial.println(param.asStr());
}

//the interrupt function must take no parameters and return nothing
void zero_crosss_int()  //function to be fired at the zero crossing to dim the light
{
  // Firing angle calculation : 1 full 50Hz wave =1/50=20ms 
  // Every zerocrossing thus: (50Hz)-> 10ms (1/2 Cycle) 
  // For 60Hz => 8.33ms (10.000/120)
  // 10ms=10000us
  // (10000us - 10us) / 128 = 75 (Approx) For 60Hz =>65

  int dimtime = (75*dimming);    // For 60Hz =>65    
  delayMicroseconds(dimtime);    // Wait till firing the TRIAC
  digitalWrite(AC_LOAD, HIGH);   // Fire the TRIAC
  delayMicroseconds(10);         // triac On propogation delay (for 60Hz use 8.33)
  digitalWrite(AC_LOAD, LOW);    // No longer trigger the TRIAC (the next zero crossing will swith it off) TRIAC
}

void loop()  {
 Blynk.run();
}

Your code is not complete, could you try the code I posted and adapt it to the Arduino Yun? This should be the easiest way to do it work.

Yes i will try your code and adapt to yun already but bad luck it doesn’t work. Its stuck no light. So i’ve to change another to code. This code has worked but i cannot combine with blynk code. I think if i can use blynk write to variable “dimming”. Coz’ when i change value in “dimming” light is dim.

i already remove the delay, and i get much of fluctuation in the output and the Bulb is dimming and is also flashing in the same time

any solution

Regards

thanks for share. I build it but I have a problem with slider widget. the widget is working contrariwise ! when I set slider to max, dimmer set to low and when set slider to min, dimmer go to max

Hi @ErfanDL, I guess you should swap the values of the slider. Give it a try!
HTH

1 Like

what about?

are you have any pcb circuit?

@samisamixp FYI, you are replying to a post on a topic that is over a year old :wink: Please take note of the time date stamps (hover over them for full details) before posting, Thank you.