I can't control RGB Led Strip

Hi,

I have an RGB LED strip connected to D5,D3 & D6 as RED GREEN BLUE

I controlling this with IRLZ44N Mosfet , Arduino UNO and hc-06.

I am trying to allow the user to either manually choose a colour using a ZERGBA set to the RGB pins in split mode and the user can push a button on the app set to V1 to fade mode the RGB LED.

I have copied the fading code but need help implementing the button to switch the “mode”

I also want to add a slider to V2 to change the speed of the fade

NOTE: I already controlling led with ZeRGBa

My Fade code is;

analogWrite(5, 255);
analogWrite(3, 255);
analogWrite(6, 255);

for (i = 90; i <= 270; i++)
  rad = DEG_TO_RAD * i;
  sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
  analogWrite(3, sinOut);
  delay(15);
}
for (i = 90; i <= 270; i++)
  rad = DEG_TO_RAD * i;
  sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
  analogWrite(6, sinOut);
  delay(15);
}
for (i = 270; i >= 90; i--)
  rad = DEG_TO_RAD * i;
  sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
  analogWrite(3, sinOut);
  delay(15);
}
for (i = 90; i <= 270; i++)
  rad = DEG_TO_RAD * i;
  sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
  analogWrite(5, sinOut);
  delay(15);
}
for (i = 270; i >= 90; i--)
  rad = DEG_TO_RAD * i;
  sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
  analogWrite(6, sinOut);
  delay(15);
}
for (i = 90; i <= 270; i++)
  rad = DEG_TO_RAD * i;
  sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
  analogWrite(3, sinOut);
  delay(15);
}
for (i = 270; i >= 90; i--)
  rad = DEG_TO_RAD * i;
  sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
  analogWrite(3, sinOut);
  analogWrite(5, sinOut);
  delay(15);
}

Thanks

First of all, the title of your topic talks about an Arduino Uno and an LED strip, but the body of the text talks about a particle photon and a single RGB LED.

You can’t simply replace a single LED with a strip, otherwise you’ll burn-out whichever MCU it is that you are using. You probably need to use suitable MOSFETs to drive the LED strip.

Forum members aren’t likely to write your code for you, but if you give it your best go at combining the two pieces of code and share what you’ve done and the issues you’re experiencing (along with accurate information about your hardware) then you may get some assistance from forum members.

Pete.

I have edited the post Thank You

I did it finally but there is another problem.

If i get into Fade Mode it moving so fast because i can’t add delay.
If i add delay to fade mode the button is not working

Here it’s my code,help me please;

#define BLYNK_USE_DIRECT_CONNECT

// You could use a spare Hardware Serial on boards that have it (like Mega)
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(10, 11); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>
char auth[] = "dLcMhMvV8VbLcIEgJHrUSk8FGi-K1zvr";


int mode = 0;
float rad;
int sinOut, i;

BLYNK_WRITE(V1)
{
  int Switch = param.asInt();
  if (Switch == 0) {
    mode = !mode;
  }
}

void Fade()
{
  analogWrite(5, 255);
  analogWrite(3, 255);
  analogWrite(6, 255);

  for (i = 90; i <= 270; i++) {
    if (mode == 0)
      break;
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(3, sinOut);

  }
  for (i = 90; i <= 270; i++) {
    if (mode == 0)
      break;
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(6, sinOut);

  }
  for (i = 270; i >= 90; i--) {
    if (mode == 0)
      break;
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(3, sinOut);

  }
  for (i = 90; i <= 270; i++) {
    if (mode == 0)
      break;
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(5, sinOut);

  }
  for (i = 270; i >= 90; i--) {
    if (mode == 0)
      break;
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(6, sinOut);

  }
  for (i = 90; i <= 270; i++) {
    if (mode == 0)
      break;
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(3, sinOut);

  }
  for (i = 270; i >= 90; i--) {
    if (mode == 0)
      break;
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(3, sinOut);
    analogWrite(5, sinOut);
  }
}


void setup()
{
  // Debug console
  DebugSerial.begin(9600);
  DebugSerial.println("Waiting for connections...");
  Serial.begin(38400);
  Blynk.begin(DebugSerial, auth);
}

void loop()
{
  Blynk.run();

  switch ( mode ) {
    case 1:
      Fade();
      break;

defaul: {
      }
  }
}

