Hi,
I hope i'm not going to be too confusing trying to give details to help troubleshooting my problem ...
I need help, any hint appreciated! Thanks in advance.
I'm having a limitation issue with the following project, where if a brightness pot sends more than 4.37v, the circuit doesn't behave as wanted.
parts: sparkfun pro micro, PIR motion sensor, Lumenati 4packs leds device and 2 pots (10k) for brightness and color temperature.
Imported Libraries: FastLED.h and Kelvin2RGB.h
Measurements are made with a cheap RadioShack digital multimeter.
Brightness pot values are mapped as map(0, 2013, 0, 255)
Color temp are set in Kelvin and pot values are mapped as map(0, 1023, 0, 7000)
Using kelvin2Rgb lib to then convert the 0 to 7000 range to 0-255 rgb values for leds.
at 2682 kelvin (pot2), but also at higher or lower color temperatures :
Brightness pot (pot1) set to 4.42v (measured when leds are ON) seems to be the limit.
It goes from 4.42v (ON) to 4.43v (OFF)
Chosen voltage: 441mv
Pot Value:
Mapped value: 75
4.35v to 4.37v seems fine.
Anything under this voltage works fine.
If pot 1 (brightness) delivers more than about 4.50v, Leds will turn back ON after a short blink instead of staying off (time limit for lights on after motion is detected)
If i remove the pots and hard code the brightness, even up to max value (255), it works fine.
What i tested and observed so far:
Light pollution doesn't seem to be a relevant factor (works fine with leds at 255, without pots)
Regardless of the circuit (and code) expected behavior, pots seem to work fine setting brightness and color temperature (leds react well to various settings)
At this point i'm probably missing basic electrical (electronics) knowledge.
Could someone help me to at least stir in the right direction?
What should i check next? Is there an obvious electrical principle i'm not considering?
Do i need a delay somewhere in the code? a resistor or capacitor in the circuit? Is it a Lin/Log issue from pot values? ...
My electronic classes are just vague memories from 30 years ago now ... so please be somewhat indulgent ![]()
Thanks,
Stefan
Attachments (pics) : Dropbox links not working???

Code:
/*
The PIR motion sensor has a three-pin JST connector terminating it. Connect
the wire colors like this:
- Black: D2 - signal output (pulled up internally)
- White: GND
- Red: 5V
LED - In Original example code: Connect an LED to pin 3 (For Sparkfun micro pro).
Whenever the PIR sensor detects movement, it'll write the alarm pin LOW.
Development environment specifics: Arduino 1.6.7
----------------
Kelvin2RGB is from timvw: https://forum.arduino.cc/index.php?topic=377680.0
Github rep: https://github.com/timvw74/Kelvin2RGB
Thanks for sharing, timvw!
*/
#include <Kelvin2RGB.h>
// PIR
const int MOTION_PIN = 2; // Pin connected to motion detector
const int LED_PIN = 3; // LED pin - active-high
// FastLED library
#include "FastLED.h"
// Number of LEDs
#define NUM_LEDS 4
// Define our clock and data lines for Luminati 4pack
// For led chipsets like the LPD8806 define both DATA_PIN and CLOCK_PIN
#define DATA_PIN 5
#define CLOCK_PIN 6
// Create the LEDs array
CRGB leds[NUM_LEDS];
// Non blocking delay
unsigned long delayStart = 0; // the time the delay started.
bool delayRunning = false; // false means Not running. True if still waiting for delay to finish.
// potentiometers
int pot1Pin = A0; // select the input pin for the potentiometer 1 (brightness)
int pot1Value = 100; // variable to store the value coming from the sensor
int pot2Pin = A1; // select the input pin for the potentiometer 1 (color temp)
int pot2Value = 100;
void setup()
{
Serial.begin(9600);
// PIR
// The PIR sensor's output signal is an open-collector, so a pull-up resistor is required:
pinMode(MOTION_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
// LEDS
// Tell FastLED what we're using. Note "BGR" where you might normally find "RGB".
// This is just to rearrange the order to make all the colors work right.
FastLED.addLeds<APA102, DATA_PIN, CLOCK_PIN, BGR>(leds, NUM_LEDS);
// Set global brightness
FastLED.setBrightness(pot1Value);
// Start with LEDs turned Off
leds[0] = CRGB::Black;
leds[1] = CRGB::Black;
leds[2] = CRGB::Black;
leds[3] = CRGB::Black;
FastLED.show();
}
byte kRed;
byte kGreen;
byte kBlue;
int prevPot1Val;
int prevPot2Val;
void loop() {
// USER VARIABLE: Duration
int light_duration = 3000; // Set how long the light will stay ON
// read the value from the potentiometers:
pot1Value = analogRead(pot1Pin);
// !!! Only mapped to 85 because of the blinking back on problem
pot1Value = map(pot1Value, 0, 1023, 0, 85);
pot2Value = analogRead(pot2Pin);
pot2Value = map(pot2Value, 0, 1023, 0, 7000);
if (abs(pot1Value - prevPot1Val) >10) {
prevPot1Val = pot1Value;
Serial.print("Brightness: ");
Serial.println(pot1Value);
delay(10);
}
if (abs(pot2Value - prevPot2Val) >100) {
prevPot2Val = pot2Value;
Serial.print("Color Temp: ");
Serial.println(pot2Value);
delay(10);
}
// Now use kelvin2rgb to pass the brightness and color temp
Kelvin2RGB kel(pot2Value, pot1Value);
kRed = kel.Red;
kGreen = kel.Green;
kBlue = kel.Blue;
FastLED.setBrightness(pot1Value);
// PIR
digitalWrite(LED_PIN, LOW);
int movement = digitalRead(MOTION_PIN);
// If Movement Detected ...
if (movement == LOW) // If the sensor's output goes low, motion is detected
{
// Start Non-blocking delay
delayStart = millis(); // start delay
delayRunning = true; // Running timing, not finished yet
// Turn LEDs On using kelvin2rgb output values
digitalWrite(LED_PIN, HIGH);
leds[0].setRGB( kRed, kGreen, kBlue);
leds[1].setRGB( kRed, kGreen, kBlue);
leds[2].setRGB( kRed, kGreen, kBlue);
leds[3].setRGB( kRed, kGreen, kBlue);
FastLED.show();
}
else {
// check if Non-blocking delay has timed out
if (delayRunning && ((millis() - delayStart) >= light_duration))
{
// prevent this code being run more then once.
delayRunning = false;
// Turn LEDs OFF
leds[0] = CRGB::Black;
leds[1] = CRGB::Black;
leds[2] = CRGB::Black;
leds[3] = CRGB::Black;
FastLED.show();
//delay(200);
}
}
}
/*
>>> TODO or FIX <<<
1) Something is not working correctly:
When the brightness is more than about 90,
the light keeps on switching back on after it's given duration (blinks off/on)
Is this depending on current/voltage drawn by the LED???
2) the Color Temp doesn't updates 'real time' when turning the pot is motion isn't detected.
3) look at linear vs log for Pots to LEDs
*/
PIR_fastLed_kelvin2Rgb_01d.ino (4.39 KB)

