How to Create Rainbow With LEDs in TinkerCad

by LakshayTheGupta in Circuits > Arduino

416 Views, 2 Favorites, 0 Comments

How to Create Rainbow With LEDs in TinkerCad

Screenshot 2023-07-24 at 12.02.24 AM.png

In this project, we aim to design a beautiful rainbow using LEDs in Tinkercad. Each row of LEDs connect in series, are connected in parallel , to create the spectrum. This project combines creativity, electronics, and programming to bring the beauty of a rainbow to life.

Supplies

For this project, we need an account on TinkerCad. You can also recreate it in real life if you have all the required components:

  1. Arduino Board: We will use the Arduino board as the brain of the project, controlling the LEDs and their lighting patterns.
  2. 105 LEDs: Each LED will represent a different color of the rainbow, creating a striking visual effect when lit up. I used 105 LEDs. You can also use fewer LEDs, but the more LEDs, the better it looks.
  3. 25 Red LEDs
  4. 23 Orange LEDs
  5. 25 Yellow LEDs
  6. 25 Green LEDs
  7. 25 Blue LEDs
  8. 25 LED RGB: As for the remaining 2 colors, we do not have similar colored LEDs; we will create those colors using RGB LEDs.
  9. Resistors: To protect the LEDs from excessive current, we will use resistors in series with each LED.
  10. Connecting Wires: These will be used to interconnect the LEDs with the Arduino board, ensuring the proper flow of electricity. Use similar-colored wires for better results.

Downloads

Creating the Circuit for Red Color

Screenshot 2023-07-23 at 6.41.15 PM.png

Take all the red LEDs. Arrange them in an arch shape to resemble a rainbow as you put the circuit together. We have to connect each LED's longer leg (anode) to the Arduino board's digital pins using a separate resistor. To avoid the mess, instead of connecting every LED to the digital pin, we can connect all the same-colored LEDs in series. Now we only need to connect one end of the wire to the particular digital pin. The ground (GND) pin on the Arduino board is where you connect the cathodes of all LEDs in a similar way.


Add Orange,Yellow,Green,Blue LEDs

Screenshot 2023-07-23 at 7.40.27 PM.png

In a similar way, add Orange, Yellow, Green, and Blue LEDs in series and connect them to ground and their respective digital pins. Make sure the digital pins you select are next to each other so that we can later use a for loop to easily control each color

Add RGB LEDs for Indigo and Violet Colors

Screenshot 2023-07-23 at 8.33.39 PM.png
Screenshot 2023-07-23 at 8.26.30 PM.png
Screenshot 2023-07-23 at 8.32.15 PM.png

A RGB LED has four connection points.

  1. Red
  2. Cathode
  3. Blue
  4. Green

For Indigo, We will connect the Blue pin to the anode. Experiment with the values of Resistance to get a color similar to Indigo.


Now for Violet, We will use blue with a little help from red to get the required color. For this, we can connect the Blue and Red pins. But we get a pink color. This is because the red color is more than what's needed. To reduce the amount of red, we can add resistance in between. Again, experiment with values of resistance to get the required color.

Code the Pattern

Select the Code Menu in the top-left and change the edit mode to "Text".

Paste this code:

int firstDigitalPin = 6;
int lastDigitalPin = 12;

void setup()
{
   for(int i=firstDigitalPin;i<=lastDigitalPin;i++){
     pinMode(i, OUTPUT);}
}


void loop()
{
  for(int i=firstDigitalPin;i<=lastDigitalPin;i++){
  digitalWrite(i, HIGH);
  delay(100);
  }
   delay(1000); 
  for(int i=firstDigitalPin;i<=lastDigitalPin;i++){
  digitalWrite(i, LOW);
  delay(100);
  }
   delay(500); 
}

Change the firstDigitalPin value to the lowest value among the selected digital pins. Mine is 6 (connected to violet).

In the loop() function, the LEDs light up one by one in order, with a 100-millisecond delay between each similar-colored LED turning on. After all the LEDs are lit, there is a 1-second pause before the LEDs turn off in the same sequence with the same delay. This cycle repeats continuously, creating an engaging LED light show with a beautiful sequence of lighting and fading effects, creating our Rainbow.

The pins that will be used as output are assigned in the setup() function.

Tweek values or write new logic to create a new pattern.

You Just Made a Beautiful Rainbow

ezgif.com-video-to-gif.gif

Start the simulation