Please use triple backticks for your code, not blockquote.
Triple backticks look like this:
```

Pete.

I changed this! Please help me:(

Help please…

Won’t anyone help??

The problem with doing fade routines like the one you’ve posted above is that the code takes a while to execute (that’s the whole idea, otherwise it wouldn’t be a fade).
While it’s executing, nothing else is getting any processor time, because you’re running the code on a single threaded machine. The Blynk library needs frequent processor time to prevent the connection to the server being dropped, and for Blynk commands from the app via the server to be recognised.

The simple solution is to add Blynk.run(); commands into your fade routine at key points so that they get called while the fade is happening.

The thing you’re doing in the void loop with the switch/case command isn’t very Blynk friendly either, as it has to be evaluated during every single cycle of the void loop, which should be happening hundreds if not thousands of times per second.
I’m not really clear why you aren’t calling the fade routine directly from your BLYNK_WRITE(V1) function.

Pete.

Thank you so much for yor reply Pete.

I tried this and it worked. Thank you so much again.

I’ve been working on it for a while and i changed it.

Here it’s my code;

#define BLYNK_USE_DIRECT_CONNECT
#include <SoftwareSerial.h>
SoftwareSerial DebugSerial(10, 11); // RX, TX
#define BLYNK_PRINT DebugSerial
#include <BlynkSimpleSerialBLE.h>
char auth[] = "dLcMhMvV8VbLcIEgJHrUSk8FGi-K1zvr";

#include <SimpleTimer.h>
SimpleTimer timer;

float rad;
int sinOut, i;
int fadeac;
int hiz;

int AccelSwitch;

int r;
int g;
int b;


BLYNK_WRITE(V0) //ZeRGBra Code
{
  if (!AccelSwitch == 0)
  {
    Blynk.run();
    r = param[0].asInt();
    g = param[1].asInt();
    b = param[2].asInt();
    analogWrite(5, r);
    analogWrite(3, g);
    analogWrite(6, b);
  }
}

BLYNK_WRITE(V1) // On/Off Switch
{
  AccelSwitch = param.asInt();
  if (AccelSwitch == 0) {
    analogWrite(5, 0);
    analogWrite(3, 0);
    analogWrite(6, 0);
    Blynk.setProperty(V1, "color", "#FF0000");
    while (AccelSwitch == 1);
  }
  else {
    Blynk.setProperty(V1, "color", "#00FF00");
    analogWrite(5, r);
    analogWrite(3, g);
    analogWrite(6, b);
  }
}


BLYNK_WRITE(V2) // Button for Turn On/Off Fade Mode
{
  fadeac = param.asInt();
  if (AccelSwitch == 1) {
    if (fadeac == 1)
    {
      Serial.print("fade mod");
      timer.enable(timer.setInterval(1000L, fadeTimer));
      timer.restartTimer(timer.setInterval(1000L, fadeTimer));
    } else
    {
      timer.disable(timer.setInterval(1000L, fadeTimer));
    }
  }
}

BLYNK_WRITE(V3) // Slider for speed
{
  hiz = param.asInt();
}


void fadeTimer()
{
  if (fadeac == 1 && AccelSwitch == 1)
  {
    Serial.println("Fade Mod a Geçiliyor");
    Fade(hiz);
  }
}


void Fade(int speed) // Fade Animation
{
  analogWrite(5, 255);
  analogWrite(3, 255);
  analogWrite(6, 255);

  for (i = 90; i <= 270; i++) {
    Blynk.run();
    if (fadeac == 0)
      break;
    if (AccelSwitch == 0)
    {
      Serial.println("Ledi Kapa");
      Blynk.virtualWrite(V2, 0);
      analogWrite(5, 0);
      analogWrite(3, 0);
      analogWrite(6, 0);
      break;
    }    
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(3, sinOut);
    delay(speed);
  }
  for (i = 90; i <= 270; i++) {
    Blynk.run();
    if (fadeac == 0)
      break;
    if (AccelSwitch == 0)
    {
      Serial.println("Ledi Kapa");
      Blynk.virtualWrite(V2, 0);
      analogWrite(5, 0);
      analogWrite(3, 0);
      analogWrite(6, 0);
      break;
    }
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(6, sinOut);
    delay(speed);
  }
  for (i = 270; i >= 90; i--) {
    Blynk.run();
    if (fadeac == 0)
      break;
    if (AccelSwitch == 0)
    {
      Serial.println("Ledi Kapa");
      Blynk.virtualWrite(V2, 0);
      analogWrite(5, 0);
      analogWrite(3, 0);
      analogWrite(6, 0);
      break;
    }    
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(3, sinOut);
    delay(speed);
  }
  for (i = 90; i <= 270; i++) {
    Blynk.run();
    if (fadeac == 0)
      break;
    if (AccelSwitch == 0)
    {
      Serial.println("Ledi Kapa");
      Blynk.virtualWrite(V2, 0);
      analogWrite(5, 0);
      analogWrite(3, 0);
      analogWrite(6, 0);
      break;
    }   
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(5, sinOut);
    delay(speed);
  }
  for (i = 270; i >= 90; i--) {
    Blynk.run();
    if (fadeac == 0)
      break;
    if (AccelSwitch == 0)
    {
      Serial.println("Ledi Kapa");
      Blynk.virtualWrite(V2, 0);
      analogWrite(5, 0);
      analogWrite(3, 0);
      analogWrite(6, 0);
      break;
    }    
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(6, sinOut);
    delay(speed);
  }
  for (i = 90; i <= 270; i++) {
    Blynk.run();
    if (fadeac == 0)
      break;
    if (AccelSwitch == 0)
    {
      Serial.println("Ledi Kapa");
      Blynk.virtualWrite(V2, 0);
      analogWrite(5, 0);
      analogWrite(3, 0);
      analogWrite(6, 0);
      break;
    }    
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(3, sinOut);
    delay(speed);
  }
  for (i = 270; i >= 90; i--) {
    Blynk.run();
    if (fadeac == 0)
      break;
    if (AccelSwitch == 0)
    {
      Serial.println("Ledi Kapa");
      Blynk.virtualWrite(V2, 0);
      analogWrite(5, 0);
      analogWrite(3, 0);
      analogWrite(6, 0);
      break;
    }
    rad = DEG_TO_RAD * i;
    sinOut = constrain((sin(rad) * 128) + 128, 0, 255);
    analogWrite(3, sinOut);
    analogWrite(5, sinOut);
    delay(speed);
  }
}



void setup()
{
  DebugSerial.begin(9600);
  DebugSerial.println("Waiting for connections...");
  Serial.begin(38400);
  Blynk.begin(DebugSerial, auth);
}

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

}

How can i make it simpler?

Sorry for my bad english. I’m Turkish :slight_smile:

Thank You.

1 Like