Please check out my code and tell me why the LED lights don't work! :(

Hi everyone,

As my username states I am new to Arduino. I wrote a sketch that grabs RGB color codes from a PHP website, and then uses the RGB code to turn on red, green, and blue LED lights on the Arduino.

The Arduino is hooked up to an Aysnc WiShield which allows the Arduino to connect directly to my wireless router. The Arduino successfully reads and parses my website to isolate an RGB color code (and a second number which will be used later to make the LEDs "pulse" but that's not important now).

My problem is that once I've already successfully parsed and isolated the RGB color code, I cannot make my LED lights come on. Here's my sketch, I think the problem lies somewhere in the printData function or ConvertStringtoRGB function (where I try to turn on the lights using analogWrite):


Here's the output in the Serial monitor of the code above, which works great in that it shows I've successfully parsed the website and put the RGB color code into the String strColor:

Request #1 sent at 45 seconds. 
19f1ff
R:1 G:159 B:31
0

Request #2 sent at 105 seconds. 
386aff
R:3 G:134 B:176
0

Request #3 sent at 165 seconds. 
ffc801
R:15 G:252 B:128
0

The problem is that once I UNCOMMENT the 3 analogWrite functions at the bottom of ConvertStringToRGB the Arduino gets stuck after the first Request. The output in the Serial monitor looks like this below and the LED lights do come on according to the RGB color code just ONCE, but the program doesn't move on to Request #2 like the earlier output. There's just no more output in the Serial monitor so I think the program is STUCK?

Request #1 sent at 45 seconds. 
19f1ff
R:1 G:159 B:31
0

How do I successfully light up my LED lights according to the RGB code in strColor every 60 seconds? (Btw, the LEDs are physically fine, I checked them all out with other sketches and all 3 are capable of lighting up). Please help! I've been stuck on this problem for days! :~

The wifi shield uses pins 10 and 11 - you can't use them to control the leds - try 3,5 and 6

Hi WildBill!

Thanks for your speedy reply! I switched to 3, 5, and 6 instead of 9, 10, 11...and the LED doesn't seem to light up like they should. For example, see this output:

Request #4 sent at 225 seconds. 
fe0000
R:15 G:224 B:0   -----> (here, the RED LED is blinking on/off and is very dim when on, 
                                the GREEN LED is OFF, and the BLUE LED is lit up VERY brightly)
0

Request #5 sent at 285 seconds. 
83cb84
R:8 G:60 B:184  -----> (here, the RED LED is blinking on/off and is very dim when on, 
                              the GREEN LED is OFF, and the BLUE LED is lit up with MEDIUM brightness)
0

Request #6 sent at 345 seconds. 
009900
R:0 G:9 B:144 -----> (here, the RED LED is blinking sporadically and is very dim when on,
                              the GREEN LED is OFF, and the BLUE LED is VERY DIM)
0

Request #7 sent at 405 seconds. 
386aff
R:3 G:134 B:175 -----> (here, the RED LED is blinking on/off and is very dim when on,
                                 the GREEN LED is OFF, and the BLUE LED is lit up VERY brightly)
0

I don't get it! Any ideas what is going on? Thanks for any help you're able to provide.

I suggest that you copy your sketch and remove all the code except the lines that initialise the LED pins, and then just write some constant values to them. Do the LEDs behave as you expect?

How do you have the LEDs wired up?

WildBill and PeterH,

Thank you both for helping me out so quickly!! WildBill, you were right about using 3, 5, 6. I thought I had implemented the changes, but it wasn't until PeterH's comment that I triple-checked everything and realized that I hadn't made all of the changes properly (wiring-wise & code-wise).

So...in conclusion, it works now! Again, thank you both for your help!