In earlier article, we discussed the basics around NeoPixel LED. We also warned about higher current consumption NeoPixel strips used for decoration. Connecting Single NeoPixel to Arduino is most simple. Thinking specially about the children, we feel that single NeoPixel is completely safe, affordable and easy for them. Here is Connection and Sketch For Arduino UNO Single NeoPixel Rainbow Blink. Adfruit Flora v2, comes with an onboard NeoPixel and Adafruit officially has code for it. We can do the similar thing with a single NeoPixel. Adafruit sells single NeoPixel on board, additionally you can buy strip of 5 NeoPixels, cut one and solder male headers. The soldering work, however not closest to easy. A trick probably will be to fix single one cut from the strip and glue on any kind of prototyping board. Also third party manufactured NeoPixel sold which are mounted on solid piece of board (usually they indicate that has WS2812B IC and Neopixel compatible), they are clones of Adafruit NeoPixel Mini PCB. Those 5 piece things are good for many purposes like building music visualizer.
Through-Hole NeoPixels also available, which looks lie normal LEDs but has 4 legs. Through-hole NeoPixels are RGB only – no white.
Arduino UNO Single NeoPixel Rainbow Blink : Connection and Code
First you need to install the Adafruit NeoPixel Library on your Arduino IDE :
---
1 | https://github.com/adafruit/Adafruit_NeoPixel |
On Arduino IDE, if you open File -> Examples -> Adafruit Neopixel -> simple, you’ll see examples are with 16 pixels (that means 16 NeoPixel LEDs). Basically, you can modify those example’s pixel to 1 for one single NeoPixel. One thing to keep in mind is that, NeoPixel draws some power even if they are not lit.
It is recommended that each NeoPixel have an accompanying 0.1 µF capacitor between +5V and ground to prevent communication problem. Also, data in pin needs a 330 Ohm resistor. Practically, only resistor to data pin is enough :
Wiring is easy. It becomes difficult when the number becomes more than 2. Our code will go like this when data pin at pin number 8 :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #include <Adafruit_NeoPixel.h> #define PIN 8 Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800); void setup() { strip.begin(); strip.setBrightness(50); strip.show(); // Initialize all pixels to 'off' } void loop() { // Some example procedures showing how to display to the pixels: colorWipe(strip.Color(255, 0, 0), 500); // Red colorWipe(strip.Color(0, 255, 0), 500); // Green colorWipe(strip.Color(0, 0, 255), 500); // Blue rainbowCycle(20); } // Fill the dots one after the other with a color void colorWipe(uint32_t c, uint8_t wait) { for(uint16_t i=0; i<strip.numPixels(); i++) { strip.setPixelColor(i, c); strip.show(); delay(wait); } } // Slightly different, this makes the rainbow equally distributed throughout void rainbowCycle(uint8_t wait) { uint16_t i, j; for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel for(i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255)); } strip.show(); delay(wait); } } // Input a value 0 to 255 to get a color value. // The colours are a transition r - g - b - back to r. uint32_t Wheel(byte WheelPos) { WheelPos = 255 - WheelPos; if(WheelPos < 85) { return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3); } else if(WheelPos < 170) { WheelPos -= 85; return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3); } else { WheelPos -= 170; return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0); } } |