Problem controlling my RGB Strip

Hey Guys :slight_smile:

I have a huge problem with my Arduino controlling my RGB-LED Strip. I can controll the blue and green channel without any issues (all values from 0-255 are working) but my red channel is really not wanting to work… I can controll it but it only goes on and off (0 and 255) but all other PWM frequencies won’t work. It will just turn the LEDs off. The really weird thing is that I can eliminate that this might be happening because of a hardware failure because when I start a new sketch and just order the Arduino (Nano) to control the in the setup method every channel for every value works like a charm… Am I blind or what’S the problem with my code (attached in a text file and the related .ino file)

I really hope anyone of you can help me out.

void setup() 
{
	ersterLauf=true;
	irrecv.enableIRIn();		  // initializes IR-receiver 
	Serial.begin(9600);
	if(EEPROM.read(3)==1){
		fadeOn=true;
	}
	else{
		fadeOn=false;
	}
	if(fadeOn == false){
		analogWrite(rotPin,EEPROM.read(0));
		analogWrite(gruenPin,EEPROM.read(1));
		analogWrite(blauPin,EEPROM.read(2));
	}
  
}
 
 
void loop(){
	if (irrecv.decode(&results)) {
										//IR-basecodes
		if(results.value == on){
		
			analogWrite(rotPin, EEPROM.read(0));
			analogWrite(gruenPin, EEPROM.read(1));	//load RGB values from EEPROM
			analogWrite(blauPin, EEPROM.read(2));
		
			irrecv.resume();
		}
		
		if(results.value == off){	//turns all LEDs off
			
			analogWrite(rotPin,0);
			analogWrite(gruenPin,0);
			analogWrite(blauPin,0);
			
			irrecv.resume();
		}
		
		if(results.value == weiss){ // turns on white color
		
			analogWrite(rotPin,255);
			analogWrite(gruenPin,255);
			analogWrite(blauPin,255);
		
			EEPROM.write(0,255);
			EEPROM.write(1,255);
			EEPROM.write(2,255);

			irrecv.resume();
		}
		
		if(results.value == rot){	// turns on red color
		
			analogWrite(rotPin,255);
			analogWrite(gruenPin,0);
			analogWrite(blauPin,0);
			
			EEPROM.write(0,255);
			EEPROM.write(1,0);
			EEPROM.write(2,0);

			irrecv.resume();
		}
		
		if(results.value == gruen){	// turns on green color
		
			analogWrite(rotPin,0);
			analogWrite(gruenPin,255);
			analogWrite(blauPin,0);
			
			EEPROM.write(0,0);
			EEPROM.write(1,255);
			EEPROM.write(2,0);

			irrecv.resume();
		}
		
		if(results.value == blau){	// turns on blue color
		
			analogWrite(rotPin,0);
			analogWrite(gruenPin,0);
			analogWrite(blauPin,255);
			
			EEPROM.write(0,0);
			EEPROM.write(1,0);
			EEPROM.write(2,255);
				
			irrecv.resume();
		}
		
		irrecv.resume();
	}
	
	if(Serial.available() > 0){
	
		delay(500);						// Serial Input Base-Code

		if(Serial.peek() == 'r'){	//controls red color (not working properly)
		
			Serial.read();
			rVal = Serial.parseInt();
			analogWrite(rotPin, rVal);
			EEPROM.write(0, rVal);
		}
		
		if(Serial.peek() == 'g'){	//controls green color
		
			Serial.read();
			gVal = Serial.parseInt();
			analogWrite(gruenPin, gVal);
			EEPROM.write(1, gVal);
		}

		if(Serial.peek() == 'b'){	//controls blue color
		
			Serial.read();
			bVal = Serial.parseInt();
			analogWrite(blauPin, bVal);
			EEPROM.update(2, bVal);
		}
		
		if(Serial.peek() == 'f'){	//controls fading
		
			Serial.read();
			int fval = Serial.parseInt();
			if(fval==1){
				fadeOn = true;
			}
			if(fval==0){
				fadeOn = false;
				ersterLauf = true;
			}
			EEPROM.update(3,fval);
		}
		
		while(Serial.available() > 0){
			Serial.read();
		}
  }
		
		
	fade();
	
}

LED-Controller.txt (8.76 KB)

LED-Controller-neu.ino (8.82 KB)

Why doesn't anyone want to post code?

Please include code in code tags
</> left most formatting symbol.

it will make code look like this, and [i] is not interpreted as italic

Ok I just edited it and addes english notes to the code (I don’t think you will get really happy with the german ones XD)

When we say " post your code", we mean "post your code" as in "all of it".

because the Code contains more than 9k chars I seem to have to send it in 2 pieces…

#include <IRremote.h>
#include <EEPROM.h>
//Pins for RGB LEDs
#define rotPin 11 //redLED
#define gruenPin 6 // green LED
#define blauPin 9 // blue LED

//EEPROM 0=red, 1=green, 2=blue 
int rVal, gVal, bVal;
boolean ersterStart = true;



