Welcome, %1$s. Please login or register.

Login with username, password and session length
 

Author Topic: [How To - Arduino Nano] Spaceship Thruster Lights  (Read 308 times)

Offline Gadgetron_3000

  • Admiral
  • *****
  • Posts: 1261
[How To - Arduino Nano] Spaceship Thruster Lights
« on: February 18, 2019, 10:17:11 pm »
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: https://youtu.be/33NPEKJot4Q.

Check out The Model Stash blog for my original article post: https://themodelstash.blogspot.com/2019/02/arduino-nano-spaceship-thruster-lights.html.

Now onto programming the attached board...

1. Copy the following code:

Quote
/*
  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.

:)
« Last Edit: February 19, 2019, 04:17:07 am by Gadgetron_3000 »
"They've done studies, you know.  60% of the time, it works every time."

-----

The Model Stash Blog: https://themodelstash.blogspot.com/

Google+: https://plus.google.com/109660073537038906328

Offline Dogs Bollocks

  • Ensign
  • *
  • Posts: 12
Re: [How To - Arduino Nano] Spaceship Thruster Lights
« Reply #1 on: February 19, 2019, 03:50:35 am »
Thanks Gadgetron!
This will be really useful!

The pin diagram seems to be missing though. :-(

Offline Gadgetron_3000

  • Admiral
  • *****
  • Posts: 1261
Re: [How To - Arduino Nano] Spaceship Thruster Lights
« Reply #2 on: February 19, 2019, 04:04:45 am »
Thanks Gadgetron!
This will be really useful!

The pin diagram seems to be missing though. :-(

Hmmmm....I'm able to see the pin diagram, testing with both Firefox (Windows and Android) and Chrome (Windows).

If you cannot see it here on the SFMA forum, you can always try viewing my original article post on The Model Stash blog here: https://themodelstash.blogspot.com/2019/02/arduino-nano-spaceship-thruster-lights.html.

Hope that helps.

:)
"They've done studies, you know.  60% of the time, it works every time."

-----

The Model Stash Blog: https://themodelstash.blogspot.com/

Google+: https://plus.google.com/109660073537038906328

Offline Dogs Bollocks

  • Ensign
  • *
  • Posts: 12
Re: [How To - Arduino Nano] Spaceship Thruster Lights
« Reply #3 on: February 19, 2019, 09:10:37 pm »
That is super weird. Chrome on windows here and it

Offline RossW

  • Captain
  • ****
  • Posts: 333
Re: [How To - Arduino Nano] Spaceship Thruster Lights
« Reply #4 on: February 21, 2019, 09:29:45 am »
Very nice!

Offline Dogs Bollocks

  • Ensign
  • *
  • Posts: 12
Re: [How To - Arduino Nano] Spaceship Thruster Lights
« Reply #5 on: February 27, 2019, 12:20:14 am »
Note to self. Do NOT use single quotes in posts. Shoot me....  :o

Offline Markeno

  • Ensign
  • *
  • Posts: 22
Re: [How To - Arduino Nano] Spaceship Thruster Lights
« Reply #6 on: April 12, 2019, 11:13:52 pm »
It is nice to see stuff like this.

I wonder if you have seen the ascii-art-arduinos?  You can include those in the sketch instead of making a graphic, and show a visual representation of the boards and what is wired to them.  They didn't have a Nano version originally so I made my own up based on the Uno, but it seems since then they came out with it.  http://busyducks.com/ascii-art-arduinos  I put the functions off to the left and right as needed.


 




Enterprise © Bloc