leds glow while pot low

I wrote this code for my wife's birthday. I am trying to light her 6 room dollhouse with potentiometer dimable LED strips for each room. On my breadboard circuit which uses single LEDs for proof of concept, LEDs will randomly glow and sometimes flash when the potentiometers are at zero or if the wires get jostled. Once the pots hit a decent range, the LEDs work as expected. Each LED is connected with a 220ohm resistor and the pinout as below. What am I missing or What more do I need to explain?

/*

  • This sketch and the accompening circuit was
  • designed with love for Mara Cohen Ioannides
  • for her birthday. Her loveing husband has now
  • become part of the tradition that started with
  • a young Mara and her father, Paul, of blessed memory.
  • May this sketch show the love I have for my wife.
  • Ok, it's not halmark... but I wrote this just for you. :wink:
    */

// potentiometer input
const int dnIn = A0;
const int ktIn = A1;
const int lrIn = A2;
const int mbIn = A3;
const int rrIn = A4;
const int sbIn = A5;

// led strip output
const int dnOut = 3;
const int ktOut = 5;
const int lrOut = 6;
const int mbOut = 9;
const int rrOut = 10;
const int sbOut = 11;

// sensors primary data
int sensorValue1 = 0;
int sensorValue2 = 0;
int sensorValue3 = 0;
int sensorValue4 = 0;
int sensorValue5 = 0;
int sensorValue6 = 0;

// leds primary state
int outputValue1 = 0;
int outputValue2 = 0;
int outputValue3 = 0;
int outputValue4 = 0;
int outputValue5 = 0;
int outputValue6 = 0;

void setup() {
//lets see how it looks.
Serial.begin(9600);
}

void loop() {

//read each potentiometer
sensorValue1 = analogRead(dnIn);
sensorValue2 = analogRead(ktIn);
sensorValue3 = analogRead(lrIn);
sensorValue4 = analogRead(mbIn);
sensorValue5 = analogRead(rrIn);
sensorValue6 = analogRead(sbIn);

//convert the potentiormeters
//outputs to values for PWM pins

outputValue1 = map(sensorValue1, 0,1023,0,255);
outputValue2 = map(sensorValue2, 0,1023,0,255);
outputValue3 = map(sensorValue3, 0,1023,0,255);
outputValue4 = map(sensorValue4, 0,1023,0,255);
outputValue5 = map(sensorValue5, 0,1023,0,255);
outputValue6 = map(sensorValue6, 0,1023,0,255);

//light the leds
analogWrite(dnOut, outputValue1);
analogWrite(ktOut, outputValue2);
analogWrite(lrOut, outputValue3);
analogWrite(mbOut, outputValue4);
analogWrite(rrOut, outputValue5);
analogWrite(sbOut, outputValue6);

//check progress for each room
Serial.print("Den light = ");
Serial.println(outputValue1);
Serial.print("Kitchen light = ");
Serial.println(outputValue2);
Serial.print("Living room light = ");
Serial.println(outputValue3);
Serial.print("Master bedroom light = ");
Serial.println(outputValue4);
Serial.print("Bathroom light = ");
Serial.println(outputValue5);
Serial.print("Second bedroom light = ");
Serial.println(outputValue6);

//slow life down a bit
delay(10);
}

Well, actually,

outputValue1 = map(sensorValue1, 0,1023,0,255);

Is more concicely written as

outputValue1 = sensorValue1 >> 2;

But the obvious problem is that the potentiometers do not reliably zero.

So try

outputValue1 = (sensorValue1 - 3) >> 2;

And someone will likely suggest you learn to use arrays to make the code vastly more elegant!

MagistarA:
On my breadboard circuit which uses single LEDs for proof of concept, LEDs will randomly glow and sometimes flash when the potentiometers are at zero or if the wires get jostled.

Bad quality breadboards are common. Build on a strip board (soldered).

Never had pots that didn't go fully to zero, except when wires were soldered to the rivets/holes (don't).

And yes, arrays could reduce this sketch to 1/10 of it's size.
Leo..

Thanks guys! I will get in to arrays at some point, but this was my first self written code. It may be longer than necessary and somewhat inelegant, but I am proud of my work. I also appreciate the explanation of non-zero pots and weak wired boards.

(untested) example of using arrays.
Leo..

const byte ledPin[] = {3, 5, 6, 9, 10, 11}; // pin array
char *roomLight[] = {"Den light = ", "Kitchen light = ", "Living room light = ", "Master bedroom light = ", "Bathroom light = ", "Second bedroom light = "};
int lightValue[6];

void setup() {
  Serial.begin(9600);
  for (int i = 0; i <= 5; i++) pinMode(ledPin[i], OUTPUT); // set all LED pins to output
}

void loop() {
  for (int i = 0; i <= 5; i++) {
    lightValue[i] = analogRead(ledPin[i] >> 2);
    digitalWrite(ledPin[i], lightValue[i]);
    Serial.print(roomLight[i]);
    Serial.println(lightValue[i]);
  }
  Serial.println(""); // blank line
  delay(1000);
}

I did not proceed to mention that you may need some settling time between reading the pots.