DIY led driver

Hmmm

Newly Enlightened
Joined
Apr 26, 2009
Messages
147
/*
Analog input, analog output, serial output

Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.

The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground



*/




const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPinPWM = 0;
const int analogOutPin13 = 13;
const int analogOutPin12 = 12;
const int analogOutPin11 = 11;
const int analogOutPin10 = 10;
const int analogOutPin9 = 9;
const int analogOutPin8 = 8;
const int analogOutPin7 = 7;
const int analogOutPin6 = 6;
const int analogOutPin5 = 5;
const int analogOutPin4 = 4;
const int analogOutPin3 = 3;
const int analogOutPin2 = 2;
const int analogOutPin1 = 1;// Analog output pin that the LED is attached to


int sensorValue = 0; // value read from the pot
int outputValue = 0; // number of 7135 chips "on"
int pwmValue =0; // percent pwm of the 1 7135 that is pwmed, 0 to 255
int pwmRateConverter(int x, int y){
//method to determine pwm value for all cases besides 0; ---------> important ------->this relies on t map() truncating any value from the conversion, instead of roudning


int result;
result = x-map(outputValue, 0, 14, 0, 255);
return result;
}
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
//add method set all low
//method to determine pwm value for all cases besides 0; ---------> important ------->this relies on t map() truncating any value from the conversion, instead of roudning


}


void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 14);

