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.
*/
// 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);
}