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

Login with username, password and session length

Author Topic: Star Ship lighting using the Arduino and ATTiny85  (Read 2312 times)

Offline Caladonis

  • Captain
  • ****
  • Posts: 340
Star Ship lighting using the Arduino and ATTiny85
« on: October 30, 2012, 10:28:44 pm »
A $4 programmable rate multi-pin flasher.

For anyone that may be interested in DIY lighting I thought I would share one way that is very low cost and easy to do. I use an Arduino board for my development environment and the developer is free open source so a kit to get anyone started would include the developer software or IDE running on a PC or other platform and some hardware;
The Arduino starter kit (http://www.amazon.com/Starter-Kit-Newsite-Uno-Breadboard/dp/B0051QHPJM/ref=sr_1_8?s=electronics&ie=UTF8&qid=1351649325&sr=1-8&keywords=breadboard)
LED assortment (http://www.amazon.com/microtivity-Assorted-Resistors-Colors-Pack/dp/B004JO2PVA/ref=sr_1_15?s=electronics&ie=UTF8&qid=1351649325&sr=1-15&keywords=breadboard)
Switches (http://www.amazon.com/microtivity-IM206-6x6x6mm-Tact-Switch/dp/B004RXKWI6/ref=sr_1_16?s=electronics&ie=UTF8&qid=1351649325&sr=1-16&keywords=breadboard)
IC sockets

And eventually a perfboard (http://www.amazon.com/Perforated-Board-4-5-3-1-320-430/dp/B0002ZPUDK/ref=sr_1_10?s=electronics&ie=UTF8&qid=1351649325&sr=1-10&keywords=breadboard) unless you want to start etching your own circuit boards.

Note you can get this stuff everywhere so shop around and be sure to check out Model Man Tom's store.

I have included a very short video (my first one and yes I know it $%^7 - hopefully I'll get better) that depicts the Arduino as ATTiny programmer

The second part shows the Arduino blinking a Red and Green LED at a one second on, and one second off rate and flashing a White LED 50 miliseconds on and 950 milliseconds off. Pretty close to federation standards (I hope)

The last part shows the ATTiny after being programmed with the exact same code used in the Arduino with three tiny exceptions doing the same thing. The exceptions (pin numbers) are due to the different pin numbering between the 8 pin ATTiny85 and the 28 pin Arduino. I like this because unlike timer chips and counters there are NO timing components so less work in hooking it up and it works as designed each time.

A +5 volt source (this can vary, but will affect the resistor values if the voltage is changed. I didn't include its cost as you will likely need power for the rest of your LED's
The ATTiny85 $1.09
The three LED's and resistors a max of @ $.75
Jumper wire and small perf board @ 2.00
Total @ $3.84

The Video clip http://www.youtube.com/watch?v=qf23xtkrgkc)
A much better explanation of what an ATTiny is from Make (http://www.youtube.com/watch?v=30rPt802n1k)

Source Code
Code: [Select]
 *  Blink Multiple LEDs without Delay on/off times individually assigned
const int LEDcount = 3; // Number of LEDS used
byte pin[LEDcount] = {0,1,2}; //Pins assigned to those LEDS
unsigned int oninterval[LEDcount] = {1000, 950,1000}; // On intervial time for leds (max 65535 ms)
unsigned int offinterval[LEDcount] = {1000, 50,1000}; // Off intervial time for leds (max 65535 ms)
unsigned long timeoff[LEDcount] = {0,0,0}; // What time was the LED last tumned OFF
unsigned long timeon[LEDcount] = {0,0,0}; // What time was the LED last tuned ON
int CurrentLedState[LEDcount] = {0,0,0}; // What is the current LED state of each LED in the array

void setup()
  for (int i=0; i<LEDcount; ++i)
    pinMode(pin[i], OUTPUT); //initilize all used LED pins as outputs
    digitalWrite(pin[i], LOW); //Turn LEDs off to start

void loop()
  unsigned long CurrentTime = millis(); // assign current elapsed time to variable "CurrentTime"
  for (int i=0; i<LEDcount; ++i) // loop through all LEDS
    if (CurrentTime - timeoff[i] > offinterval[i] && CurrentLedState[i] == 0)
      digitalWrite(pin[i], HIGH); //Turn LED on
      timeon[i] = CurrentTime;// Set timeon = current time (or relative 0)
      CurrentLedState[i] = 1; //Flag LED state on since we turned it on

    if (CurrentTime - timeon[i] > oninterval[i] && CurrentLedState[i] == 1)
      digitalWrite(pin[i], LOW); //Turn LED off
      timeoff[i] = CurrentTime; // Set on timeoff = current time (or relative 0)
      CurrentLedState[i] = 0; //Flag LED state off since we turned it off
« Last Edit: October 31, 2012, 08:40:24 am by Caladonis »

Offline wolf 359

  • Admiral
  • *****
  • Posts: 1905
Re: Star Ship lighting using the Arduino and ATTiny85
« Reply #1 on: October 31, 2012, 12:03:41 pm »
I do think Arduino rocks and it's something I have to learn for my kits.  I don't think I would ever sell arduino as the prices out there are what they are.  Timer chips are good, basic and open to anyone with some relatively simple diagrams, direction and tools such as are in the Bag of Chips.

Tom,  I have been looking at your bag of chips. From this above, you supply simple diagrams for differant blinking boards in the Bag of Chips? I posted in Jmar's Enterprise A build,I am not a expert, but I want to learn as I go further. I know I can make them cheeper than what I have been paying for a perbuilt one. Any help would be greatly appreciated.


Enterprise © Bloc