5 Push buttons to LED strip

Hello everyone

I am new to arduino,

I am trying to connect 5 push buttons to NeoPixel Strip 8

The objective being, each button should trigger a specific blinking sequence.
(I am still learning how the code works, so I have asked chat GPT for the code)

Terminal 1b of all 5 buttons are connected to pins 2 to 6
Terminal 1a of all 5 buttons are connected to GND via a breadboard
DIN of the LED strip is connected to pin 7
5V & GND of the LED strip is connected to 5V & GND on the arduino

I am attaching a picture of my circuit and the code

Any help / guidance is much appreciated
Thank you :slight_smile:

const int leds[] = {2, 3, 4, 5, 6, 7, 8, 9};  // LED pins
const int buttons[] = {6, 5, 4, 3, 2};   // Button pins
const int delayTime = 750;  // 80 BPM, adjust as needed

void setup() {
  // Initialize LEDs as OUTPUT
  for (int i = 0; i < 8; i++) {
    pinMode(leds[i], OUTPUT);
  }
  
  // Initialize buttons as INPUT_PULLUP
  for (int i = 0; i < 5; i++) {
    pinMode(buttons[i], INPUT_PULLUP);
  }
}

void loop() {
  if (digitalRead(buttons[0]) == LOW) {  // Active LOW due to INPUT_PULLUP
    playA();
  } else if (digitalRead(buttons[1]) == LOW) {
    playM();
  } else if (digitalRead(buttons[2]) == LOW) {
    playR();
  } else if (digitalRead(buttons[3]) == LOW) {
    playK();
  } else if (digitalRead(buttons[4]) == LOW) {
    playE();
  }
}

// Preset Functions
void playA() {
  flashLeds(0, 8);
}

void playM() {
  flashLeds(0, 3);
  flashLeds(4, 8);
}

void playR() {
  flashLeds(0, 3);
}

void playK() {
  flashLeds(0, 5);
}

void playE() {
  flashLeds(0, 5);
}

void flashLeds(int start, int end) {
  for (int i = start; i < end; i++) {
    digitalWrite(leds[i], HIGH);
  }
  delay(delayTime);
  for (int i = start; i < end; i++) {
    digitalWrite(leds[i], LOW);
  }
  delay(delayTime);
}

This may destroy your Arduino. The 5V is incapable of providing enough current.

Read this:

Is that code yours or from ChatGPT?

Pins 6,5,4,3,2 have duplicate purposes!

1 Like

ChatGPT

I’m curious, can you post the wording of your question to Chat GPT?

This was my prompt

"I am trying to make a project using arduino

It involves an 8 bit led strip

The main objective is to make the led strip flash in a preprogrammed sequence at 80 bmp speed

There are 5 such preprogrammed sequences (presets)I want. Viz

The presets are named and defined below

  1. A : all 8 Leds should flash
  2. M: LEDs numbered 1,2,3,5,6,7,8 should flash
  3. R : LEDs numbered 1,2,3, should flash
  4. K : LEDs numbered 1,2,3,4,5 should flash
  5. E, LEDs numbered 1,2,3,4,5 should flash

The above presets / sequences should be triggered by 5 individual push buttons
i.e, each button should be assigned to a preset "

But I am using a strip that has 8 leds, its not a long one
And I want it to flash in red (based on what I read from the link you gave, red colour requires relatively less voltage)

So if 5V is not enough, I should use batteries ?

Eight red LEDs should be well within the max current from a UNO’s 5V pin.

So what happens when you

  • compile it?
  • run it?

The code appears to be fine, as no error message has popped up.
Its the connections that I am not sure of

Yeah, after I run the simulation and press the buttons, nothing happens
So I thought I must have made a mistake in the connection

5V is fine. It's the current to be concerned with.

Your Neopixel strip has the potential to draw ~500mA. That's fine as long as you are powering it with a USB device such was your computer. You will damage your Uno if you attempt to power it any other way.

Your code as written will not work on Neopixels. Provide a link to your strip

I see

how to provide a link to the strip ?

Is this your strip?

Yes, (I am doing this on Tinkercad Arduino Simulator)
But its the same thing

The first thing you need to do is install the library and get familiar with the examples

I doubt the capacitor is needed in such a short strip. However, be aware of glitches. Adding a 330 or 470 ohm resistor would be a good idea.

Ah ! I forgot to include the library

(tinkercad has sample projects / examples to understand how it works, I am learning from it)

My main doubt is, did I connect everything correctly ?
(with reference to the picture I have attached)

Follow the examples. Get the Neo working first, then revisit the switches.

With the help of the examples I got the strip to work with a single push button

I am having trouble with connecting 5 push buttons to the strip
I tried searching for similar examples online, but could not get any

If you can kindly guide me to any post / documentation for my use case I will be much obliged. I will read it and try to understand / follow

Post your code and setup