How to control two RGB LED Neopixel Rings (16x pixels each) with Arduino UNO

Hi everybody

I am new in dealing with Arduino. I am carrying out a personal project to simply learn how to control the lighting colours of the two RGB LED Neopixel rings (16x pixels each) using Arduino UNO and two different digital pins (3 and 6). Both RGB rings are powered by 5V from Arduino and grounded.

The idea of my project is to simply light both rings sequentially (one in a time). When the first ring turns green for 5 seconds, it will turn OFF and the second ring will turn blue for 2 seconds. Thereafter the second ring will turn OFF to allow the first ring turning red for 5 seconds. While the first ring is now red, the second ring must turn blue for 2 seconds before both two rings turn OFF to start the sequence from the beginning.

I wrote the code and used Tinkercad (www.tinkercad.com) for simulation which was a success. I also uploaded the code successfully into the Ardunio UNO. Unfortunately, when “physically” executing the code, the two rings follow the sequence above at once (i.e. with no LOOP). After that the second ring only starts to repeat the blue colour several times indicating that the circuit does not follow the complete loop I wrote.

I think I am missing something to allow running the colour sequence loop forever. I would appreciate your kind help.

Kindly find attached the circuit diagram, the code and the TinkerCad simulation link.

Thanks

#include <Adafruit_NeoPixel.h>

#define PIN 3   // input pin Neopixel is attached to

#define PIN 6   // input pin Neopixel is attached to

#define NUMPIXELS      16       // number of neopixels in Ring


Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, 6, NEO_GRB + NEO_KHZ800);

 

int delayval = 5; // timing delay


void setup() {
  
  pixels.begin(); // Initializes the NeoPixel library.
 
 
  
  pixels.setBrightness(25);  // Lower brightness and save eyeballs!
  pixels.show(); // Initialize all pixels to 'off'
  
//  Serial.begin(9600);
}



void loop()                                                  //defined a loop function
{
  
  
  /********************************************************************/
    for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,250,0)); // Moderately bright green color.
      
pixels.setBrightness(25);  // Lower brightness and save eyeballs!  
      
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
  /**************************************************************************/
  delay(5000); /// this for how much time green color stays in mS
  
  for(int i=0;i<NUMPIXELS;i++){
    pixels.setPixelColor(i, pixels.Color(0,0,0)); // Ring (all 16 pixels)in PIN 6 is OFF (Green OFF).
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
  
  /**************************************************************************/
  
 Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, 3, NEO_GRB + NEO_KHZ800);
  
  pixels.begin(); // Initializes the NeoPixel library.
  
  
  for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,0,250)); // Moderately bright Blue color.
    
pixels.setBrightness(25);  // Lower brightness and save eyeballs!  
    
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
  /***********************************************************************/
  delay(3000); // this for how much time orange color stays in mS
   /*******************************************************/

  for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels.setPixelColor(i, pixels.Color(0,0,0)); // Ring (all 16 pixels)in PIN 3 is OFF (Blue OFF).
    pixels.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
 
   /*******************************************************/
  
 Adafruit_NeoPixel pixels6 = Adafruit_NeoPixel(NUMPIXELS, 6, NEO_GRB + NEO_KHZ800);
  
   for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels6.setPixelColor(i, pixels6.Color(250,0,0)); // Moderately bright red color.
     
 pixels6.setBrightness(25);  // Lower brightness and save eyeballs!   
     
    pixels6.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
  /***************************************************************/
  delay(5000); // this for how much time Red color stays in mS

  
   /*******************************************************/
  
  
  
   Adafruit_NeoPixel pixels3 = Adafruit_NeoPixel(NUMPIXELS, 3, NEO_GRB + NEO_KHZ800);
  
  
  
  
  for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels3.setPixelColor(i, pixels3.Color(0,0,250)); // Moderately bright Blue color.
    
 pixels3.setBrightness(25);  // Lower brightness and save eyeballs!  
    
    pixels3.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
  /***********************************************************************/
  delay(3000); // this for how much time orange color stays in mS
   /*******************************************************/

  for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels3.setPixelColor(i, pixels3.Color(0,0,0)); // Ring (all 16 pixels)in PIN 3 is OFF (Blue OFF).
    pixels3.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
  
   /*******************************************************/
 
  for(int i=0;i<NUMPIXELS;i++){
    // pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
    pixels6.setPixelColor(i, pixels6.Color(0,0,0)); // Ring (all 16 pixels)in PIN 6 is OFF (Red OFF).
    pixels6.show(); // This sends the updated pixel color to the hardware.
    delay(delayval); // Delay for a period of time (in milliseconds).
  }
  
  
}

