Ok, so I just got a Duemilanove board and have been playing with it for a few days. I wrote a fairly simple program to create an intelligent power supply from the arduino that can power any small DC device without additional components (resistors).
The idea behind this is simple: when you have a capacitor and a resistor in parallel, and hit it with a pulse of HV electricity, the empty capacitor will cause a voltage drop, and it generally has to fill up before the resistor (or LED in this case) suffers the consequences of overvoltage. (Convert high voltage to low voltage if timed correctly)
These were the requirements:
I want to run some LEDs and I don't want to use resistors.
I want to plug/unplug as many in as I want at any time while making no adjustments - also no resistors added - optionally can add motors or other devices
I want to control the voltage with the push of a button.
For testing and maybe even usage I also want the measured voltage printed to the LCD screen.
Ok. That being said here is my code:
#include <LiquidCrystal.h>
//Make sure to verify pins before hooking up
LiquidCrystal lcd(12, 11, 7,6,5,4);
#define bDuration 25
int OutPin = 8;
int DetPin = 4;
int Vread = 0;
//322 is good for VMAX (voltage = 322 * .0098) about 3.156 Volts for my LEDS
int VMax = 321;
int OutState = 0;
unsigned long time = 0;
unsigned long currTime = 0;
float detV = 0;
volatile int VMaxvar = VMax;
volatile unsigned long bounceTime=0;
void setup(){
attachInterrupt(0,Increase, RISING);
attachInterrupt(1,Decrease, RISING);
pinMode(DetPin,INPUT);
pinMode(OutPin, OUTPUT);
lcd.begin(16,2);
}
void loop(){
time=millis();
if(time - currTime > 1500){
currTime = time;
digitalWrite(OutPin, LOW);
OutState = 0;
detV = Vread * 2 * .004887586;
lcd.setCursor(3,0);
lcd.print(detV);
//lcd.print(" Volts");
}
Vread = analogRead(DetPin);
if(Vread < VMaxvar && OutState == 0){
digitalWrite(OutPin, HIGH);
OutState = 1;
}
else if(Vread > VMaxvar && OutState == 1){
digitalWrite(OutPin, LOW);
OutState = 0;
}
}
void Increase(){
if(millis() > bounceTime && VMaxvar < VMax){
VMaxvar = VMaxvar + 3;
bounceTime = millis() + bDuration;
}
}
void Decrease(){
if(millis() > bounceTime && VMaxvar){
VMaxvar = VMaxvar - 3;
bounceTime = millis() + bDuration;
}
}
The power circuit is:
-
1 small & 1 bigger transistor in darlington configuration (npn)
-
Transistors Fed by Pin 8 via 10K resistor - collectors of both hooked directly to 9V battery
-
Analog Pin 4 reads off a voltage divider ( 2 10K resistors ) connected between emitter and ground
-
A 1000uF cap. is connected between emitter and ground to buffer the pulses
-
LEDs/Motors etc connect between emitter and ground
I have tested this for a while using 9V batteries and ~3V leds and it seems to work great. It will work with a single transistor, but the darlington pair allows more current and zero voltage drop with 10-15 LEDs for example. The voltage appears to hold at 3.14 to 3.16V regardless of whether I have 0-10 LEDs or a small motor hooked up.
One of the main things I'm wondering is if this is used in any mainstream electronics or industrial applications, because I haven't been able to find any examples of it? If so, how and where, etc? If not, why not? I wouldn't say its just PWM, but PWM is kind of a part of it.
My assumption is that efficiency would be fairly high, considering zero power dissipation by resistors, and digital control of the transistor(s).
Also, one of the issues I have is the speed of the LCD printing. If I print both the voltage number and the word "Volts" it creates a noticeable 'glitch' in the output of the LEDs. The work-around I found so far was to simply turn off the Output before printing to LCD, and let it recover on its own. Why is the LCD printing so slow and could it be done in a faster way? How about the timing of it, is there a better way to delay the printing to every 1 or 1.5 seconds than what I currently use?
Also, since I can run up to small bank bank of 3V LEDs, connected almost directly to a 9V source (no resistors), how about scaling this up to say 24 or even 120 Volts input? Is that feasible? I assume the arduino would not be fast enough for 120V...