Hi. I'm pretty sure this is a hardware issue and I haven't been able to solve it. Many thnks.
I am trying to control 8 leds in series (5v) through a hardware switch to illuminate a light box. Power supply is a 5 volt, 1.5 amp 7805 replacement switchmode regulator mounted on a shield powered by the 12v Vin.
It works like this.
Hardware switch ON - leds ON - camera takes a defined number of shots - leds OFF - next sequence.
The camera part and other code is working well.
I have tested the LED switching code using a single led (pin 12 and GND) to test the sequence - led ON, camera shoots 1, 2, 3, ... as defined, led OFF. The code jumps to the next sequence no problems.
However, when I switch all 8 leds ON through a power transistor my code doesn't sequence... zero nothing at all and the LEDs remain on endlessly, until the hardware switch is off.
The problem seems to be associated with switching through the power transistor. It is wired correctly, because it can be switched ON and OFF by the hardware switch, setting pin12 HIGH then LOW.
(The base is connected to the microcontrollers output. The high-current load (i.e. the leds) is attached to its power source, and then to the collector of the transistor. The emitter of the transistor is connected to ground).
Reference
http://itp.nyu.edu/physcomp/Tutorials/HighCurrentLoads
I have posted the relevant code as minimally as possible to avoid distraction. Note: the camera sequence works well and is a bit irrelevant to the LED power switching IMHO.
#define pin2 2 // hardware switch - 3 positions - different sequences
#define pin3 3 // hardware switch
#define pin12 12 // power transistor - base
void pause() {
digitalWrite(pin12, LOW);
}
void setup() {
pinmode(pin2, INPUT);
pinmode(pin3, INPUT);
pinmode(pin12, OUTPUT);
}
void loop() {
if (pin2 == LOW && pin3 == LOW) {
digitalWrite(pin12, HIGH); // LEDS light up - power transistor BASE
// camera shoot - when finished
digitalWrite(pin12, LOW); // leds should turn off here - but they don't
// next camera sequence - then all stop - no problems here
// hardware switch - pause everything
if (pin2 == HIGH && pin3 == LOW) {
pause();
}
}