RGB LED Strip not executing code

Hi Tom,
I quickly realized that mistake and fixed the wiring. Now the problem persists in that the LED Strip sometime works and sometimes does not when the values in the dashboard are changed. I tried to ensure all the connections are firm. Hope you could help me out!

Hi,
We need to see your code.

Tom... :grinning: :+1: :coffee: :australia:

Yes Tom, here is the code:

* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/d4b645a4-12b7-47fb-84d9-952dbb47d38a 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int greenValue;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
int myPin=4;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 
  pinMode(myPin,OUTPUT); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  Serial.println(greenValue);
  delay(500);
}



/*
  Since GreenValue is READ_WRITE variable, onGreenValueChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onGreenValueChange()  {
  // Add your code here to act upon GreenValue change
  analogWrite(myPin,greenValue); 
  Serial.println(greenValue);
  delay(500);
}

Also, my arduino board is failing to get detected by the Arduino IOT Cloud software. Every now and then, a notification saying"Uncaught error, subscription failed," pops up.

Hello, I wonder about your led strip. Do all of the leds light up the same and can't be different colors? I have an old rope claimed RGB but has red, green and blue leds on 1 wire each color and one ground, 12V.

The BJT is going to get hot with much current draw.
If you use a Logic Level (opens full at !2V) FET, you PWM brightness as field effect transistors need to be full closed or full open to not burn up where bipolar junction transistors get hot with current flow but make great "valves".

But worth a million of those is WS2811 12mm tree lights that fit 1/2" holes and have easy-hack wires between and every bulb in the chain can be set with a 24 bit color, 0-255 each of red, green, and blue, 16 million shades and every bulb has a color that can change faster than seeing.

As you mentioned, my RGB LED strip has inidividual R,G and B LEDs and one 12V pin. The LEDs can't light up in different colours, and if I want a combination, I will have to code for all 3.

And could I understand what you are trying to explain here? Forgive my lack of experience.

And finally, what should I do so that I can get my contraption to work?

You have that inside a comment.
Not in your code.

I'm not familiar with IOT Cloud, so can't offer much help.

Tom... :grinning: :+1: :coffee: :australia:

gate opens with 2V, not 12 but 12 works.

Transistors close to stop current flow through.
They open to let current flow through.

BJT (T for transistor) opens by current flowing into the control pin. More current into control, many times more emitted if available.
Problem is BJT makes heat and not so good past 500 mA use.

FET opens by voltage through field effect, not current flow.
It is almost 100% efficient when full open or full closed.
Most power FETs need 10V to full open (for 12+V use) but FETs with L or LL in the part number mean low level voltage can open them safely full. I once got 60 FETs good for several amps at 5-12V for $10, about 15 cents each. Shop Around! I bought and used IRLZ44N FETs with built-in protection diodes for inductive loads for that price when to buy 1 or 2 they were near a dollar each! The price wasn't so bad each at $5 worth but at $10,,, 14.5 cents each, shipped!

With WS2811 (or any WS28xx strip) you connect 5V supply to the strip. The nodes power the RGB in one light. You connect the data line to an Arduino pin and run the FastLed Library and get super results. before 2020 I got 50 lights on 5 m for $15.

this is a price to beat, an Amazon seller.

1 Like

The 2N3904 will not work for you application.
Your strip needs 1A per color (total 3A) and the 2N3904 can only handle 0.2A.
Use a ZTX1049A

Sry, I think you've done all these experiments but I am not finding it looking through the small window, so state the results you got, or get, when you…

get one regular LED to function. Leave the strip aside, attach or don't a single LED maybe with a transistor driver. One LED can run directly off the Arduino.

So…

The function onGreenValueChange() gets magically called and changes your variable, I accept that rather than look into it.

With no external circuitry on the Arduino. Does the value printed for the magic variable greenValue change reliably with the external activity meant to make it do?

Can you place a single LED and series current limiting resistor (for 5 volt operation) on the Arduino output pin (pin -> resistor -> LED -> ground)) and observe correct behaviour?

Can you get success with a 2N3904 using it to drive a single LED and series resistor (for 12 volt operation) and the external power supply?

---> Using the blink sketch, but replacing digitalWrite(thePin, HIGH) with analogWrite(thePin, 255) and similarly analogWrite(thePin, 0) instead of LOW does the LED blink? Wire the LED without the transistor, just a resistor to ground.


You can see my questions march you through tests that should all work. Tests independent of the large strip. Tests independent of the magic external control signal. Tests the transistor. Tests the PWM output. Tests the reception for changes to greenValue.

Divide and conquer. If these test don't work, no point in using the strip yet.

I would think the 2N3904 would burn out pretty soon. I can't explain the less than satisfactory but continues to work functioning that you describe.

If all the test work, then it looks like you do need a beefier transistor or switch to a MOSFET circuit as has been suggested.

a7

2 Likes

↑ Excellent strategy ↑

Thank you
I will try it out and report the results soon

Hi Alto,
Sorry for the late reply.
I conducted the tests you mentioned, and here are the results.

I have a IOT Cloud "thing" named greenValue, and I set it as an integer with a limit from 0 to 255. I attempted to see the greenValue through the serial monitor, and I came to see that despite what value I put the number in my IOT Dashboard, the serial monitor always displayed 0.

I attempted to do the blink code using the analogWrite function, with both the 2N3904 transistor and a KA7904 MOSFET. Both did not work, with the RGB LED staying stuck at a constant brightness despite the changes I make to it. I also tried to wire the LED directly to the pin, and yet there was no effect.

Here is my blink code.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/ef390053-b36e-4f9d-af49-8f81cfec9710 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int greenValue;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
int greenPin=2;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 
  pinMode(greenPin,OUTPUT);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  analogWrite(greenPin,255);
  delay(200);
  analogWrite(greenPin,255);
  delay(0);
  Serial.println(greenValue); 
  delay(200);
  
}


/*
  Since GreenValue is READ_WRITE variable, onGreenValueChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onGreenValueChange()  {
  // Add your code here to act upon GreenValue change
  
}

Some boards have broken power rails.

Are you sure you have an RGB(W)LED? The devices in the spool looks like WS2812 of 30 per meter.

Writing 255 to the green pin should make it as bright as it gets.

But if you are trying to use as WS2812... those are digital, not analog! Those are ones you feed 5V, GND and a data pin that you need a library to handle the data timing.

My RGB leds have a bulb and 4 pins, WS28xx is modules. I like WS2811 Tree Lights because the modules have easy to hack wires in between the bulbs like 4 fingers wide insulated wires, not tiny pads to solder!
Some WS2811 are not 12mm dia tree light bulbs with the easy to hack wires so beware what you get. Bulbs have diffusers, when they light up it is the bulb that gets color, not as good for casting light.

This is what the tree lights look like unlit.
The diffuser bulbs blend the colors in each, 16 million shades possible and you can get more by changing color faster than eyes can see, like dimming a led with PWM.

OK, so your internet magic thing doesn't work. Leave that for later.

This code

turns on the green, delays, then turns on the green and delays. Rinse and loop.

It is no surprise that the green stays on.

If you have a single regular LED and appropriate series limiting resistor, you could perform experiments you have not reported doing.

Please post a .ink to and better pictures of your LED strip. If we've been working on a smart LED strip, it's all been quite a waste of time.

Maybe a picture of the end of the strip would have some pin names we could know for sure you have a regular RGB LED strip, meant to be used in the manner you are attempting.

a7

Hi Alto,
I retried my RGB LED with the same 2n3904 transistor, and it works now. A simple blink code generates the expected result. I came to realize I had many faulty transistors. The problem now is that the int greenValue remains at 0, as observed through the serial monitor, even though I am changing it from the dashboard.
image
I have ensured that my wifi has been set up properly for the cloud to work with. I am still confused as to why my changes from the dashboard are not syncing to my board. Here is my new code.

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/ef390053-b36e-4f9d-af49-8f81cfec9710 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int greenValue;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
int greenPin=2;
int greenVAL;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 
  pinMode(greenPin,OUTPUT);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
  
  analogWrite(greenPin, greenVAL);
  Serial.print("greenVAL=");
  Serial.println(greenVAL); 
  delay(500);
}


/*
  Since GreenValue is READ_WRITE variable, onGreenValueChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onGreenValueChange()  {
  // Add your code here to act upon GreenValue change
  greenVAL=greenValue;
}

Put a print statement in this function.

void onGreenValueChange()  {
  // Add your code here to act upon GreenValue change
  greenVAL=greenValue;
}

Just to see if it ever gets called…

a7

I just did, but despite all changes in the dashboard, the serial monitor displays nothing.
Thanks for staying with me

I'm about to shift gears here, but I am curious about thingProperties.h.

It looks like you have that in a tab, can you post it here like you did your code?

Obvsly if there are passwords and stuff remove them before.

a7