//IR-recevier Stuff
const int RECV_PIN = A0; // Pin of the IR-Receiver
IRrecv irrecv(RECV_PIN); // defining of a receiver object
decode_results results; // variable for saving the IR-results

//IR-Codes for the IR transmitter
#define on 16236607
#define off 16203967
#define dunkler 16220287
#define heller 16187647
#define rot 16195807
#define gruen 16228447
#define blau 16212127
#define weiss 16244767
#define hellrot 16191727
#define orange 16199887
#define orangebraun 16189687
#define gelb 16197847
#define dunkelgr√ľn 16224367
#define hellesdunkelgr√ľn 16232527
#define hellgr√ľn 16222327
#define tuerkis 16230487
#define dunkelblau 16208047
#define ultramarine 16216207
#define dunkelviolett 16206007
#define violett 16214167
#define flash 16240687
#define strobe 16248847
#define fadebtn 16238647
#define smooth 16246807

//Variables for Fading (fade())
byte r, g, b;
char farbe = 'b';             // letter for current color (Blue)
int fadePause = 8;            // time for fading steps; smaller = faster, bigger = slower
int halteZeit = 500;          // pause time between colors
unsigned long fadeZeit = 0;   // variable for saving the current millis()
boolean ersterLauf = true;    // needed to check if it's the first run of the program
boolean fadeOn = false;  // defines if fademode should be turned on

void setup() 
{
ersterLauf=true;
irrecv.enableIRIn();  // initializes IR-receiver 
Serial.begin(9600);
if(EEPROM.read(3)==1){
fadeOn=true;
}
else{
fadeOn=false;
}
if(fadeOn == false){
analogWrite(rotPin,EEPROM.read(0));
analogWrite(gruenPin,EEPROM.read(1));
analogWrite(blauPin,EEPROM.read(2));
}
 
}


void loop(){
if (irrecv.decode(&results)) {
//IR-basecodes
if(results.value == on){

analogWrite(rotPin, EEPROM.read(0));
analogWrite(gruenPin, EEPROM.read(1)); //load RGB values from EEPROM
analogWrite(blauPin, EEPROM.read(2));

irrecv.resume();
}

if(results.value == off){ //turns all LEDs off

analogWrite(rotPin,0);
analogWrite(gruenPin,0);
analogWrite(blauPin,0);

irrecv.resume();
}

if(results.value == weiss){ // turns on white color

analogWrite(rotPin,255);
analogWrite(gruenPin,255);
analogWrite(blauPin,255);

EEPROM.write(0,255);
EEPROM.write(1,255);
EEPROM.write(2,255);

irrecv.resume();
}

if(results.value == rot){ // turns on red color

analogWrite(rotPin,255);
analogWrite(gruenPin,0);
analogWrite(blauPin,0);

EEPROM.write(0,255);
EEPROM.write(1,0);
EEPROM.write(2,0);

irrecv.resume();
}

if(results.value == gruen){ // turns on green color

analogWrite(rotPin,0);
analogWrite(gruenPin,255);
analogWrite(blauPin,0);

EEPROM.write(0,0);
EEPROM.write(1,255);
EEPROM.write(2,0);

irrecv.resume();
}

if(results.value == blau){ // turns on blue color

analogWrite(rotPin,0);
analogWrite(gruenPin,0);
analogWrite(blauPin,255);

EEPROM.write(0,0);
EEPROM.write(1,0);
EEPROM.write(2,255);

irrecv.resume();
}

irrecv.resume();
}
	if(Serial.available() > 0){
	
		delay(500);						// Serial Input Base-Code

		if(Serial.peek() == 'r'){	//controls red color (not working properly)
		
			Serial.read();
			rVal = Serial.parseInt();
			analogWrite(rotPin, rVal);
			EEPROM.write(0, rVal);
		}
		
		if(Serial.peek() == 'g'){	//controls green color
		
			Serial.read();
			gVal = Serial.parseInt();
			analogWrite(gruenPin, gVal);
			EEPROM.write(1, gVal);
		}

		if(Serial.peek() == 'b'){	//controls blue color
		
			Serial.read();
			bVal = Serial.parseInt();
			analogWrite(blauPin, bVal);
			EEPROM.update(2, bVal);
		}
		
		if(Serial.peek() == 'f'){	//controls fading
		
			Serial.read();
			int fval = Serial.parseInt();
			if(fval==1){
				fadeOn = true;
			}
			if(fval==0){
				fadeOn = false;
				ersterLauf = true;
			}
			EEPROM.update(3,fval);
		}
		
		while(Serial.available() > 0){
			Serial.read();
		}
  }
		
		
	fade();
	
}
	



