Hi!
I'm new to Arduino and I choose as my first project to make an LED unicorn horn for my girlfriend.
I use an Arduino Nano, 16 WS2812 LEDs (two of these in series: https://tinyurl.com/y75cnptz
) and the whole circuit is powerd by a 18650 and step up converter.
Everything worked perfectly so I wanted to see for how long the battery can run the whole circuit and LED-strip.
The lights made a nice cycling rainbow effect for about 3.5 hours and then all LEDs were shining red.
I thought at the time that the voltage just dropped to far for the other diodes but when I tried it again the next day (while being attached to 5v power) only the first 4 LEDs were lighting up.
I replaced the led strip, checked all voltage, reloaded the code but I can't find the reason for it not working anymore.
After replacing the leds now only the first 2 LEDS light up and the third flashes faintly when the battery is connected to the curcuit.
Life at this point doesn't make any sense to me anymore so I come here for help.
Below I will show my circiut and my code but I don't think there is anything with the code because it worked before.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
Adafruit_NeoPixel strip = Adafruit_NeoPixel(16, PIN, NEO_GRB + NEO_KHZ800);
const int buttonPin1 = 2;
const int buttonPin2 = 4;
int buttonState1 = 0;
int buttonState2 = 0;
int x = 0;
void setup() {
strip.begin();
strip.setBrightness(50);
strip.show(); // Initialize all pixels to 'off'
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
Serial.begin(9600);
colorWipe(strip.Color(204, 0, 102), 20); // Pink
colorWipe(strip.Color(0, 0, 0), 20); // off
colorWipe(strip.Color(204, 0, 102), 20); // Pink
colorWipe(strip.Color(0, 0, 0), 20); // off
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == HIGH || buttonState2 == HIGH)
{
while (x == 0) {
colorWipe(strip.Color(204, 0, 102), 50); // Pink
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == HIGH)
{
while (x == 0) {
rainbow(30);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == HIGH)
{
while (x == 0) {
rainbowCycle(20);
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
if (buttonState1 == HIGH || buttonState2 == HIGH)
{
colorWipe(strip.Color(0, 0, 0), 50); // off
delay(200);
return;
}
if (buttonState2 == HIGH)
{
colorWipe(strip.Color(0, 0, 0), 50); // off
delay(200);
return;
}
}
}
if (buttonState2 == HIGH)
{
colorWipe(strip.Color(0, 0, 0), 50); // off
delay(200);
return;
}
}
}
if (buttonState2 == HIGH)
{
colorWipe(strip.Color(0, 0, 0), 50); // off
return;
}
}
}
}
// 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);
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for (j = 0; j < 256; j++) {
for (i = 0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i + j) & 255));
}
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);
}
}
//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j = 0; j < 10; j++) { //do 10 cycles of chasing
for (int q = 0; q < 3; q++) {
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, c); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0); //turn every third pixel off
}
}
}
}
//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j = 0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q = 0; q < 3; q++) {
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, Wheel( (i + j) % 255)); //turn every third pixel on
}
strip.show();
delay(wait);
for (uint16_t i = 0; i < strip.numPixels(); i = i + 3) {
strip.setPixelColor(i + q, 0); //turn every third pixel off
}
}
}
}
// 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);
}
if (WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}