BLYNK
BLYNK.IO       ๐Ÿ“ฒ GETTING STARTED       ๐Ÿ“— DOCS       ๐Ÿ‘‰ SKETCH BUILDER

ESP32 with Blynk 2.0 facing problem to drive high power 3W led in parallel

void Sync()
{
  CH1Period = CH1End - CH1Start;
  CH2Period = CH2End - CH2Start;
  CH3Period = CH3End - CH3Start;
  CH4Period = CH4End - CH4Start;
  CH5Period = CH5End - CH5Start;
  CH6Period = CH6End - CH6Start;
}
}

//CHANNEL 2/////////////////////////////////////////////////////////////////////
BLYNK_WRITE(V8)   //Start time
{
  CH2S = param.asInt();
  Blynk.virtualWrite(V8, CH2S);
  CH2Start = CH2S*60;
  ////EEPROM.put(25, CH2Start);
  ////EEPROM.commit();
}

BLYNK_WRITE(V9)   //End time
{
  CH2E = param.asInt();
  Blynk.virtualWrite(V9, CH2E);
  CH2End = CH2E*60;
  ////EEPROM.put(30, CH2End);
  ////EEPROM.commit();
}

BLYNK_WRITE(V10)   //FadeIn time
{
  FadeINmin2 = param.asInt();
  Blynk.virtualWrite(V10, FadeINmin2);
  FadeINsecs2 = FadeINmin2*60;
  ////EEPROM.put(35, FadeINsecs2);
  ////EEPROM.commit();
}

BLYNK_WRITE(V11)   //FadeOut time
{
  FadeOUTmin2 = param.asInt();
  Blynk.virtualWrite(V11, FadeOUTmin2);
  FadeOUTsecs2 = FadeOUTmin2*60;
  ////EEPROM.put(40, FadeOUTsecs2);
  ////EEPROM.commit();
}

BLYNK_WRITE(V12)   //Intensity value 
{
  maxPWM2 = param.asInt();
  Blynk.virtualWrite(V12, maxPWM2);
}

BLYNK_WRITE(V56)   //Saved Intensity value 
{
  svPWM2 = param.asInt();
  Blynk.virtualWrite(V56, svPWM2);
  ////EEPROM.put(45, svsvPWM2);
  ////EEPROM.commit();
}

BLYNK_READ(V39)
{
  Blynk.virtualWrite(V39, C2prog);
}

//CHANNEL 3/////////////////////////////////////////////////////////////////////
BLYNK_WRITE(V14)   //Start time
{
  CH3S = param.asInt();
  Blynk.virtualWrite(V14, CH3S);
  CH3Start = CH3S*60;
  ////EEPROM.put(50, CH3Start);
  ////EEPROM.commit();
}

BLYNK_WRITE(V15)   //End time
{
  CH3E = param.asInt();
  Blynk.virtualWrite(V15, CH3E);
  CH3End = CH3E*60;
  ////EEPROM.put(55, CH3End);
  ////EEPROM.commit();
}

BLYNK_WRITE(V16)   //FadeIn time
{
  FadeINmin3 = param.asInt();
  Blynk.virtualWrite(V16, FadeINmin3);
  FadeINsecs3 = FadeINmin3*60;
  ////EEPROM.put(60, FadeINsecs3);
  ////EEPROM.commit();
}

BLYNK_WRITE(V17)   //FadeOut time
{
  FadeOUTmin3 = param.asInt();
  Blynk.virtualWrite(V17, FadeOUTmin3);
  FadeOUTsecs3 = FadeOUTmin3*60;
  ////EEPROM.put(65, FadeOUTsecs3);
  ////EEPROM.commit();
}

BLYNK_WRITE(V18)   //Intensity value 
{
  maxPWM3 = param.asInt();
  Blynk.virtualWrite(V18, maxPWM3);
}

BLYNK_WRITE(V57)   //Saved Intensity value 
{
  svPWM3 = param.asInt();
  Blynk.virtualWrite(V57, svPWM3);
  ////EEPROM.put(70, PWM3);
  ////EEPROM.commit();
}

BLYNK_READ(V40)
{
  Blynk.virtualWrite(V40, C3prog);
}

//CHANNEL 4/////////////////////////////////////////////////////////////////////
BLYNK_WRITE(V20)   //Start time
{
  CH4S = param.asInt();
  Blynk.virtualWrite(V20, CH4S);
  CH4Start = CH4S*60;
  ////EEPROM.put(75, CH4Start);
  ////EEPROM.commit();
}

