0

I am using atmega 2560 to control 590 LED lights with NeoPixels library.

I also got an IR receiver connected so I could control the LED properties and it does work but only when the LEDs are not engaged, the moment the code for LED's goes off the IR receiver keep returning random rubish.

Pressing the same button on a remote:

11:48:18.394 -> FF3AC5
11:48:19.550 -> D53AFF52
11:48:58.586 -> 24AE7D4E
11:48:59.341 -> 4CB0FADF
11:48:59.742 -> 4CB0FADF
11:49:00.491 -> 6BDBBF60
11:49:09.462 -> A8E05FBB
11:49:10.612 -> 40892F89
11:49:11.067 -> 3AD8A119
11:49:11.515 -> 2C1330B0
11:49:14.176 -> DDE32E9D
11:49:16.597 -> FF1AE5
11:49:17.445 -> A8E05FBB
11:49:17.499 -> FFFFFFFF
11:49:18.502 -> FF1AE5
11:49:18.548 -> FFFFFFFF
11:49:19.350 -> FF1AE5

IR connection diagram below: enter image description here

My code below:

#include <IRremote.h>
#include <Adafruit_NeoPixel.h>

int LED_pin = 6;
int PIR_pin_D = 4;
int PIR_pin_U = 3;
int IR_pin = 2;

int LDR_pin = A0;

int pirInputU = LOW;
int pirInputD = LOW;
int ldrInput =  0;
int irInput = 0;

bool goignDown = false;
bool goingUp = false;

//states
bool lights = true;
bool constantMode = false;
byte ledBrightness = 50;
byte mode = 0;


int lightDuration = 8000;
int sensorDelay = 1500;


#define NUM_LEDS 590
#define NUM_STEPS 14

int numOfLEDs[NUM_STEPS] {41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 57, 41};

Adafruit_NeoPixel strip(NUM_LEDS, LED_pin, NEO_GRB + NEO_KHZ800);
int32_t currentColour = strip.Color(255, 255, 255);

IRrecv irrecv(IR_pin);
decode_results results;

void setup()
{
  strip.begin();
  strip.setBrightness(ledBrightness);

  irrecv.enableIRIn();

  pinMode(LDR_pin, INPUT);    // declare sensor as input
  pinMode(IR_pin, INPUT);    // declare sensor as input
  pinMode(PIR_pin_U, INPUT_PULLUP);  // declare sensor as input
  pinMode(PIR_pin_D, INPUT_PULLUP);  // declare sensor as input

  strip.clear();
  strip.show();

  delay(10000);
  Serial.begin(9600);
}

void loop()
{
  ldrInput = analogRead(LDR_pin);    // read input value

  checkIrInput();

  if (ldrInput < 60 && lights)
  {
    pirInputU = digitalRead(PIR_pin_U); // read input value
    pirInputD = digitalRead(PIR_pin_D); // read input value
    checkIrInput();
    //UPSTAIRS SENSOR
    if (pirInputU == HIGH && pirInputD == LOW) // check if the input is HIGH
    {
      moveDown(currentColour);
      delay(lightDuration);
      moveDown(strip.Color(0, 0, 0));
      delay(sensorDelay);
      pirInputD = digitalRead(PIR_pin_D); // read input value
    }

    //DOWNSTAIRS
    if (pirInputD == HIGH && pirInputU == LOW) // check if the input is HIGH
    {
      moveUp(currentColour);
      delay(lightDuration);
      moveUp(strip.Color(0, 0, 0));
      delay(sensorDelay);
      pirInputU = digitalRead(PIR_pin_U); // read input value
    }
  } 
}

void clearLedStrip()
{
  strip.clear();
  strip.show();
}

void checkIrInput()
{
  //Serial.println("pooling");

  while (!irrecv.isIdle());  // if not idle, wait till complete
 
  if (irrecv.decode(&results))
  {
    Serial.println(results.value, HEX);

    switch (results.value)
    {
      case 0xFF1AE5: //red
        {
          currentColour = strip.Color(255, 10, 10);
          break;
        }
      case 0xFF9A65: //green
        {
          currentColour = strip.Color(10, 255, 10);
          break;
        }
      case 0xFFA25D: //blue
        {
          currentColour = strip.Color(10, 10, 255);
          break;
        }
      case 0xFF22DD: //white
        {
          currentColour = strip.Color(255, 255, 255);
          break;
        }
      case 0xFF18E7: //yellow
        {
          currentColour = strip.Color(255, 255, 0);
          break;
        }
      case 0xFF58A7: //purple
        {
          currentColour = strip.Color(186,85,211);
          break;
        }
      case 0xFF02FD:
        {
          lights = !lights;
          break;
        }
      case 0xFF827D:
        {
          constantMode = !constantMode;
          break;
        }
      case 0xFF3AC5:
        {
          ledBrightness += 10;
          if (ledBrightness > 100)
            ledBrightness = 100;
          strip.setBrightness(ledBrightness);
          break;
        }
      case 0xFFBA45:
        {
          ledBrightness -= 10;
          if (ledBrightness < 10)
            ledBrightness = 10;
          strip.setBrightness(ledBrightness);
          break;
        }
    }
    irrecv.resume();
  }
}


void moveDown(uint32_t colour)
{
  int start = 0;

  for (int step = 0; step < NUM_STEPS; step++)
  {
    int end = (start + numOfLEDs[step]) - 1;
    int midPoint = start + numOfLEDs[step] * 0.5;
   
    checkIrInput();
   
    for (int led = start, temp = 0; led <= midPoint; led++, temp++)
    {   
      strip.setPixelColor(led, colour);
      strip.setPixelColor(end - temp, colour);
      strip.show();
    }
    checkIrInput();
    start += numOfLEDs[step];
  }
}

void moveUp(uint32_t colour)
{
  int start = NUM_LEDS - numOfLEDs[NUM_STEPS - 1];

  for (int step = NUM_STEPS - 1; step >= 0; step--)
  {
    int end = (start + numOfLEDs[step]) - 1;
    int midPoint = start + numOfLEDs[step] * 0.5;
   
    checkIrInput();
   
    for (int led = start, temp = 0; led <= midPoint; led++, temp++)
    {
      strip.setPixelColor(led, colour);
      strip.setPixelColor(end - temp, colour);
      strip.show();
    }
    checkIrInput();
    start -= numOfLEDs[step];
  }
}

Is atmega 2560 not powerfull enough? Or is there something that I am doing wrong?

Any feedback welcome, thank you.

  • 1
    start with example IR receive code ... that will confirm the module functionality – jsotola Aug 1 at 16:50
  • Hi as mentioned in my question I got the IR receiver working but the moment the NeoPixel code get's run to turn on the LED lights the IR receiver starts returning random values and once LEDs stop changing the IR values go back to normal – user1031204 Aug 3 at 9:35
  • then shield the IR receiver from the neopixels – jsotola Aug 3 at 9:40
  • you think it's a physical problem rathe than software? – user1031204 Aug 4 at 13:02
  • no, i do not think that ... i have no preconceived opinion about the source of the problem ... shielding the IR receiver is the easiest troubleshooting step – jsotola Aug 4 at 14:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.