void fade(){	//fading function

// Blaue LED beim ersten Durchlauf einblenden

        if (ersterLauf == true && millis()- fadeZeit > fadePause && fadeOn == true)
        {
          // Wenn b kleiner als 255 ist...
          if (b < 255)
          {
            b++;                      // Zählt b um 1 hoch
            analogWrite(blauPin, b);  // Ausganbe von b am LED Pin
            fadeZeit  = millis();     // Aktuelle Zeit speichern
          }
  
          // Wenn b bei 255 angekommen UND die halteZeit vergangen ist...
          if (b == 255 && (millis()- fadeZeit) > (fadePause + halteZeit))
          {
            ersterLauf = false;     // Erster Lauf ist abgeschlossen
          }
       }

        // Wenn ersterLauf abgeschlossen ist UND fadePause vergangen ist...
        if (ersterLauf == false && millis()- fadeZeit > fadePause && fadeOn == true && fadeOn == true)
        {
          // Wechsel von Blau zu Lila 
          if (farbe == 'b')
          {
            // Wenn r kleiner als 255 ist...
            if (r < 255)
            {
              r++;                      // Zählt r um 1 hoch
              analogWrite(rotPin, r);   // Ausganbe von r am LED Pin
              fadeZeit  = millis();     // Aktuelle Zeit speichern
            }
    
            // Wenn r bei 255 angekommen UND die halteZeit vergangen ist...
            if (r == 255 && millis()- fadeZeit > fadePause + halteZeit)
            {
¬† ¬† ¬† ¬† ¬† ¬† ¬† farbe = 'l';¬† ¬† // √Ąndere Frabe auf "l" (Lila)
            }
          }

            // Wechsel von Lila zu Rot
            if (farbe == 'l')
            {
               // Wenn b größer als 0 ist...
               if (b > 0)
              {
                b--;                      // Zählt b um 1 runter
                analogWrite(blauPin, b);  // Ausganbe von b am LED Pin
                fadeZeit  = millis();     // Aktuelle Zeit speichern
              }
    
              // Wenn b bei 0 angekommen UND die halteZeit vergangen ist...
              if (b == 0 && millis()- fadeZeit > fadePause + halteZeit && fadeOn == true)
              {
¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† farbe = 'r';¬† ¬† // √Ąndere Frabe auf "r" (Rot)
               }
            }

            // Wechsel von Rot zu Gelb
            if (farbe == 'r')
            {
              // Wenn g kleiner als 255 ist...
              if (g < 255)
              {
              g++;                      // Zählt g um 1 hoch
              analogWrite(gruenPin, g);   // Ausganbe von g am LED Pin
              fadeZeit  = millis();     // Aktuelle Zeit speichern
              }
    
              // Wenn g bei 255 angekommen UND die halteZeit vergangen ist...
              if (g == 255 && millis()- fadeZeit > fadePause + halteZeit && fadeOn == true)
             {
¬† ¬† ¬† ¬† ¬† ¬† ¬† farbe = 'y';¬† ¬† // √Ąndere Frabe auf "y" (Gelb)
             }
           }

           // Wechsel von Gelb zu Gruen
           if (farbe == 'y')
           {
              // Wenn r größer als 0 ist...
              if (r > 0)
              {
                r--;                      // Zählt r um 1 runter
                analogWrite(rotPin, r);   // Ausganbe von r am LED Pin
                fadeZeit  = millis();     // Aktuelle Zeit speichern
              }
    
              // Wenn r bei 0 angekommen UND die halteZeit vergangen ist...
              if (r == 0 && millis()- fadeZeit > fadePause + halteZeit && fadeOn == true)
              {
¬† ¬† ¬† ¬† ¬† ¬† ¬† ¬† farbe = 'g';¬† ¬† // √Ąndere Frabe auf "g" (Gr√ľn)
              }
            }

          // Wechsel von Gruen zu Petrol
          if (farbe == 'g')
          {
            // Wenn b kleiner als 255 ist...
            if (b < 255)
            {
              b++;                      // Zählt b um 1 hoch
              analogWrite(blauPin, b);  // Ausganbe von b am LED Pin
              fadeZeit  = millis();     // Aktuelle Zeit speichern
            }
    
          // Wenn b bei 255 angekommen UND die halteZeit vergangen ist...
          if (b == 255 && millis()- fadeZeit > fadePause + halteZeit && fadeOn == true)
          {
¬† ¬† ¬† ¬† ¬† ¬† farbe = 'p';¬† ¬† // √Ąndere Frabe auf "p" (Petrol)
          }
        }

        // Wechsel von Petrol zu Blau
        if (farbe == 'p')
        {
          // Wenn g größer als 0 ist...
          if (g > 0)
          {
            g--;                      // Zählt g um 1 runter
            analogWrite(gruenPin, g);   // Ausganbe von g am LED Pin
            fadeZeit  = millis();     // Aktuelle Zeit speichern
          }
    
       // Wenn g bei 0 angekommen UND die halteZeit vergangen ist...
       if (g == 0 && millis()- fadeZeit > fadePause + halteZeit && fadeOn == true)
       {
¬† ¬† ¬† ¬†  farbe = 'b';¬† ¬† // √Ąndere Frabe auf "b" (Blau)
       }
    }
  }

}

because the Code contains more than 9k chars I seem to have to send it in 2 pieces…

you’ve really got to ask yourself how the code for too big to post before you discovered this really fundamental problem.