Need help with dimming with blynk

Hi Toro,
I did that too, no luck though. :sob:

Hello,
Can i ask why you have two zerocross functions?
Light bulbs are connected to different phases? if not you need only one zerocross function
Your sketch will work fine only for one Light bulb.

Hi 777,
I do not connect the bulbs to different phases and yes, you are right, one zero-cross should be enough. Though, I have tries and the result is the same as described above. To be more explicit, if I dim the bulb that has the last attachInterrupt() call in my code (see above) it works fine. If I dim though the others, all the bulbs dim together and if I reach the end of the slider, they start to flicker and the Arduino gets blocked. Another aspect I have noticed, If I dim the first bulb (and in this case both bulbs dims) so basically I slide the first slider and let them anywhere in between the min and max, when sliding then the second slider, I get the same behavior as described aboveā€¦

Secondly, you are right, with only one dimmer the sketch works like a charm. Unfortunately fI need to dim 8 different light zones in the house and I would like to use the same Arduino board to control them.

Thank you,

Hi again,
i have similar project, but its not ready for now and i write code for esp32 and esp8266.
So i can copy part of the code here for example, but i dont know how the code will work on arduino mega.
For my project i use the Ticker library created by sstaub, and I managed to control the thyristor.

Hi 777,
if you can, please share your code. I would love to see your idea.

Thank you.

Have you considered buying an 8 channel dimmer board, rather than using 8x 1 channel dimmers?

Pete.

So here,

#include <Arduino.h>
#include "Ticker.h"

volatile int tic, Dimmer, setDimmer;
volatile int flag1, flag2;

void tiker_interrupt();
void pulse_trig();
void analogport();


Ticker timer1(tiker_interrupt, 50, 0, MICROS_MICROS);
Ticker timer2(pulse_trig, 220,0 , MICROS_MICROS);
Ticker timer3(analogport, 1000);

void tiker_interrupt(){
    tic++;

    if (tic > Dimmer){
        digitalWrite(27, 1);
        timer2.start();
        timer1.stop();
    }

}

void zero_cross(){
    digitalWrite(27, 0);
    tic = 0;
    timer1.start();
}

void pulse_trig(){
    digitalWrite(27, 0);
    timer2.stop();
}

void analogport(){
    Dimmer = analogRead(4);
    Dimmer = map(Dimmer, 0, 4028, 0, 200);
    Serial.println(String(" ") + Dimmer + " " + tic +" " + flag2);
}
void setup() {
    Serial.begin(115200);
    delay(500);
    pinMode(4, INPUT); //analog potentiometer pin
    pinMode(27, OUTPUT);
    digitalWrite(27, 1);// pin 27 triac gate pin 
    delay(300);
    attachInterrupt(17, zero_cross, RISING); //pin 17 zerocross 
    timer3.start();
}

void loop() {
    timer1.update();
    timer2.update();
    timer3.update();
}

Hi Pete,
I did, unfortunately the complexity of the circuit does not allow me to work with one of those. Why that? Because I have done a separate electrical circuit for each zone (each bulb) to be able to light on and off the bulbs from two different normal wall switches, and I will be able to switch on and off the bulb from Blynk as well. So I can switch on and off the lights from both electrical switches as from the Blynk app through a relay and then, this voltage goes into the dimmer to dim the bulb. Of course there is more logic in there but this is simple to handle. I draw a schematic in the picture below.
Therefore I cannot use one board with 8 dimmers on it because that type of board has only one input and 8 outputs.

Thank you 777 for sharing,
from what I see from your code, youā€™re using a mechanical potentiometer to adjust the light intensity (am I right?). I am using an electronic device for that.
I will try to understand your code entirely to see if I can reuse something from there if you allow me that.

Thank you.

Yes basic code use mechanical potentiometer, this is not the full version of my code. You can use it.

Well, I can think of several potential solutions to thatā€¦

  1. Switch the dimmed output to each bulb using the light switches and relays

  2. If dimming to zero actually turns the bulb off then you have other possibilities about how to control your lighting using your existing circuitry.

Pete.

Hi Pete,
unfortunately the logic of the circuit as I built does not allow me to do this trick. I monitor each bulb to see when is turned on or off and, based on that there are some actions I take. I use to monitor 220V on the bulb this (https://www.aliexpress.com/item/AC-220V-8-Channel-MCU-TTL-Level-8-Ch-Optocoupler-Isolation-Test-Board-Isolated-Detection-Tester/32849914729.html?spm=a2g0s.9042311.0.0.27424c4dYryObz) device. It senses 220V presence and dies not behave well with dimmed voltages (altered sinus waves).
I found out though other dimmers with hardware zero-cross detection where Arduino control the intensity over PWM without carrying about zero-cross. I will try them and see whatā€™s the result.