BLYNK_WRITE(V21)   //End time
{
  CH4E = param.asInt();
  Blynk.virtualWrite(V21, CH4E);
  CH4End = CH4E*60;
  ////EEPROM.put(80, CH4End);
  ////EEPROM.commit();
}

BLYNK_WRITE(V22)   //FadeIn time
{
  FadeINmin4 = param.asInt();
  Blynk.virtualWrite(V22, FadeINmin4);
  FadeINsecs4 = FadeINmin4*60;
  ////EEPROM.put(85, FadeINsecs4);
  //EEPROM.commit();
}

BLYNK_WRITE(V23)   //FadeOut time
{
  FadeOUTmin4 = param.asInt();
  Blynk.virtualWrite(V23, FadeOUTmin4);
  FadeOUTsecs4 = FadeOUTmin4*60;
  //EEPROM.put(90, FadeOUTsecs4);
  //EEPROM.commit();
}

BLYNK_WRITE(V24)   //Intensity value 
{
  maxPWM4 = param.asInt();
  Blynk.virtualWrite(V24, maxPWM4);
}

BLYNK_WRITE(V58)   //Saved Intensity value 
{
  svPWM4 = param.asInt();
  Blynk.virtualWrite(V58, svPWM4);
  //EEPROM.put(95, PWM4);
  //EEPROM.commit();
}

BLYNK_READ(V41)
{
  Blynk.virtualWrite(V41, C4prog);
}

This my code for my 8 channel Led lighting. Try to use Blynk only as a method to get the info and write your code in a way that the lighting can run without the need to keep referring back to Blynk. The reason if the internet drops the lighting schedule will continue as normal. Hope this helps.


void LEDFunction()
{
  CH1Period = CH1End - CH1Start;
  CH2Period = CH2End - CH2Start;
  CH3Period = CH3End - CH3Start;
  CH4Period = CH4End - CH4Start;
  CH5Period = CH5End - CH5Start;
  CH6Period = CH6End - CH6Start;

  if (TempAlarm == false)
  {
    if (BTNmode == 1)
    {
      SetLed(0, 8, TotalSecs, CH1Start, FadeINsecs1, CH1Period, FadeOUTsecs1, CH1End, svPWM1, V38);   //UV 
      SetLed(1, 9, TotalSecs, CH2Start, FadeINsecs2, CH2Period, FadeOUTsecs2, CH2End, svPWM2, V39);   //RBLUE/BLUE
      SetLed(2, 10, TotalSecs, CH3Start, FadeINsecs3, CH3Period, FadeOUTsecs3, CH3End, svPWM3, V40);  //BLUE
      SetLed(3, 11, TotalSecs, CH4Start, FadeINsecs4, CH4Period, FadeOUTsecs4, CH4End, svPWM4, V41);  //OCW
      SetLed(4, 12, TotalSecs, CH5Start, FadeINsecs5, CH5Period, FadeOUTsecs5, CH5End, svPWM5, V42);  //RGB
      SetLed(5, 13, TotalSecs, CH6Start, FadeINsecs6, CH6Period, FadeOUTsecs6, CH6End, svPWM6, V43);  //LIME
    }
    else
    {
      pwm.setPin(0, maxPWM1, false);
      pwm.setPin(1, maxPWM2, false);
      pwm.setPin(2, maxPWM3, false);
      pwm.setPin(3, maxPWM4, false);
      pwm.setPin(4, maxPWM5, false);
      pwm.setPin(5, maxPWM6, false);
  
      pwm.setPin(8, maxPWM1, false);
      pwm.setPin(9, maxPWM2, false);
      pwm.setPin(10, maxPWM3, false);
      pwm.setPin(11, maxPWM4, false);
      pwm.setPin(12, maxPWM5, false);
      pwm.setPin(13, maxPWM6, false);
  
      int prog1 = round((maxPWM1*100)/4096);
      int prog2 = round((maxPWM2*100)/4096);
      int prog3 = round((maxPWM3*100)/4096);
      int prog4 = round((maxPWM4*100)/4096);
      int prog5 = round((maxPWM5*100)/4096);
      int prog6 = round((maxPWM6*100)/4096);
      Blynk.virtualWrite (V38, prog1);
      Blynk.virtualWrite (V39, prog2);
      Blynk.virtualWrite (V40, prog3);
      Blynk.virtualWrite (V41, prog4);
      Blynk.virtualWrite (V42, prog5);
      Blynk.virtualWrite (V43, prog6);
    }
  }
  else
  {
    pwm.setPin(0, 600, false);
    pwm.setPin(1, 600, false);
    pwm.setPin(2, 600, false);
    pwm.setPin(3, 600, false);
    pwm.setPin(4, 600, false);
    pwm.setPin(5, 600, false);

    pwm.setPin(8, 600, false);
    pwm.setPin(9, 600, false);
    pwm.setPin(10, 600, false);
    pwm.setPin(11, 600, false);
    pwm.setPin(12, 600, false);
    pwm.setPin(13, 600, false);

    Blynk.virtualWrite (V38, 30);
    Blynk.virtualWrite (V39, 30);
    Blynk.virtualWrite (V40, 30);
    Blynk.virtualWrite (V41, 30);
    Blynk.virtualWrite (V42, 30);
    Blynk.virtualWrite (V43, 30);
  }
}