Please fix your post above. You have not used code tags correctly. Delete those square brackets, highlight all the code and press the </> icon.

You should take care with this circuit. It could easily overload the Uno's regulator if you switch on too many leds at full brightness. It would be better to use a separate 2.5~3A 5V power supply for the LEDs.

Your code seems to be written for only one ring of LEDs, not two.

PaulRB: Your code seems to be written for only one ring of LEDs, not two.

There are 3 instances of the led driver: * pixels * pixels3 * pixels6

These are created with every loop(). I don't know if the Arduino runs out of memory here.

These are created with every loop()

Don’t do that.

PaulRB:
Please fix your post above. You have not used code tags correctly. Delete those square brackets, highlight all the code and press the </> icon.

You should take care with this circuit. It could easily overload the Uno's regulator if you switch on too many leds at full brightness. It would be better to use a separate 2.5~3A 5V power supply for the LEDs.

Your code seems to be written for only one ring of LEDs, not two.

Thank you for the advice. I posted the code again.

In order to avoid overloading of Arduino Uno's regulator, I controlled the brightness of each RGB ring to be only 25 (which is 25/255 =~ 9% of the full brightness).

Do you have any idea to modify my code and/or the electric circuit shown above?

Grumpy_Mike:
Don’t do that.

Hi

Thank you for the warning.

In fact, I tried first writing the following in the declaration part (not in the loops) to initiate both PIN 6 and PIN 3 but discovered that the Arduino is only controlled by the first demand (which is written PIN 6). Obviously, If I exchange the order of the following two sentences, the Arduino will only execute PIN 3:

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, 6, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, 3, NEO_GRB + NEO_KHZ800);

Is it possible to re-write the above two sentences in the declaration part (i.e. before the void setup) as follows to ensure the execution of both PIN 6 and PIN 3?:

Adafruit_NeoPixel pixels6 = Adafruit_NeoPixel(NUMPIXELS, 6, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel pixels3 = Adafruit_NeoPixel(NUMPIXELS, 3, NEO_GRB + NEO_KHZ800);

I would appreciate if you kindly show me how to fix or re-modify my code and/or the electric circuit.

Thanks

Is it possible to re-write the above two sentences in the declaration part (i.e. before the void setup) as follows to ensure the execution of both PIN 6 and PIN 3?:

Yes you are calling both rings with the same names, both strips are called pixels, therefore only the last one you used will actually do anything. Do:-

Adafruit_NeoPixel ring1 = Adafruit_NeoPixel(NUMPIXELS, 6, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel ring2 = Adafruit_NeoPixel(NUMPIXELS, 3, NEO_GRB + NEO_KHZ800);

and in the setup function:-

void setup() {
  ring1.begin(); // Initializes the NeoPixel library for ring 1
  ring2.begin(); // Initializes the NeoPixel library for ring 2
  ring1.setBrightness(25);  // Lower brightness and save eyeballs!
 ring2.setBrightness(25);  // Lower brightness and save eyeballs!

Then you can do things like:-

ring1.setPixelColor(i, pixels.Color(0,250,0)); // Moderately bright green color
ring1.show(); 
// some time later
ring2.setPixelColor(i, pixels.Color(0,0,0));
ring2.show();

I like to give them the name strip, and then I take childish delight in writing:-

strip.show();