tira led controlada con arduino

Arduino RGB LED strip clap control

Welcome to a new Arduino project. In this tutorial, you will learn how to program and control an RGB LED strip using an Arduino controller. The strip also reacts to sounds such as claps, creating a striking visual effect.

We will also go through the different materials used in the build, show the wiring diagram, and finally share the code so you can build your own LED strip.

Materials used to control the LED strip

Below you can find the materials used in this project and what each one is used for.

It is the brain of the project and controls every part of it through the code you will find below.

A board with interconnected holes (pins) that we use to make all the project connections.

RGB LED strip: the most visible part of the project, used to light the scene and create striking visual effects.

RobotUNO PCB: a PCB designed by the RobotUNO team. The project can be built without it, but using the PCB makes all the connections much easier.

Components needed for the LED strip project

If you want to build this project, below you will find a list with links to Amazon Spain (ES) and Amazon United States (US).

WE DEVELOP YOUR IDEA

Need help with a project?

RobotUNO project consulting
  • Prototyping and MVPs
  • Arduino and ESP32
  • PCB design
  • 3D part design
  • Bluetooth connectivity
  • Feasibility study
  • Cost optimization
  • Technical consulting
  • Internet of Things
  • Patent supbyt
Learn more

Project explanation, goal and operation

This project consists of programming an RGB LED strip that reacts to sound. It is a great build to place on the wall of a bedroom or studio. We will use an Arduino Nano board to control the on and off behavior of all the LEDs.

Step-by-step LED strip project video

If you want a much more detailed walkthrough of how to build this project from start to finish, including a code explanation, the video below covers everything in a more visual and easier-to-follow way. And remember, if you enjoy this kind of content, do not forget to subscribe.

Arduino wiring diagram to control the RGB LED strip

One of the most important parts of assembling and wiring the LEDs is connecting the different elements correctly. To avoid assembly mistakes or incorrect connections, here is the wiring diagram used in this project.

With this wiring diagram, you can use the code at the end of the post directly without making any modifications.

Esquema de conexiones tira led Arduino

Files to manufacture your own PCB and control the LED strip

If you want your own PCB like the one shown in the project video, below you can find the required files and the steps to follow.

If you have any questions, the video shows all the steps so you can do everything yourself.

Download the Gerber files to manufacture the PCB below:

Download the CSV file with the position and orientation of each component:

Download the spreadsheet with the information for each component on the PCB:

Arduino code for the RGB LED strip

Below you can find the Arduino code used specifically for the LED strip project shown in the YouTube video. The pins used in the code are the same ones shown in the wiring diagram above.

If you still do not have Arduino installed and have questions about how to use or install the development environment used for Arduino, here is a link to how to download the Arduino IDE

Arduino starter kit
Arduino starter kit
Arduino Uno board
Arduino Uno board
RGB LED strip
RGB LED strip
Arduino Nano
Arduino Nano
Male-to-female jumper wires
Male-to-female jumper wires
//Tiral led programada by @RobotUNO

#include <Adafruit_NeoPixel.h>

int longitudCohete=20; //Cuantos pixeles de largo tiene cada cohete

int tiraLed=6;
int numLeds=180; //Numero total de leds que tiene tu tira led

int microfono=5; //Pin Microfono
int ldr=A5; //Pin Fotorresistencia

Adafruit_NeoPixel pixels = Adafruit_NeoPixel(numLeds, tiraLed, NEO_GRB + NEO_KHZ800);

void setup() {
  pixels.begin();
  pixels.show();

  Serial.begin(115200);
  Serial.println("Proyecto tira led by RobotUNO");

  pinMode(microfono,INPUT);
  pinMode(ldr,INPUT);
}

int cohete1=200; //pixel fuera de la tira led
int cohete2=200;
int cohete3=200;
int cohete4=200;
int cohete5=200;
int cohete6=200;

int coheteNuevo=0;

void loop() {
  //Serial.println(digitalRead(microfono));
  //Serial.println(analogRead(ldr));

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  if (coheteNuevo==1){ //Si hay un cohete pendiente lo lanzo
    coheteNuevo=0; //Reinicio la variable cohete pendiente
    if(cohete1==200) cohete1=0;
    else if(cohete2==200) cohete2=0; 
    else if(cohete3==200) cohete3=0; 
    else if(cohete4==200) cohete4=0; 
    else if(cohete5==200) cohete5=0; 
    else if(cohete6==200) cohete6=0; 
    Serial.println("nuevo cohete detectado");
  }

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  pixels.clear();

  for(int largo=-longitudCohete ; largo<0 ; largo++){ //DIBUJO COHETE1 (Empieza desde -longitudCohete para que se vean salir los cohetes poco a poco por la base)
      pixels.setPixelColor(cohete1+largo,255,0,0); //(nºled,R,G,B) rojo  
  }

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  for(int largo=-longitudCohete ; largo<0 ; largo++){ //DIBUJO COHETE2
      pixels.setPixelColor(cohete2+largo,0,0,255); //(nºled,R,G,B) azul   
  }

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  for(int largo=-longitudCohete ; largo<0 ; largo++){ //DIBUJO COHETE3
      pixels.setPixelColor(cohete3+largo,0,255,0); //(nºled,R,G,B) verde  
  }

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  for(int largo=-longitudCohete ; largo<0 ; largo++){ //DIBUJO COHETE4
      pixels.setPixelColor(cohete4+largo,255,255,255); //(nºled,R,G,B) blanco
  }

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  for(int largo=-longitudCohete ; largo<0 ; largo++){ //DIBUJO COHETE5
      pixels.setPixelColor(cohete5+largo,0,0,255); //(nºled,R,G,B) rojo
  }

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  for(int largo=-longitudCohete ; largo<0 ; largo++){ //DIBUJO COHETE6
      pixels.setPixelColor(cohete6+largo,0,255,0); //(nºled,R,G,B) verde
  }

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }
  
  pixels.show();

  cohete1++;
  cohete2++;
  cohete3++;
  cohete4++;
  cohete5++;
  cohete6++;

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  if(cohete1>200) cohete1=200;
  if(cohete2>200) cohete2=200;
  if(cohete3>200) cohete3=200;
  if(cohete4>200) cohete4=200;
  if(cohete5>200) cohete5=200;
  if(cohete6>200) cohete6=200;

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }

  delay(1); //Velocidad de los cohetes

  if(digitalRead(microfono) == HIGH && cohete1>(longitudCohete+3) && cohete2>longitudCohete+3 && cohete3>longitudCohete+3 && cohete4>longitudCohete+3 && cohete5>longitudCohete+3 && cohete6>longitudCohete+3){ //Si se activa el microfono y no hay ningun cohete saliendo (para evitar que salga mas de uno a la vez)
    coheteNuevo=1; //Se pone un cohete pendiente
  }
}