I've got an Arduino with a WS2812 hooked up to it, powered by the USB on my computer and I am trying to run the following code:
#include <FastLED.h>
#define NUM_LEDS 144
#define DATA_PIN 6
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.show();
}
void loop() {
for(int dot = 0; dot < NUM_LEDS; dot++) {
fill_solid(leds, NUM_LEDS, CRGB::Red);
leds[dot] = CRGB::Black;
leds[dot] = CRGB::Blue;
FastLED.show();
leds[dot] = CRGB::Red;
delay(30);
}
}
void setAll() {
FastLED.show();
}
What this does is sets all the LEDs to red, then goes through each one turning it off, then to blue and then back to red.
For some reason, it gets X number of LEDs along and then crashes. By crashes I mean the Arduino disconnects itself from the computer, but the Arduino stays on with the LED strip still powered up.
Any ideas? This is a genuine Uno.
Also. If I plug the LED into the 3.3v pin, the animations works just fine, but the LED flashes black and doesn't complete the Blue part.
I never used the NeoPixels, so I'm not really sure about this, but I'm pretty confident these will solve your problem.
First of all, your program. I don't think it is doing what you think it should do. Try with this loop, instead:
void loop()
{
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
delay(100);
for(int dot = 0; dot < NUM_LEDS; dot++)
{
leds[dot] = CRGB::Black;
FastLED.show();
delay(100);
leds[dot] = CRGB::Blue;
FastLED.show();
delay(100);
leds[dot] = CRGB::Red;
FastLED.show();
delay(100);
}
}
and remove the SetAll function, since it is useless.
Try this code with NUM_LEDS set to 5, and it should work.
Now the main problem: are you really using 144 leds powered by the USB? I suggest you to read this link about powering the neopixels. Particularly the part stating that at full brightness each neopixel draws 60mA. Doing the math, 144 neopixels draw at most 8.64A, so you need a 5V 10A power supply to power them all! a USB with 5V 0.5A will just shut itself down when you try to turn them on, thus giving you strange behaviors.
So lower the number of leds you are using (7 at most), or use an external power supply. And by external I do not mean use the barrel jack on the arduino, but connect a 5V 10A (or more amps) to the neopixel strip, then the ground and data wire to the arduino (not the +5v) and power the arduino through the usb port: it should work.
UPDATE:
According to the chat with the author, the problem was indeed the power supply
The datasheet from adafruit https://cdn-shop.adafruit.com/datasheets/WS2812.pdf says that you need a power supply between 6v and 7v but USB cannot provide more than 5v, I am guessing the arduino crashes because it cannot find enough power.
Can you try using an external power supply?
Related
I purchased a 5 meter strip of WS2812B LEDs to be used in conjunction with a motion detector (WS2812B 5 Pins RGBW RGBWW 4 IN 1 LED Strip Light Non-Waterproof DC5V).
The strips are hooked up to a 5V power supply (USB powerbank) and GND/5V/signal on pin 6 on an arduino UNO.
I should note that I so far have not cut the LED strip, so all 5 meters are intact.
I've tried getting the LEDs to emit simple colors using the FASTLED library using the code below. The Blue/blue/blue combination results in the colors Blue/Red/Green on LEDs 0-2
Changing to Red/Red/Red produces Yellow-ish/blue/off
Changing to Green/Green/Green produces the colors Red/lightgreen-ish/off
I've tried shifting from RGB to RBG color scheme to no avail
I don't have much information on the LED strip apart from what I have already provided you with
Can you give me any ideas on how to proceed?
#include "FastLED.h"
#define NUM_LEDS 5
#define DATA_PIN 6
// Define the array of leds
CRGB leds[NUM_LEDS];
void setup()
{
//FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS); // for GRB LEDs
}
void loop()
{
leds[0] = CRGB::Blue;
leds[1] = CRGB::Blue;
leds[2] = CRGB::Blue;
FastLED.show();
delay(500);
This might not be the exact answer you are looking for, but I’d suggest using the Adafruit_Neopixel.h library for your LED’s. Just did a Projekt with that library and the exact LED strip you are using and it is working great so far.
#include "Adafruit_NeoPixel.h"`
#define LED_PIN 6
#define LED_COUNT 60
Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
int red = 100;
int green = 0;
int blue = 0;
void setup() {
strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP}
}
void loop() {
for (i=0; i<LED_COUNT; i++){
strip.setPixelColor(i, strip.Color(Red, Green, Blue));
strip.show();
}
}
This should make 60 LED’s red. I’ve also got an LED Project on my GitHub page if you want to look that up. If the code above still doesn’t work I assume your wiring is wrong. I power my chip and LEDs off a power supple and also use the ground of the power supply.
I have a problem with flickering neopixel leds. I'm using a setup of 6 strips of 8xWS2812 5050 leds. I've connected these to a 5v power supply (USB charger) and an Arduino Uno running the Neopixel simple example code:
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 48
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 50; // delay for half a second
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
// End of trinket special code
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
for(int i=0;i<NUMPIXELS;i++){
pixels.setPixelColor(i, pixels.Color(200,200,200)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
delay(delayval); // Delay for a period of time (in milliseconds).
}
}
I've connected a 500uf 10v capacitor between the 5v and the gnd. And a 470 ohm resister between the arduino and the datapin.
I've noticed that the leds also flicker when the leds are on and the datapin is disconnected. The flickering is subtle, but annoying.
I've also tried an alternative power supply. For this I used a adjustable lab power supply. But the same problem persists.
I have to use these leds for a project that I need to finish tomorrow. (I know i should have done this earlier) Is there anyone who could offer me some help? I could really use some.
EDIT: The flickering had to do with the quality of the leds. These weren't real neopixels, instead I received some bad fake ones.
I am trying to attach a servo on an Arduino (branded) Robot but not sure whhich pin to use for the bellow code.
Most people seem to recommend to use pin 9 and 10 to control the servo for arduino Unos.
However, I can't use Pin 9 because that is already used as the Slave Select pin for the LCD.
I have tried attaching it to pins TKD0-TKD3 by calling them pins 19-22 in myservo.attach(). The code runs but the servo doesn't rotate and only gets hot and/or twitches.
Could the problem be something other than incorrect pin connection?
Thanks,
-M
I have been referencing these for the Control board pin mapping:
http://arduino.cc/en/Main/Robot)
http://fabcirablog.weebly.com/blog/grappling-with-the-arduino-robot-control-board
#include <Servo.h>
Servo myservo; // create servo object to control a servo
int pos = 0;
void setup()
{
myservo.attach(19); // attaches the servo on pin 9 to the servo object
}
void loop()
{
for(pos = 0; pos < 60; pos += 1)
{
myservo.write(pos);
delay(15);
}
for(pos = 60; pos>=1; pos-=1)
{
myservo.write(pos);
delay(15);
}
}
You have this robot, right?
Arduino Robot
And you are using a classic servo (3 pins, yellow red and black cable)? If so.... Watch out. According to the schematic, the pinout of the connector on the board (e.g. TKD0) is
+5V
AD1
GND
While usually servos have
DATA
+5V
GND
So.. you have to make a short cable to invert the pins.
If that's not the problem.. Are you sure that 19 is the right number for the pin? I can't find references, but i suggest you to call it TKD0 (which is probably a macro defining the right pin), as arduino designers suggest you.
I'm playing around with an Arduino Uno, and an RGB led-strip (Ikea Dioder 4 strips, only one is connected). Primary and secondary colors look fine when writing 255 to one or two colors. The problem is when I want white light (e.g. 255 on all three LEDs), then instead of becoming fully white, it just turns off.
I have an ethernet-shield connected to the Arduino, and a seperate 12V dc powersource. When I connect the power source to the Arduino, it works, but the regulator gets insanely hot (known issue). So I connect the LEDs to the 12V power source directly (they are rated at 12V, the Ikea one is also 12V). Only this causes the problem.
In the program below I can see it very clearly. The code should do the following: fade to red; fade to yellow; fade to white; repeat. The first two go fine, but when it's time to fade to white, it fades to black instead. It just turns off. And I have no idea why.
int redPin = 3;
int greenPin = 5;
int bluePin = 6;
int color[] = {3, 5, 6};
int i = 0;
int j = 0;
void setup(){
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop(){
for(i=0;i<=2;i++)
{
for(j=0;j<=255;j++)
{
analogWrite(color[i],j);
delay(5);
}
}
delay(1000);
analogWrite(redPin, 0);
analogWrite(bluePin, 0);
analogWrite(greenPin, 0);
}
Since it works fine then powered from Arduino, I guess this is hardware, not software problem. Arduino port providing around 40mA, while each colour of Dioder sync around 140mA. Do you use any amplification, like FET or ULN2003? Can you post your schematic?
The problem has been solved (I think) by connecting the GND for the IC and the (-) side of the adapter to the GND of the Arduino.
So my problem is as title says: Arduino UNO analogRead always returns 1023.
But when I burn the same sketch in Arduino Mega 2650 everything works like a charm.
I have tried to change Atmel chips on the UNO, have tried like 3 of them (ATMEGA328P-PU) and nothing changes.
I'm trying to count signals from a hall effect sensor and display the count on a 7 segment display.
Here is the code:
#include "SevSeg.h"
SevSeg sevseg;
volatile int rpmcount;
void setup() {
Serial.begin(9600);
pinMode(2,INPUT_PULLUP);
rpmcount = 0;
sevseg.Begin(1,3,4,5,6,7,8,9,10,11,12,13);
}
int border=15;
void loop() {
int tmp=0;
tmp = analogRead(0);
if(!digitalRead(2))rpmcount=0;
Serial.println(tmp,DEC);
if(tmp<=border && res >border){
rpmcount++;
if(rpmcount>9999)rpmcount=0;
}
res=tmp;
sevseg.NewNum(rpmcount,(byte) 0);
sevseg.PrintOutput();
}
Any help would be much appreciated
This sounds to me as if you had the internal pullup resistor on the ADC pin enabled.
generic checklist:
ACD bit in ACSR is 0 (comparator enable)
MUX bits in ADMUX set properly
correct AREF selected
ADC pin set as input
internal pull up resistors are deselected