Arduino Tinkercad NeoPixel for Rainbow Led's
by Aryan007 in Circuits > Arduino
1302 Views, 3 Favorites, 0 Comments
Arduino Tinkercad NeoPixel for Rainbow Led's
This is a fun project using Arduino and Neo Pixel Leds. The Colorful Led lights are displayed on Neo Pixel bands forming a pattern based on Rainbow. There are also Led's Connected in alphabets called "Welcome" which has Rainbow colors that look awesome at night time.
Stay tuned, and watch out the video attached to get more idea about it, I've also attached all connections and code below with brief explanation. Let's get started!! Enjoy...
Supplies
Welcome, here we'll discuss what components are required to build this project!
- Arduino UNO R3
- NeoPixel strip 8 (6 in Total)
- (15) Red Led's
- (13) Blue Led's
- (4) Orange Led's
- (5) Green Led's
- (6) Yellow Led's
- (36) 1 Ohm Resistors
- Few wires as per requirement
- External Power supply
Please Note You can even use Your own custom Colored Led as per Your preference.
Connecting NeoPixel With Arduino
Firstly we will see how to connect the components:
- NeoPixel strip 8 has total 3 connections
- 1st is input connection - Connect it with PWM pin of Arduino
- 2nd is power connection - connect it with Arduino's +5V
- 3rd is ground connection - connect it with Arduino's Ground
Note: why use PWM (Pulse Width Modulation) pin ??
-> Digital pins will only give 1 or 0 (LED ON or OFF for Particular color only) but we need more colors which can be only be done using RGB leds.
Here we've used 6 NeoPixel strip:
Connection is as follows:
Strip 1 NeoPixel input pin - Pin 3 of Arduino
Strip 2 NeoPixel input pin - Pin 5 of Arduino
Strip 3 NeoPixel input pin - Pin 6 of Arduino
Strip 4 NeoPixel input pin - Pin 9 of Arduino
Strip 5 NeoPixel input pin - Pin 10 of Arduino
Strip 6 NeoPixel input pin - Pin 11 of Arduino
(NOTE: All this strips are arranged vertically)
You will find the connection idea in attached picture!
Now note that here we've also used simple Led's and created a alphabetical shape - character "Welcome"
As we know Led has 2 legs. 1 leg for ground and other is power.
We've used about 43 Led's its not possible to connect with individual pin of Arduino.
So, we've connected all 43 pins and by using only 1 pin we can Blink all the 43 Led's.
Arrange the Led's in Welcome shape and the shorter legs of all Led's are connected together and attached to Ground pin of Arduino.
Now all the longer legs are connected together but using 1 Ohm resistor, attach that with any digital pin of Arduino.
There is an idea about connecting leds in attached image for reference.
Program Code Part 1
The Program code is too long to remember or understand. So we'll break down the code to understand it better!
Step 1.
To use NeoPixel we need to include Header File/ Library
- #include <Adafruit_NeoPixel.h>
Step 2.
We have used 6 NeoPixel so for better understanding of code we'll define them
#define Line_1 3 // this is 1st strip
#define Line_2 5 // this is 2nd strip
#define Line_3 6 // this is 3rd strip
#define Line_4 9 // this is 4th strip
#define Line_5 10 // this is 5th strip
#define Line_6 11 // this is 6th strip
you can also name them as per your preference.
Step 3.
#define LED_COUNT 16
int myDelay = 220; // you can decrease for better lighting
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, Line_1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(LED_COUNT, Line_2, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(LED_COUNT, Line_3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip4 = Adafruit_NeoPixel(LED_COUNT, Line_4, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip5 = Adafruit_NeoPixel(LED_COUNT, Line_5, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip6 = Adafruit_NeoPixel(LED_COUNT, Line_6, NEO_GRB + NEO_KHZ800);
Please go through this link for understanding NeoPixel code.
https://learn.adafruit.com/adafruit-neopixel-uberguide/arduino-library-use
Step 4. (setup)
void setup() {
strip.begin();
strip.show();
...
...
strip6.begin();
strip6.show(); // Code is longer so I've skip here (but attached original code below)
pinMode(13,OUTPUT);
}
Step 5. (Loop)
void loop() {
digitalWrite(13,HIGH);
hide_colors();
go_second();
go_third();
go_forth();
go_fifth();
go_sixth();
go_seventh();
go_eight();
}
Downloads
Main Logic and Functions
Before we move into functions, here is logic behind it.
Columns in our NeoPixel is 8 that's why its called NeoPixel strip 8
We have used total 6 NeoPixels strips, so rows in NeoPixel here is 6
Imagine following '#' as NeoPixel Leds
this is our connection:
# # # # # # # # // NeoPixel 1 with 8 Columns
# # # # # # # # // NeoPixel 2 with 8 Columns
# # # # # # # # // NeoPixel 3 with 8 Columns
# # # # # # # # // NeoPixel 4 with 8 Columns
# # # # # # # # // NeoPixel 5 with 8 Columns
# # # # # # # # // NeoPixel 6 with 8 Columns
Let's break this, suppose we have single NeoPixel for now:
Below (1 means light is ON state)
E.g.
# # # # # # # 1
0 1 2 3 4 5 6 7 //Note: this starts from 0 to 7 columns
To make 8th Column Blink,
Code for this should be:
strip.setPixelColor(7, 255, 0, 0);
strip.show();
Understanding this:
strip.setPixelColor(7, 255, 0, 0);
Strip.setPixelColor() is inbuilt function which takes 4 argumments by default.
1st argument is column number:
- So to make on 8th column it should be 7
2nd, 3rd and 4th arguments are Rgb values:
- Here R = 255, G = 0, B = 0
- Which means Red Color would be flash
strip.show() is inbuilt function
Next Exercise:
# # # 1 # # # # -> suppose this is strip 1 (see declaration part above)
# # # 1 # # # # -> suppose this is strip 2
To make 4th column ON of strip 1 and strip 2
Code:
strip1.setPixelColor(3, 255, 0, 0);
strip1.show();
strip2.setPixelColor(3, 255, 0, 0);
strip2.show();
The same is for all the other Led's just remember to ON led in sequence for good lighting.
Note: Using Delay in my code?
- In Tinkercad there is no real lighting and designs so to check whether leds are blinking in sequence or not, delay is used.
- One can change the value of delay as per requirements. (Its declared globally so changing its value will affect in full code).
Program Code Part 2 (cont..)
void go_second(){
//step 1
strip5.setPixelColor(7, 255, 0, 0);
strip5.show();
delay(myDelay);
strip5.setPixelColor(6, 255, 0, 0);
strip5.show();
delay(myDelay);
strip6.setPixelColor(6, 255, 0, 0);
strip6.show();
delay(myDelay);
}
void go_third(){
strip4.setPixelColor(7, 255, 165, 0);
strip4.show();
delay(myDelay);
strip4.setPixelColor(6, 255, 165, 0);
strip4.show();
delay(myDelay);
strip4.setPixelColor(5, 255, 165, 0);
strip4.show();
delay(myDelay);
strip5.setPixelColor(5, 255, 165, 0);
strip5.show();
delay(myDelay);
strip6.setPixelColor(5, 255, 165, 0);
strip6.show();
delay(myDelay);
}
void go_forth(){
strip3.setPixelColor(7, 0, 255, 0);
strip3.show();
delay(myDelay);
strip3.setPixelColor(6, 0, 255, 0);
strip3.show();
delay(myDelay);
strip3.setPixelColor(5, 0, 255, 0);
strip3.show();
delay(myDelay);
strip3.setPixelColor(4, 0, 255, 0);
strip3.show();
delay(myDelay);
strip4.setPixelColor(4, 0, 255, 0);
strip4.show();
delay(myDelay);
strip5.setPixelColor(4, 0, 255, 0);
strip5.show();
delay(myDelay);
strip6.setPixelColor(4, 0, 255, 0);
strip6.show();
delay(myDelay);
}
void go_fifth(){
strip2.setPixelColor(7, 0, 0, 255);
strip2.show();
delay(myDelay);
strip2.setPixelColor(6, 0, 0, 255);
strip2.show();
delay(myDelay);
strip2.setPixelColor(5, 0, 0, 255);
strip2.show();
delay(myDelay);
strip2.setPixelColor(4, 0, 0, 255);
strip2.show();
delay(myDelay);
strip2.setPixelColor(3, 0, 0, 255);
strip2.show();
delay(myDelay);
strip3.setPixelColor(3, 0, 0, 255);
strip3.show();
delay(myDelay);
strip4.setPixelColor(3, 0, 0, 255);
strip4.show();
delay(myDelay);
strip5.setPixelColor(3, 0, 0, 255);
strip5.show();
delay(myDelay);
strip6.setPixelColor(3, 0, 0, 255);
strip6.show();
delay(myDelay);
}
void go_sixth(){
strip.setPixelColor(7, 143, 0, 255);
strip.show();
delay(myDelay);
strip.setPixelColor(6, 143, 0, 255);
strip.show();
delay(myDelay);
strip.setPixelColor(5, 143, 0, 255);
strip.show();
delay(myDelay);
strip.setPixelColor(4, 143, 0, 255);
strip.show();
delay(myDelay);
strip.setPixelColor(3, 143, 0, 255);
strip.show();
delay(myDelay);
strip.setPixelColor(2, 143, 0, 255);
strip.show();
delay(myDelay);
strip2.setPixelColor(2, 143, 0, 255);
strip2.show();
delay(myDelay);
strip3.setPixelColor(2, 143, 0, 255);
strip3.show();
delay(myDelay);
strip4.setPixelColor(2, 143, 0, 255);
strip4.show();
delay(myDelay);
strip5.setPixelColor(2, 143, 0, 255);
strip5.show();
delay(myDelay);
strip6.setPixelColor(2, 143, 0, 255);
strip6.show();
delay(myDelay);
}
void go_seventh(){
strip.setPixelColor(1, 255, 255, 0);
strip.show();
delay(myDelay);
strip2.setPixelColor(1, 255, 255, 0);
strip2.show();
delay(myDelay);
strip3.setPixelColor(1, 255, 255, 0);
strip3.show();
delay(myDelay);
strip4.setPixelColor(1, 255, 255, 0);
strip4.show();
delay(myDelay);
strip5.setPixelColor(1, 255, 255, 0);
strip5.show();
delay(myDelay);
strip6.setPixelColor(1, 255, 255, 0);
strip6.show();
delay(myDelay);
}
void go_eight(){
strip.setPixelColor(0, 255, 0, 0);
strip.show();
delay(myDelay);
strip2.setPixelColor(0, 255, 0, 0);
strip2.show();
delay(myDelay);
strip3.setPixelColor(0, 255, 0, 0);
strip3.show();
delay(myDelay);
strip4.setPixelColor(0, 255, 0, 0);
strip4.show();
delay(myDelay);
strip5.setPixelColor(0, 255, 0, 0);
strip5.show();
delay(myDelay);
strip6.setPixelColor(0, 255, 0, 0);
strip6.show();
delay(myDelay);
strip6.setPixelColor(7, 143, 0, 255);
strip6.show();
delay(myDelay);
}
//This function makes all Led OFF
void hide_colors(){
strip.clear();
strip.show();
strip2.clear();
strip2.show();
strip3.clear();
strip3.show();
strip4.clear();
strip4.show();
strip5.clear();
strip5.show();
strip6.clear();
strip6.show();
delay(500);
}
Downloads
Conclusion
This was just a basic idea about the Led's using NeoPixels, there are varieties of NeoPixel strips available in the market.
One can use it according to need.
If you find any error or suggestions in my project please do let me know, I would be happy to optimize it!
Thank you...