Welcome, %1$s. Please login or register. - Did you miss your activation email?

Login with username, password and session length
 

Author Topic: Need help with arduino sketch (flickering engine lights)  (Read 2861 times)

Offline Grumpy Popeye

  • Commander
  • ***
  • Posts: 177
Re: Need help with arduino sketch (flickering engine lights)
« Reply #15 on: February 28, 2017, 08:55:46 pm »
So I plugged in a transistor into my cct and the results were less than stellar. Even while being fed by 12V the LEDs were way dimmer than those being driven off the Arduino. While I can't account for the dimness, I think the transistor is only switching on once its voltage threshold is reached, so we're not getting the full effect of the PWM signal.

Here's a fun bit of video, Arduino feed at the top, 12V transistor on the bottom;

http://vid111.photobucket.com/albums/n154/Darph_Bobo_photos/8A34EDC4-86E2-48B8-B21A-3DC39CD3532F_zpsxcx9epvo.mp4

Offline AussieTrekkie

  • Admiral
  • *****
  • Posts: 696
Re: Need help with arduino sketch (flickering engine lights)
« Reply #16 on: February 28, 2017, 09:35:15 pm »
Probably a little late. When I did a course in electronics 15 years ago my understanding of the transistor, the base leg is what turns the transistor on and off. The base leg only needs a very small amount of current to turn on the transistor. In saying this a transistor cannot be used in a circuit that the Arduino will be used for flickering the lights, you need to connect the led directly to the PWM output on the Arduino to get the effect. In my Refit build using multiple Arduinos to control my lighting system I am using the before mentioned transistors 2N222A to turn on multiple leds on a circuit from one output on the Arduino. I have the base leg connected to the Arduino and the Collector and Emitter legs are connected to the led and the main power supply. So the Arduino is turning on the transistor but the transistor is turning on the led using the 9/12 volt power.

Don't know if this helps you in anyway.
Scott.

Offline madmonk

  • Captain
  • ****
  • Posts: 269
Re: Need help with arduino sketch (flickering engine lights)
« Reply #17 on: March 01, 2017, 02:51:41 am »
I regularly run 2 LEDs of one output and usually attach the resistor to one leg of the LED then take 2 wires back to the output, the Arduino outputs run at 5V so I use a 180Ohm resistor in line with each LED, basically running the LEDs in parallel.

Offline texastony1946

  • Lieutenant
  • **
  • Posts: 30
Re: Need help with arduino sketch (flickering engine lights)
« Reply #18 on: August 15, 2017, 08:15:14 am »
I'm trying with no success to ramp and flicker an LED at the same time. The code gets tangled up in timing between the 2 functions. I think I can do this with 2
JFET in seires (one to flicker ,one to ramp). Any ideas would be appreciated.

Offline scottminium

  • Admiral
  • *****
  • Posts: 1136
  • There are submarines, and targets.
Re: Need help with arduino sketch (flickering engine lights)
« Reply #19 on: May 09, 2018, 04:20:06 pm »
In case anyone is looking for ideas, for my Y-Wing I flicker the engines and ramp them.  They ramp up or down, then hold, then randomly move on to a new value.  They ramp at 1 setting/ms, so the effect is quick, but not instantaneous.
sketch:
const int EngPin =9;     
const int DummyPin = 8;   // unused pin for initial random value
int NewEngPower=200;            //initial value for the next brightness
int EngPower=150;            //Brightness setting
int EngOnTime=100;          //how many ms to hold the current EngPower value

unsigned long seed=0;
int count=32;

void setup() {
  pinMode(EngPin, OUTPUT);       
  pinMode(CockpitPin, OUTPUT);     
  pinMode(DummyPin, INPUT);
  randomSeed(analogRead(DummyPin));
  analogWrite(CockpitPin, 180);
  }

void loop(){
  //ENGINES
       // Engines will randomize output for random times,
       // ramp up or down to new value then
       // stay at a particular brightness for 50-500ms after ramp up/down
   analogWrite(EngPin, EngPower); 
   if (NewEngPower>EngPower) {EngPower++; } 
      else if (NewEngPower<EngPower) {EngPower--;}
            else {EngOnTime--;}  //if NewEngPower==EngPower, then hold at that power
   if (EngOnTime<=0) {   //respawn the seed generator, maybe useless
                       count=32;
                       while (--count)
                          seed = (seed<<1)|(analogRead(DummyPin)&1);
                       randomSeed(seed);
                       NewEngPower=random(150,255);  //minimum acceptable value and max for brightness
                       EngOnTime=random(80);     //adjust to to get desired flicker rate
                     }
 
       
  delay(1);  //this is the overall control loop, so engine functions are checked/adjusted each millisecond

}
"I rather believe that time is a companion who goes with us on the journey, and reminds us to cherish every moment... because they'll never come again."

Offline texastony1946

  • Lieutenant
  • **
  • Posts: 30
Re: Need help with arduino sketch (flickering engine lights)
« Reply #20 on: May 10, 2018, 05:24:58 am »
Scott I was able to ramp and flicker at the same time in my gundam code. Not the most eloquent solution, but worked for my needs. It ramps and flickers , then holds at max output.

 




Enterprise © Bloc