[Arduino Nano] Spaceship Thruster Lights

Hi, Everyone!

Here is another Arduino sketch.  This time for Spaceship Thruster Lights.

First, if you need to install an Arduino board and the Arduino Software (IDE), you can check out my previous post for a guide: http://scifimodelaction.com/sfmaforum/index.php?topic=4793.msg64348#msg64348.

This Arduino sketch will have the Nano control three LEDs.  Once the power is turned on, each thruster will randomly start at a low brightness level for 30 seconds.  Each thruster will then gradually become brighter at a random rate of increase for another 30 seconds.  Finally, each thruster will reach a full brightness and stay that way for 3 minutes.

The code allows one to reduce or add to the number of LEDs (depending on the available number of PWM pins on the Arduino being used) and to change the thruster effect times and brightness intensity ranges of each.

This is intended for sci-fi spaceship effects such as for the nozzles of Battlestar Galactica Colonial Viper engines, Star Wars Imperial Star Destroyer engines, and Space Battleship Yamato engines.  However, it can also be used for things such as cockpit interior lights, robot lights, equipment lights, etc..  I posted a demo video on YouTube:


 Now onto programming the attached board...

1. Copy the following code:

/*
  Spaceship Thruster Lights:

    - Produces LED thruster effects:
   
      - Each thruster will randomly start at a low brightness for 30 seconds.
     
      - Each thruster will then gradually become brighter at a random rate of
        increase for another 30 seconds.
       
      - Each thruster will finally reach a full brighness and stay that way
        for 3 minutes.
     
    - The LED update rate is 40Hz which makes the delay 25 milliseconds.

    - Based on original Arduino sketch by 'Jot'
      (https://arduino.stackexchange.com/questions/57354/help-with-simple-gradually-brighter-flickering-led).

  NOTE:

    - This Arduino sketch uses DELAY, so it is not meant to be combined with
      other sketches.
 
*/

#define RATE 40          //update rate of LEDs in Hz
const int ledPin1 = 3;   //output pin must be PWM!
const int ledPin2 = 5;   //output pin must be PWM!
const int ledPin3 = 6;   //output pin must be PWM!

void setup () {
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  Serial.begin(9600);
  randomSeed(analogRead(A0));
}

void loop() {
  int n;

  Serial.println("30 seconds low brightness");
  n = 30*RATE;
  for(int i=0; i<n; i++) {
    analogWrite(ledPin1, random(5,15));
    analogWrite(ledPin2, random(5,15));
    analogWrite(ledPin3, random(5,15));
    delay(1000/RATE);
  }

  Serial.println("30 seconds gradually brighter");
  n = 30*RATE;
  for(int i=0; i<n; i++) {
   
    //   random start: from 5 to 80     (75 increase)
    //   random end  : from 15 to 256   (241 increase)
    //   The calculation is with long, it might not fit in a 16 bit integer

    int random_start = 5 + int((long(i) * 75) / long(n));
    int random_end   = 15 + int((long(i) * 241) / long(n));
    analogWrite(ledPin1, random(random_start,random_end));
    analogWrite(ledPin2, random(random_start,random_end));
    analogWrite(ledPin3, random(random_start,random_end));
    delay(1000/RATE);
  }

  Serial.println("180 second full thrust");
  n = 180*RATE;
  for(int i=0; i<n; i++) {
    analogWrite(ledPin1, random(80,256));
    analogWrite(ledPin2, random(80,256));
    analogWrite(ledPin3, random(80,256));
    delay(1000/RATE);
  }

  analogWrite(ledPin1,0);
  analogWrite(ledPin2,0);
  analogWrite(ledPin3,0);
  delay(2000);
}


2. Replace the existing code in the Arduino software window with the copied code.
3. Save the sketch.  NOTE: for your reference, saved Arduino sketches are located in the C:\Users\<Windows user name>\Documents\Arduino folder.
4. Click the 'Verify' check-mark icon to allow the Arduino software to compile the code and check for issues.   When finished, the software status bar will say 'Done compiling.'
5. Click the 'Upload' right-arrow icon to allow the Arduino software to program the Nano.   When finished, the software status bar will say 'Done uploading.'

And that's it!  Easy!

Here is a pin diagram picture that will show where to make all your connections:


Don't forget to use resistors for your LEDs when doing your setup!  You should be able to use a 9- or 12-volt power supply.  For the purposes of my testing, I used a 5-volt "power bank" external rechargeable battery.

:)

Comments

Popular posts from this blog

Polar Lights / Round 2 1:48 Area 51 UFO

Trumpeter Transformers Blitzwing

Academy Plastic Model Science Ninja Team Gatchaman God Phoenix