// change the analog out value:
switch (outputValue) {
case 0:
pwmValue = map(sensorValue, 0, 1023, 0, 255)
analogWrite(analogOutPinPWM, pwmValue);
//add method set all pins except pwmValue to low
break;
case 1:
digitalWrite(analogOutPin1, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 2:
digitalWrite(analogOutPin2, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 3:
digitalWrite(analogOutPin3, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 4:
digitalWrite(analogOutPin4, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 5:
digitalWrite(analogOutPin5, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 6:
digitalWrite(analogOutPin6, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 7:
digitalWrite(analogOutPin7, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 8:
digitalWrite(analogOutPin8, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 9:
digitalWrite(analogOutPin9, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 10:
digitalWrite(analogOutPin10, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 11:
digitalWrite(analogOutPin11, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 12:
digitalWrite(analogOutPin12, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;
case 13:
digitalWrite(analogOutPin13, HIGH);
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
break;






// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}
 

Hmmm

Newly Enlightened
Joined
Apr 26, 2009
Messages
147
does this look right? nvm, that is not very good.
 
Last edited:

Hmmm

Newly Enlightened
Joined
Apr 26, 2009
Messages
147
possible head design:
head1xw.png

headjp.png

the solid block in the center is threaded in. the circuit board will be on one side and the leds will be heatsinkedon the other side.

its maglite compatible.
 
Last edited:

Hmmm

Newly Enlightened
Joined
Apr 26, 2009
Messages
147
/*
Analog input, analog output, serial output

Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.

The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground



*/




const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int analogOutPinPWM = 0;




int sensorValue = 0; // value read from the pot
int outputValue = 0; // number of 7135 chips "on"
int pwmValue =0; // percent pwm of the 1 7135 that is pwmed, 0 to 255
int pwmRateConverter(int x, int y){
//method to determine pwm value for all cases besides 0; ---------> important ------->this relies on t map() truncating any value from the conversion, instead of roudning


int result;
result = x-map(outputValue, 0, 14, 0, 255);
return result;
}
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
//add method set all low
//method to determine pwm value for all cases besides 0; ---------> important ------->this relies on t map() truncating any value from the conversion, instead of roudning


}


void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 14);

// change the analog out value:
if (outputValue=0) {

pwmValue = map(sensorValue, 0, 1023, 0, 255)
analogWrite(analogOutPinPWM, pwmValue);
//add method set all pins except pwmValue to low
}
else
{
pwmValue =pwmRateConverter(pwmValue, outputValue);
analogWrite(analogOutPinPWM, pwmValue);
digitalWrite(outputValue, HIGH);
for (c=1, c<=outputValue, c++)
{
digitalWrite(c, HIGH);
}
}



// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}
 

Hmmm

Newly Enlightened
Joined
Apr 26, 2009
Messages
147
any help?

i've tested it alittle and it is very bright, but the throw is pretty horrible.
 

Hmmm

Newly Enlightened
Joined
Apr 26, 2009
Messages
147
I've looked at thoe, but they are rather large and too close to the input voltage. I would need a buck boost driver. To drive it all in series I would need one that could boost to near 70v do those exist? Besides the hyper boost?
 

mpf

Enlightened
Joined
Oct 2, 2005
Messages
228
If you want to DIY your own 5A driver, this post has all the details for attiny controlled series regulator with multiple current levels
https://www.candlepowerforums.com/threads/201383

Build a Basic uC 3 Level Led Driver - A Tutorial

The basic circuit can be used to control milliamps to amps. I have used it for a 5A led driver.

There are also extensions to this project to control it from a mobile phone. OR you can just use the RS232 interface to help you debug the code.

I use a logarithmic scale for the current steps to get a set of levels the look 'linear' to the eye. At the very low levels you need a well damped control or you will get flickering due to current measurement noise.

My website has details on reducing the flicker.
 
Last edited:

Hmmm

Newly Enlightened
Joined
Apr 26, 2009
Messages
147
That looks like it will have the same problem of input voltage being too close to output.

This is my code plan ofr the driver:

/*
Analog input, analog output, serial output

Reads an analog input pin, maps the result to a range from 0 to 255
and uses the result to set the pulsewidth modulation (PWM) of an output pin.
Also prints the results to the serial monitor.

The circuit:
* potentiometer connected to analog pin 0.
Center pin of the potentiometer goes to the analog pin.
side pins of the potentiometer go to +5V and ground
* LED connected from digital pin 9 to ground


*/


const int analogInPin = A5; // Analog input pin that the potentiometer is attached to
const int analogOutPinPwm = 3; // pin 3 is available for pwm
const int digitalOutPin13 = 13;
const int digitalOutPin12 = 12;
const int digitalOutPin11 = 11;
const int digitalOutPin10 = 10;
const int digitalOutPin9 = 9;
const int digitalOutPin8 = 8;
const int digitalOutPin7 = 7;
const int digitalOutPin6 = 6;
const int digitalOutPin5 = 5;
const int digitalOutPin4 = 4;
const int digitalOutPin3 = 0;
const int digitalOutPin2 = 2;
const int digitalOutPin1 = 1;// Analog output pin that the LED is attached to

double pwmPercent=0;
int i;
int sensorValue = 0; // value read from the pot
int outputValue = 0; // number of 7135 chips "on"
int pwmValue =0; // percent pwm of the 1 7135 that is pwmed, 0 to 255

void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);


pinMode(digitalOutPin1, OUTPUT);
pinMode(digitalOutPin2, OUTPUT);
pinMode(digitalOutPin3, OUTPUT);
pinMode(digitalOutPin4, OUTPUT);
pinMode(digitalOutPin5, OUTPUT); '
pinMode(digitalOutPin6, OUTPUT);
pinMode(digitalOutPin7, OUTPUT);
pinMode(digitalOutPin8, OUTPUT);
pinMode(digitalOutPin9, OUTPUT);
pinMode(digitalOutPin10, OUTPUT);
pinMode(digitalOutPin11, OUTPUT);
pinMode(digitalOutPin12, OUTPUT);
pinMode(digitalOutPin13, OUTPUT);
}

void loop() {
// read the analog in value:
sensorValue = analogRead(analogInPin);
// map it to the range of the analog out:
outputValue = map(sensorValue, 0, 1023, 0, 14);
pwmPercent = ((double)map(sensorValue, 0, 1023, 0, 14)-outputValue)*100;

// change the analog out value:

switch (outputValue) {
case 13:
digitalWrite(digitalOutPin13, HIGH);
case 12:
digitalWrite(digitalOutPin12, HIGH);
case 11:
digitalWrite(digitalOutPin11, HIGH);
case 10:
digitalWrite(digitalOutPin10, HIGH);
case 9:
digitalWrite(digitalOutPin9, HIGH);
case 8:
digitalWrite(digitalOutPin8, HIGH);
case 7:
digitalWrite(digitalOutPin7, HIGH);
case 6:
digitalWrite(digitalOutPin6, HIGH);
case 5:
digitalWrite(digitalOutPin5, HIGH);
case 4:
digitalWrite(digitalOutPin4, HIGH);
case 3:
digitalWrite(digitalOutPin0, HIGH);
case 2:
digitalWrite(digitalOutPin2, HIGH);
case 1:
digitalWrite(digitalOutPin1, HIGH);
case 0:
pwmValue = map(pwmPercent, 0, 100, 0, 255);
analogWrite(analogOutPinPwm, pwmValue);
//add method set all pins except pwmValue to low
break;

}

i=outputPin;
while (i<=13)
{
digitalWrite(i, LOW);
i++;
}
// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(2);
}


Could you tell me if this looks like it will work? I think it should.


I'll upload a schematic tomorrow.
 

Hmmm

Newly Enlightened
Joined
Apr 26, 2009
Messages
147
I'm facing 2 problems. I thought the vdd pin of the amc 7135 would switch the led on and off. It isn't if I tie it high or to ground. The other problem is when I connect the led to my cree easwhite led it gives less than 1ma nomatter how i attach the vdd pin.
 
Top