(SOLVED) RGB led strip with potentiometers - one output always high?

This has since been solved. TLDR: Cause was dodgy A0 and A1 analog pins. Bought that way.

Hi all,
I recently bought an Uno clone. Works well except for one issue. I'm controlling an rgb strip through mosfets using one potentiometer for each colour. The pwm pins are 9,10,11. No matter what pwm pins i choose, one of them always stays high. In this case, pin 11 lights blue led and its always on fairly dim. I can control the other colours just fine, but blue stays on. My first thought was that pin 11 was borked, so i changed the code to use pin 6 instead. Same issue. I swapped colours around and its not the led strip or the mosfets causing the problem. Its only the third pwm pin, whichever pin it is.

My analog inputs are A0(blue), A1(green), A2(red)
Any ideas?

This is the code:

int writeValue_red; //declare variable to send to the red LED
int writeValue_green; //declare variable to send to the green LED
int writeValue_blue; //declare variable to send to the blue LED

void setup() {
pinMode(potPin_red, INPUT); //set potentiometer for red LED as input
pinMode(potPin_green, INPUT); //set potentiometer for green LED as input
pinMode(potPin_blue, INPUT); //set potentiometer for blue LED as input

pinMode(redPin,OUTPUT); //set pin for red LED as output
pinMode(bluePin,OUTPUT); //set pin for green LED as output
pinMode(greenPin, OUTPUT); //set pin for blue LED as output
}

void loop() {
readValue_red = analogRead(potPin_red); //Read voltage from potentiometer to control red LED
readValue_green = analogRead(potPin_green); //Read voltage from potentiometer to control green LED
readValue_blue = analogRead(potPin_blue); //Read voltage from potentiometer to control blue LED

writeValue_red = (255./1023.)*readValue_red; //Calculate the value to write on the red LED (add point to change to float point)
writeValue_green = (255./1023.)*readValue_green; //Calculate the value to write on the green LED
writeValue_blue = (255./1023.)*readValue_blue; ///Calculate the value to write on the blue LED

analogWrite(redPin,writeValue_red); //write value to set the brightness of the red LED
analogWrite(greenPin,writeValue_green); //write value to set the brightness of the green LED
analogWrite(bluePin,writeValue_blue); //write value to set the brightness of the blue LED
}

I assume the problem is with the MOSFET circuit (or maybe the MOSFET). You can try a digitalWrite() or you can try disconnecting Arduino, and ground the wire going to the MOSFET to see if it turns-off.

Or, test the Arduino & pots with regular LEDs (with current limiting resistors, of course).

I swapped the mosfet for a TIP120 with 1k base resistor and had the same problem. The pot still controls the led, but on its minimum setting its not off as it should be.

(deleted)

Thanks. Ok I've narrowed it down a bit. All the pots go down to about 3 ohms. With the serial print command, I can see that any pot connected to A0 will only go from 30-920 in the serial monitor. If I swap it to another analog input, then its fine.

If I connect a different pot to A0, it suffers the same problem. Why only on A0?

Maybe you toasted the A0 pin somewhere in your experimentation. Does the driver circuit use 12V?

Yes the whole thing is powered by 12V. Well. I'm stumped. Now it looks like it's all of them. They're all dimly lit when they should be off. I checked the voltage on all the output pins and they go from 29mV up to 5V, which seems fine...

Perhaps it is the mosfets not turning off, but the transistors do the same.

Post a complete schematic.

(deleted)

writeValue_red = (255./1023.)*readValue_red; //Calculate the value to write on the red LED (add point to change to float point)
Why float.
Just divide potValue by four, or bitshift two places.
Untested.

const byte red = 9;
const byte green = 10;
const byte blue = 11;

void setup() {
  pinMode(red, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(blue, OUTPUT);
}

void loop() {
  analogWrite(red, analogRead(A0) >> 2);
  analogWrite(green, analogRead(A1) >> 2);
  analogWrite(blue, analogRead(A2) >> 2);
}

Here is the design I used. The only changes i have are i'm using mosfets (IRLB8721PBF) and 12V rgb strip. What i've tried:

  1. Using TIP120 transistors with 1k base resistor.
  2. Adding 10k gate-source resistors on the mosfets.
  3. Powering the arduino from usb and led from 12v (with ground commoned between the two)
  4. Powering both arduino and leds from same 12v supply.
  5. Using code from another source. (didn't have the float command as mentioned above)

No matter what I try, the minimum pot setting doesn't turn off the strip. It stays dimly lit. Adjusting the pots to max brightness works a treat though.

Have you tried a serial print debug of the values you're sending to the output pins?

No I used a multimeter to check the voltages on the output pin. Strangely enough, I just tried this schematic (with added mosfet) and its happening here too. I'm using one colour of the rgb strip only and one pot. Same dimly lit LED when pot is at 0, regardless of which analog pin i use for pot. Changing outpin pin has no effect either. However, using a transistor (TIP120) it works fine!

/* POT to LED test -> by Owen Mundy March 11, 2010
from: http://itp.nyu.edu/physcomp/Labs/AnalogIn
—————————————————————*/

int potPin = 0; // Analog input pin that the potentiometer is attached to
int potValue = 0; // value read from the pot
int led = 9; // PWM pin that the LED is on. n.b. PWM 0 is on digital pin 9

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
// declare the led pin as an output:
pinMode(led, OUTPUT);
}

void loop() {
potValue = analogRead(potPin); // read the pot value
analogWrite(led, potValue/4); // PWM the LED with the pot value (divided by 4 to fit in a byte)
Serial.println("hello"); // print the pot value back to the debugger pane
delay(10); // wait 10 milliseconds before the next loop
}

Time to post a real picture of the setup.

Back to basics
Remove everything except the three wires from the pot, and run this sketch.
It should return 0-1023.
Leo..

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(analogRead(A0));
  delay(100);
}

Its exactly as the first image I posted.

Just did as you said with only the pot connected and my readings are 40-920.
Tried all three pots and the values are the same.

I also tried with A1 and I get 0-1000.
A2 and A3 both give me 0-1023

I only see Fritzing pictures.
Your breadboard could have split power rails.

Remove the pot, and connect A0 directly to ground (not via breadboard).
What reading do you get in the serial monitor.

If it's 0, then your pot/wiring/breadboard is the problem.
If it's not 0, then the Arduino is stuffed.
Leo..

I get 0. This is strange because the pot wires are soldered on to it, they are only 30cm long, and it works fine on A2 and A3.

Then post photographs.

I've attached a photo of the setup with arduino and single pot connected to A0.

Arduino.jpg

Look for a faulty connection under the insulating tape. If that looks good and you still have a problem, try it with a different potentiometer. The connections to it are a little strange, they look like push tab connectors, not intended for pot leads.