void GraphData()
{
  Average = (C1prog + C2prog + C3prog + C4prog + C5prog + C6prog);
  TotalPWM = (svPWM1 + svPWM2 + svPWM3 + svPWM4 + svPWM5 + svPWM6);
  TotalAverage = (Average/TotalPWM) * 100;
  Blynk.virtualWrite(V100, TotalAverage);
}
    
////////////////////////////////////////////////////////////////////////////////
void SetLed(int fpin,                 //Pin number
            int fpin2,                //Slave device pin number
            unsigned long ftime,      //Current time in seconds
            unsigned long fstart,     //Start time of LED channel
            unsigned long ffadeUP,    //Fadeup period in seconds
            unsigned long fperiod,    //Total photo period in seconds
            unsigned long ffadeDOWN,  //Fadedown period in seconds
            unsigned long fstop,      //Stop time of LED channel
            unsigned long fpwm,       //Max value of brightness
            int fVpin)                //ProgressBar
            
{
  //ON PERIOD//
  if (ftime > fstart + ffadeUP && ftime <= fstart + fperiod - ffadeDOWN)
  {
    pwm.setPin(fpin, fpwm, false);
    pwm.setPin(fpin2, fpwm, false);
    progress = round(fpwm*100/4096);
    Blynk.virtualWrite (fVpin, progress);
  }
  //FADEUP PERIOD//
  else if (ftime > fstart && ftime <= fstart + ffadeUP)
  {
    unsigned long fadeSecs = ftime - fstart;
    brightness = fpwm * fadeSecs / ffadeUP;
    pwm.setPin(fpin, brightness, false);
    pwm.setPin(fpin2, brightness, false);
    progress = round(brightness*100/4096);
    Blynk.virtualWrite (fVpin, progress);
  }
  //FADEDOWN PERIOD
  else if (ftime > fstart + fperiod - ffadeDOWN && ftime <= fstart + fperiod)
  {
    unsigned long fadeSecs = fstop - ftime;
    brightness = fpwm * fadeSecs / ffadeDOWN;
    pwm.setPin(fpin, brightness, false);
    pwm.setPin(fpin2, brightness, false);
    progress = round(brightness*100/4096);
    Blynk.virtualWrite (fVpin, progress);
  }
  //OFF PERIOD//
  else if (ftime > fstop || ftime < fstart)
  {
    pwm.setPin(fpin, 0, false);
    pwm.setPin(fpin2, 0, false);
    Blynk.virtualWrite(fVpin, 0);
  }
}

I forgot this part of the code. Quite important

1 Like

Thanks proietti. Can you please send the complete code in on comments. It will help me a lot.

What do you mean on comments?

He means,

Explain important lines in the code with โ€œ//this line does thisโ€œ

I know, that is a functioning code which has been running for years, I do not have time to go through my old code to put comments on.

1 Like

Hi proietti,

Can you please send me the code file in a mail? say.hlw@gmail.com

Thank You

Dear Proietti,

I am facing problem to combine your 3 commentโ€™s code together in one file.

1st comment seems a complete code itself, 2nd and 3rd comment seems to be a part of a complete code.
So, it would be great if you can send me the actual code in actual file through mail. it would be a great help.

Thanks