Introduction: Digital LED Flower

The digital LED flower uses two water bottle caps for a disk, with 8 pedals made out of LEDs, the pedals are glass vials with LEDs wrapped in wire mesh, and a button located in the center of the flower’s disk, which changes the LED sequences. An Arduino Mini that is hidden within the small confines of the flower’s disk controls the sequences; a 9V battery powers the entire unit.



I wanted to write an Instructable that would be beneficial to those who want to learn how to use a micro-controller and provide some basic electronics for the beginner. Please remember, I claim no expertise.



This Instructable was written to help those who are just getting into building and working with electronics and micro-controllers. Being self-taught, I cannot claim any more expertise than the devices I build that work as designed. For those who know the information already, you can skip ahead, glean the code, design and make something cool. If you know a better way to skin this cat, you can post suggestions.



When I first started writing this Instructable, I had plans on commenting and explaining the process of coding and basic electronics for the beginner. I wanted to help anyone who is interested in tinkering with electronics and micro-controllers to get more comprehensive instructions including extensive code comments . If time permits I will post the entire instructions in a file called Flower_V1_0.pdf.



There is a video of the flower during programming and testing taken using a Nikon Coolpix, the problem I am having is that the video is too big. Once I get it smaller, I will post it here.  I finished this project in time to use it on Halloween, but I did not get any video of it that night, and the crowds downtown were merciless; so I need to repair two LEDs and I will post a video after the fix.

Step 1: Components, Tools, and Tips

COMPONENTS

1      Arduino Mini

1     10K-ohm resistor 1/4 watt (used as a pull-down resistor)

1     150-ohm resistor 1/4 watt

8     glass vials

8     LEDs - 2 red, 2 blue, 2 green, 2 yellow

2    plastic bottle caps from 1 gallon Crystal Geyser water bottles

1     round circuit board (Radio Shack)

1     spool red 32 AWG Teflon hookup wire

1     spool blue 32 AWG Teflon hookup wire

1     Spool red 24 AWG strand wire

1     Spool blue 24 AWG strand wire

1     mini push button

1     9V battery clip with leads

10    jumper pins (taken from old computer motherboard)

2     yellow LEDs (for the flower disk)

1     Sheet fine copper mesh

2     Rare Earth magnet


TOOLS

    Soldering iron

    Small wire cutting pliers

    Wire strippers (optional, but worth having)

    Helping hands (not an option if you are serious)

    Heat gun

    Shrink tubing, two of the smallest sizes available 3/32"

    Hot glue gun and glue

    LED (use when programming the mini

    Arduino Diecimila or NG board, or Mini USB adapter

    USB cable

    Computer

     Arduino compiler software - free download from Arduino site

    Drill

    Multi-hole drill bit (multi-hole is best but they cost)

     breadboard (if you do not own one, get one)

    Jumper wires with alligator clips on each end

    Magnifying glass on stand or magnifying glasses (Optional)

    Needle nose pliers


NOTES ON PARTS, TOOLS & TECHNIQUES


The Teflon hookup wire is expensive, sorry, but is necessary for the small confines of the flower’s disk. Maybe there is less expensive wire of that gauge, but I could not find it locally.



Having helping hands is mandatory if you are serious about tinkering. With a hot soldering iron in one hand and the solder in the other, holding the work with your mouth is not recommended. The helping hands are so invaluable to me I named mine Igor.



To make Igor better, I added some heat shrink tubing to the teeth of the alligator clips. This provides a good grip on wires and keeps them from marring circuit boards and other delicate parts; it provides electrical isolation as well. Igor is a very good lab assistant but can be very ornery at times. 



After building many sub-standard electronic projects, it was apparent early on that electrical tape prevented quality in the work; a good heat gun and shrink tubing are necessary if you plan on creating quality work that fails less.



A medium size bread board is also irreplaceable, the larger the better, you would be surprised at how easy it is to use up space on even a modest sized proto-board. Currently I have three I use continually; correction, two, one of the three has a project stuck in prototype without time to finish, so it sits populated with future today. 



Jumper wires with alligator clips, for faster prototyping and testing beats trying to hold unsoldered wires together with my three hands.



A good soldering iron is important for the serious tinker, though I do not want to sell any specific product, I have to go with what I know, which is, I really love my Weller WES50.



Magnifying glass or glasses, and for the eagle eye, wouldn’t it be great to be an eagle with binoculars? It really helps increase the quality of your work.



Tinning the iron is accomplished by wiping around the iron tip of the iron on a wet sponge cleaning off any residual solder, then applying a small amount of solder to the iron and cleaning it once more on the sponge, leaving a silver coated tip, no lumps of solder. Tinning is also done to the end of wire strand in order to hold the twisted ends together and make then stiff.



Drink water.

Step 2: Micro-Controller

MICRO-CONTROLLER

I chose the Arduino Mini for this project because of its size and also how much fun I had with other Arduino boards.The Arduino Mini is a complete circuit board with an ATmega168 micro controller, a 16 MHz clock, a power regulator, memory, and a series of input and output pins; some digital and some analog.



The Mini can be used to operate other electrical components from lights to motors or transistors for driving solenoids, speakers and a host of other electrical devices.
It can also be used to read data, such as sensor states, buttons, or other electrical input devices like thermometers, SCRs or even your own device creations; one who thinks outside the box, defines the box.



The Arduino Mini can run using a DC power source from 7 to 9V; the on-board power regulator adjusts the voltage to 5V for the micro-controllers I/O pins and power pins.



The I/O pins on the Arduino can be set to either INPUT mode or an OUTPUT mode. The input mode is used for reading input data from sensors, buttons or other devices, or INPUT mode can be used to set the pin to a high-impedance, which has a similar effect as an open circuit. Note this can also be used to turn LEDs on or off, but we will handle that operation differently.



You can even send PWM (Pulse Width Modulation) to the pins for controlling stepper motors, solenoids, audio synthesis, power reduction, telecommunications or any other devices that might function with PWM like controlling the brightness of an LED. PWM is a series of on off pulses, which vary in length; I call them hillbilly teeth.



The digital and analog pins can be set to LOW or HIGH, which is the same as attaching V- or V+ respectively to the pin. The analog pins can have their values set in a range between 0V and 5V with a resolution of 1024 for analogRead() and 0 to 255 for analogWrite().



You can use this to ramp the brightness of an LED. For example, analogRead() can be used for a potentiometer as an adjustment knob. There are many other uses for controlling the values of analog pins but they are not pertinent to this project.



By attaching LEDs to the same ground pin, and setting this pin to OUTPUT and LOW, we can turn any of the LEDs on or off by setting their individual positive pin to HIGH or LOW respectively; this will also make programming simpler.



The programming language used by the free compiler software is based on the C/C++ programming language; anyone with even the slightest interest can learn to program this micro controller with ease. If you have ever programmed in another language it is simple to learn the basic construct and formatting of this language.



The electronics of this flower are simple, the difficulty is in the size of the project, but this is also the beauty of the piece, it fits nicely on the blouse of my spouse. Gather all the components and your thoughts into one place and let the fun begin.

Step 3: LED Pedal Construction

START BUILDING

The Mini has to be programmed before it can be installed on the circuit board, there will be no way to program it once it is installed in its flower disk. The LEDs need to be made first so that programming, design for the sequences, and testing can be complete before assembly.



First we need to create the diffusion and housing for our LEDs, prepare the leads, using the wire mesh method is perfect. For the housing and mounting of the LEDs, I used small glass vials picked up from a local industrial liquidator; they were perfect for this project. The wire mesh a molding material that can be found at most craft stores.


LED BUILD

Parts needed for this section:

8 LEDs 2 each of red, blue, green, yellow, or any colors you wish

8 glass vials

1 sheet copper mesh 8” x 2”

16 x 1.5” 24 AWG strand wire 8 red, 8 black

16 x 3” 3/32 Teflon wire 8 red, 8 blue

Tools needed this section:

Soldering Iron and solder

Helping hands (Igor)

Wire cutters and wire strippers

Heat gun and shrink tubes

3V battery with leads

Hot glue gun and glue sticks


Prepare the leads of the LEDs by soldering 24 AWG wire so that only 1/4" would protrude from the end of the vial. Using this gauge wire is necessary in order to provide enough strength so the LED can be pushed into the vial along with the wire mesh; it is an interference fit.



Before you solder, be sure to think about the heat shrink tubing, if you do not do this now, it will not be long before you will be un-soldering your work to apply the tubing, which kills the Zen quality of the project.



You could get away with adding heat shrink to only one lead, since the solder joints will be inside the glass vial and the vial, but since the glass is transparent and the installation will be visible when the unit is off, I wanted the installation to look clean.
I used color-coded heat shrink for effect and to identify the color of the LED after it is installed within the mesh; tin the iron.



Use the 3V battery with leads to test the LED, attach (+) to the long lead, and (–) to the short, it should light, if it does not, switch leads and repeat test. If the LED still does not light discard after you check the leads and repeat; sometimes the leads break when removing from the light string, with your teeth.



An LED cannot be damaged by a reversing the battery leads (reverse bias); LEDs are diodes, which act like check valves and will resist current in the opposite direction.



Solder the 1.5” 24 AWG to each of the LED’s leads, red to the ANODE (positive) and black to the CATHODE (negative) apply heat shrink tubing and check LED’s functionality again, if you do not check it here, you will have to melt the glue at the end of the vial and hope that you can get a new LED back into the mesh since the mesh did not come out with the bad LED.



Solder 3" Teflon wire to the end of the 24 AWG wire; red to the ANODE (positive) and blue to CATHODE (negative). Even with the use of this small wire, it is still a bit crowded. I could make the leads shorter, but with two hands full of thumbs, length is a premium.



Always have a 3V battery with leads available for testing each of the LEDs after the wires are attached, or you could own an adjustable power supply. Plug in your glue gun now.



The red LEDs have a forward voltage of 1.9V which means that they will light when there is 1.9V across its leads. The blue and green require 3V of forward voltage to light. The red LEDs sink 20mA of current, when using a 3 volts battery the current is low enough that it will not burn out the LED if you do not use a resistor with a 3V battery.



If an LED burns out using a 3V battery during the test, you did not need that one anyway. You can tie a 150-ohm resistor in line with either the positive or negative lead but I doubt you will need this. For tutorial purpose we can determine the resistor  to keep the current through the LED at .020A for 3Vt battery: resistor = 3V / 0.020A = 150 ohms.



All of the LEDs ground leads will be tied together, the code will have only two LEDs on at the most at any one time.
Most LEDs are rated at a max current of .020A or 20mA. Using Ohm’s law we can determine how much resistance we need to place inline with the LED in order to keep the current at 20mA, the max current is the rating, but we can push this, or at least I do.



V = IR, R = V/I, I = V/R. We know our HIGH on each pin is 5V and the current requirement for the LED is 20mA so R = 5V/.020A = 250 ohms. This is how much resistance we need to keep the current around 20mA. You must keep in mind that we also have a maximum current limit on the I/O pins of the Arduino Mini of .040mA.



Now comes the tinker push, I use a 3V battery without a resistor to test my LEDs before adding them to a project and they burn bright but not out. Using Ohm’s law R = 3V/.020A = 150 ohms. If we calculate the current using a 150-ohm resistor and 5V we see that I = V/R = 5V/150 = .033A or 33mA.
Some LEDs are rated at 30mA specifically the green and blue LEDs, so this value is within my tinker range. 



Once the LEDs are prepared cut the mesh sheet the length of the vial. The vials I used have a flute so I made the mesh length equal to the vial’s depth not including the flute. For the width of the mesh I used the flute’s diameter. Make the mesh long enough to wrap around the flute forming a tube, cut to fit the diameter and remove the mesh from the flute, then gently roll it with your fingers into a smaller diameter, small enough to fit in the end of the flute.



Press the tube into the flute about half way, press an LED into the end of the mesh tube and proceed to press the whole installation into the vial, if the mesh jams, remove and turn around placing the other end in first, some slight rolling may be required to get the ends to fit.



The goal is to have the mesh touching the end of the vial with the LED at the other end, not in the middle of the mesh. When you have the mesh touching the end of the vial, squeeze a bead of hot glue in the end of the flute so that it covers the protruding wires, this will keep them tight and secure.


Drink water.


Step 4: Test LEDs and Program Mini



Once all the LEDs have been prepared, it is time to program the Arduino Mini. With only eight LEDs and one button, there are plenty of pins on the Mini for this job. All the LEDs will share a common ground and will be controlled by setting their positive lead to a HIGH for on and LOW for off. The ground pin, using pin (2), for all the LEDs will be set to OUTPUT and LOW at start-up. I could have used one of the Mini’s ground pins but wanted control over the LED’s ground, weird, I know.


Parts needed in this section:

8 prepared LEDs

            1 1.75" round PCB (Ra     hack)

1 Arduino Mini

1 LED (green)

1 push button (mini)

1 10K resistor

1 150-ohm resistor

1 black 24 AWG wire or green

1 red 24 AWG wire

            1 red Teflon wire

            1 blue Teflon wire


Tools needed this section:

9 jumper cables

9 4” wire

1 USB cable

1 breadboard

            1 soldering iron and solder

1 computer with Arduino compiler installed



Since the LEDs in this project are sharing the same ground connection; we limit the need for more (in quantity) current limiting resistors in order to save space. I will not have all the LEDs on at once, so this should not cause a problem with sinking too much current through that ground pin. Remember that the Arduino Mini' has a max sink of 40mA (.040A) of current per pin.



The Arduino Mini is a circuit board with micro controller, power regulator, memory, clock and IO pins, but due to its compact size it lacks the RS232 chip for serial IO. Its size is great for fitting it into small spaces, which is great for robotics and other applications where space is valuable and rare.



The serial chip needed for programming the micro controller or sending data back and forth to the computer. Arduino makes a serial board that has the RS232 chip and USB port for programming the Mini and it is compact as the Mini. At the time of the writing of this article the Mini Serial adapter cost only $20.



I was short on time so I had to use an alternate method using an Arduino Diecimila board to program the Mini. Note: The website example uses an Arduino NG, which is almost identical to the Diecimila, and the fact I had a couple Diecimila boards already.



Programming the Mini using the Diecimila or NG is simple, it requires the removal of the micro controller chip from the board and tying the Rx, Tx pins to the respective Rx, Tx pins on the Mini. To power the Mini, simply jump the power leads from the Diecimila. This is accomplished using the breadboard.



The Diecimila has two LEDs for the Rx, TX activity and one LED tied to pin 13. The Mini does not any LEDs so we can attach an LED from pin 13 (ANODE) to ground (CATHODE). Pin 13 has a limiting resistor attached to it so we do not have to worry about using a resistor with an LED attached to this pin.



You can also tie into the reset button on the Diecimila or NG by tying the reset pin on the Mini to pin 1 on the Diecimila, this allows you to use the reset button on the host board.
Arduino has photos showing the connections needed for using the larger board for a serial port, power, and reset button at this link http://arduino.cc/en/Guide/ArduinoMini



Now make all connections of LEDs to the micro-controller. Each LED’s positive lead is tied to the Mini’s pins from pin 3 to pin 10; attach all the grounds of the LEDs to pin 2 through the 150-ohm resistor. Remember, the I/O pins on the Mini are from 0 to 15, so pin 2 is really the third pin on the Mini.



Leaving pins 0 and 1 open so that we can communicate via the COM port, we start the LED pins on pin 2 and end at pin 10. We will be using pin 11 for receiving the button INPUT to change the sequences.



To test the LEDs, I used 9 x 3” lengths of wire, 8 red, 1 black: always use color-coded wire, it is easier when they are all tangled together to identify positive from ground etc. . Solid core wire is good for breadboard hookups over strand wire.



If using strand wire it should be tinned, first tin the iron by adding a small amount of solder to the tip, then clean your solder iron off with the wet sponge, touch the iron to the wire and touch with the solder while stroking along the wire length. If you have done it correctly the wire should be shinny with solder without large clumps or bubbles; this will make the strand end stiff enough to push into the breadboard.



Use the diagram of the pins that can be found on the Arduino site; be sure to note the version number of the micro-controller you are using, the pins are different between the 03 and 04 versions. http://arduino.cc/en/Main/ArduinoBoardMini



I placed a red wire in the breadboard for each of the pins 3-10 and a black wire on pin 2 for ground. Then using the jumper cables with alligator clips, I tied all the ground wires on the LEDs to pin 2 through a 150-ohm resistor (this will be the ground pin for the LEDs) this is accomplished by making a "Y" harness 8 into 1 with the 150-ohm at the combined end, heat shrink around the resistor; next connect the red leads to each individual LED.



We need to hook a button up so that we can write multiple sequences and allow the user to change them. To do this the button is attached to a pin so we can read a button push. When the button is pushed, +5V (V++) will be sensed at the pin. When we read it we can take action if it is HIGH, or no action if LOW.



We cannot leave the pin floating with nothing attached, because doing so will leave the pin susceptible to unknown values, even getting close to the micro-controller can modify the value if the pin is not tied either V++, ground, or a load, so we will use what is called a pull-down resistor.



This resistor will tie the INPUT pin to ground while resisting the flow of current through the INPUT pin, when the button is pushed the pin will then be tied to V++ and read as HIGH.



Now that we have the button and LEDs tied to the controller it is time to power the board. Set the jumper next to the USB cable port on the Diecimila or NG to jump the two pins closest to the USB port, this causes the board to take power from the USB connection. Connect the Diecimila or NG board to the computer with a USB cable.


Step 5: Testing Board Connections

There are many different ways of writing code that accomplishes the same task, through different means. Two things that I focus on are the program’s functionality and some sort of control over obfuscation; I like to avoid making the code too obscure to read. If I do not, in the future I will wonder who the hack was that wrote this code? Some may be wondering that now.


If you want to test your connections and the ability to upload and run code on the Mini, copy the following code, upload, and the program should blink the LED tied to pin 13.

/* Test program, Blinking LED */

int LEDpin = 13;
int t_delay = 1000;

/* The setup() function is used for initializing data */

void setup(){

pinMode(LEDpin, OUTPUT);
digitalWrite(LEDpin, LOW);
}


/* This is the main loop function that will continually loop
after the initialization and setup() function are complete
and while the
micro-controller is powered. */

void loop(){

digitalWrite(LEDpin, HIGH);
delay(t_delay);
digitalWrite(LEDpin, LOW);
delay(t_delay);
}

Step 6: First Sequence

You should have all the LEDs that you built hooked up to the Mini’s I/O/ pins from pin 3 to pin 10, with the grounds tied to pin 2.


Run the Arduino programming environment, copy the following code and paste into the window. Click on the save button and save the file in a location that named for this project.

Please note that I removed the comments in this code so that it will copy and paste cleanly. If you want to see full commenting on the code, it will be in the file
Flower_V1_0.pdf. at the end of this Instructable.

int posPins[] = {3,4,5,6,7,8,9,10};     
int negPin = 2;                                         

int i;                                          
int t_delay = 100;                     


/* setup() Initialization function, the word “void” before the function name means that the function does not return a value. */


void setup(){

                  Serial.begin(9600);                                                
                  pinMode(negPin, OUTPUT);      
                  digitalWrite(negPin, LOW);       

            for (i = 0; i < 8; i++){                        

                   pinMode(posPins[i], OUTPUT);                                   
                   digitalWrite(posPins[i], LOW);      

               }
}


/* This is the main loop after all the variables are declared and setup() is run, this function will loop over and over. */

void loop(){

          for (i = 0; i < 8; i++){                                     

                       digitalWrite(posPins[i], HIGH);         
                       delay(t_delay);                                
                       digitalWrite(posPins[i], LOW);         
                       delay(t_delay);                               

         }                              

       }

Upload the code to the Arduino board, if there are any errors the compiler will stop on the line where it found the error. Check all formatting and spelling of variables if there was an error.


After the program has uploaded, the LEDs should start turning on and off in sequence, if it does not, follow the instructions again and be sure the LEDs are connected properly.


Step 7: More Sequences

We have a sequence that starts at pin 3 and lights up each LED through pin 10, then starts at pin 3 again. Suppose you wanted the LEDs to light in sequence and return the opposite direction? We can add this ping-pong effect by adding another loop after the first loop, and make this one count down.


for (i = 7; i >= 0; i--){

digitalWrite(posPins[i], HIGH);
delay_(t_delay);
digitalWrite(posPins[i], LOW);
delay(t_delay);

}

Now we have two sequences, so our second sequence ping-pongs by counting then counting down. How we select each one when the button is pushed, is to select them from a list of sequences using the "switch" statement.

The Switch statement uses a variable, which we set, it compares the value of that variable to a set of values, like multiple condition statements, if condition is met it executes the statements that are within the scope of the case statement. It takes the following form:

switch(variable) {

                        case 1:
                                     code statements
                        break;

                        case 2:
                                     code statements
                        break;

                        default:
code statements
break;

}

The Switch statement is passed one variable, then the value of that variable is checked against the values for each case statement, it will then execute the code statements within the scope of that case evaluation and its closing break;.

Once we have a way of running different sequences, we need some way of receiving user input to change the states; this is where the button comes in.

We have attached a button to pin 11. The button is in a normally open state, and pin 11 is tied to ground through a current limiting resistor of 10K ohms. When the button is pushed, it ties pin 11, to V++ which is the +5V provided by the Mini's power regulator. The path will be from V++ to pin 11 and not through the resistor to ground when the button is pushed because the path between +5V and ground will be the path of least resistance.

Once the button is pushed and we read there is a HIGH on pin 11, we add one to the sequence variable. After we increment the sequence variable, we check to make sure its value is not greater than the number of sequences (case statements) we have. If it is greater, we reset it to reference the first case statement, starting the sequences all over.

 NOTE: I am not using the default case statement so there are statements within its scope, so it does nothing but end with a break statement. 

Now to put it all together, the following code has two sequences, the first is the linear sequence we started out with and the second is the ping-pong sequence.

/* Flower LED
* Written by Mark S. Drummond, (Gravity Boy) 2009
* You are free to use, distribute, modify, this code.
* Any credit would be appreciated
*


int num = 255;
int temp = 0;
int binNum[8];

int maxLED = 8;
int maxSequence = 6;
int seqButton = 11;
int sequence = 1;
int buttonVal = LOW;
int negPin = 2;           
int posPins[] = {3,4,5,6,7,8,9,10};


int i, t;
int t_delay = 100;
int p_offset = 0;
int n_offset = 0;
int tSTEP = 50;

/* setup() Initialization function, the word “void” before the function name means that the function does not return a value. */

void setup(){
      Serial.begin(9600);          
      pinMode(negPin, OUTPUT);
      digitalWrite(negPin, LOW);

  for (i = 0; i <
maxLED; i++){     
      pinMode(posPins[i], OUTPUT);
      digitalWrite(posPins[i], LOW);
      }
}

/* This is the main loop after all the variables are declared and setup() is run, this function will loop over and over. */

void loop(){

    buttonVal = digitalRead(seqButton);

  if(buttonVal == HIGH){        // read the pin value and check if  HIGH
      sequence++;                   // increment sequence value
      delay(t_delay * 10);        // Stop the button from recording
                                                 // multiple presses

        if (sequence > maxSequence) { sequence = 1; }
      }

  switch (sequence){

      case 1:       //straight sequence

              for (i = 0; i < maxLED; i++){  
                  digitalWrite(posPins[i], HIGH);
                  delay(t_delay);              
                  digitalWrite(posPins[i], LOW);
                  delay(t_delay);                
                }    
      break;
      case 2:      //Ping pong

       // forward direction         
              for (i = 0; i <
maxLED; i++){  
                  digitalWrite(posPins[i], HIGH);
                  delay(t_delay);              
                  digitalWrite(posPins[i], LOW);
                  delay(t_delay);                
                }
      // reverse direction

              for (i = (
maxLED - 1); i >= 0; i--){     // we are counting down to zero, total - 1
                  digitalWrite(posPins[i], HIGH);
                  delay(t_delay);              
                  digitalWrite(posPins[i], LOW);
                  delay(t_delay);                
              }
    break;
case 3:    // every other toggle


               t_delay = 60;

             for (i = 0; i <= maxLED; i++){
                 digitalWrite(posPins[i], t);
                 delay(t_delay);
                 digitalWrite(posPins[i], LOW);
                 delay(t_delay);

                   //toggle t
                   if (t == 0){
                       t = 1;
                       }
                   else{
                         t = 0;
                       }
                 }

                   t_delay = 30;
    break;
    case 4:   // this sequence will light up the LEDs from center out

                    p_offset = 4;
                     n_offset = 3;

                for ( i = 0; i < (maxLED/2); i++ ){       //start at center and count to ends
                       digitalWrite(posPins[p_offset], HIGH);
                       digitalWrite(posPins[n_offset], HIGH);
                       delay(t_delay);
                       digitalWrite(posPins[p_offset], LOW);
                       digitalWrite(posPins[n_offset], LOW);
                      delay(t_delay);

                     ++p_offset;  // light them in one direction
                      --n_offset;  // while lighting them in the other direction
    }

    break;

    case 5:  // random flashing LEDs

    for (i = 0; i < maxLED; i++){

               srand(rand()); // Setting the seed using rand function
               int randomNumber = (rand()%maxLED);  // random number between 0 and maxLEDs
               digitalWrite(posPins[randomNumber], HIGH);
               delay(t_delay/4);     // speed up the delay so that it sparkles
               digitalWrite(posPins[randomNumber], LOW);
               delay(t_delay/4);
         }

    break;

  case 6:  // start fast and end slow, can use this with different patterns.

      for (i = 0; i < maxLED; i++){

             digitalWrite(posPins[i], HIGH);
             delay((t_delay/2) + (i * tSTEP));
             digitalWrite(posPins[i], LOW);
             delay(t_delay);
          }

    break;   

case 7:   //Binary counter, counts in binary on 8 LEDs

// Be sure to use this when you have the proper resistance for each LED

    for (i = 0; i < 255; i++){

          int counter = 0;               
          int index = maxLED - 1;

          num = i;
          temp = num;

            while(num > 0){

                      ++counter;
                      if(num % 2 == 0){binNum[index] = 0;}
                      else {binNum[index] = 1;}

                      num = num / 2;
                      --index;
                 }        // after while loop breaks, the rest of binNum[] is filled with 0s ( MSB->LSB)

/* Forgive the inline format for the for loops, once you know them, they are an easy read */

            for ( t = 0; t < (maxLED - counter); t++){binNum[t] = 0;}

           for( t = 0; t < maxLED -1; t++){digitalWrite(posPins[t], binNum[t]);}

            delay(t_delay/2);

            for(t = 0; t < maxLED - 1; t++){digitalWrite(posPins[t], LOW);}

      }
            delay(t_delay * 10);

    break;

    default:
    break;

   } // end switch statement

} // end main loop() function


Copy the code and once the program starts running, press the button to change the linear sequence to the ping-pong sequence.
We can keep adding new sequences by adding more case statements before the default case statement. The switch statement can be used to test any value from a int, char, or Boolean. You can even nest the switch statement if you wanted to add some set speed variations to a sequence.

There is another added block of code at the beginning of the main loop() function and before the Switch statement; this is used to read the value of the button and increment our sequence variable, it also tests the variable to be sure it is within range before entering the Switch statement; if variable is higher than the number of case statements, reset to 1, which is the first case statement.

  buttonVal = digitalRead(seqButton);    // read button state

  if(buttonVal == HIGH){                             // read the pin value and check if HIGH
      sequence++;                                         // increment sequence value
      delay(t_delay * 10);                              // Stop the button from recording
                                                                       // multiple presses

        if (sequence > maxSequence ||  sequence < 0) { sequence = 1; }
      }


The delay was set to push the time to 1000 ms or 1 second to account for the !speed of the human pushing the button. Note that I added the second conditional test of sequence < 0 in the example above and not in the code. The two bars || is a boolean or, so either statement being true would meet the condition and set sequence = 1. If the first sequence > 2 is true, then sequence < 0 will not even be evaluated.

A trick to adding more sequences is to set sequence right after the button check at the beginning of the main loop(), set the value of sequence to reference the case you are working on. If you are working on a new sequence for case 3: and you want to run test, but don't want to push the button every time to see the sequence you are working on, then use brute force as shown below.


buttonVal = digitalRead(seqButton);

if(buttonVal == HIGH){
    sequence++;
    delay(t_delay * 10);

    if (sequence > maxSequence){sequence = 1;}
}

sequence = 3;   // override the code above and force the sequence we are working on



This will explicitly set the value of sequence to 3 after the button read.I will include extra sequences designed for the flower in the PDF file at the end of this Instructable. I was messing around with the analog values of the analog pins that some of the LEDs are tied to, with the diffusion and a slow fade in and out, was a nice effect. Ramping up and down can be accomplished with a for loop and increasing and decreasing values between +0V and +5V.





Step 8: Prepare PCB Board



COMPONENTS:

1  Arduino Mini
1  mini push button
1  PCB 1.75"  dia. (Ra     hack)
1  10K ohm resistor (brown, black, orange)

TOOLS:

    Solder iron and solder
    Needle nose pliers
    Cutters
    Wire strippers
    Pen (for marking)
    Igor
    Heat gun and shrink tubing


Once the sequences and the programming and testing phase is complete, it is time to squeeze it all into a small space while using big thumbs.With the confines of the bottle caps so small, we need to keep the number of components down.

Using a socket for the micro-controller would be too big and not wanting to solder the micro-controller to the PCB; I found a solution that worked best. I had an old motherboard I kept for possible cannibalization; it happened to be populated with enough jumper pins for this job.

I placed the jumpers only on the pins we are using. To make the pins at the ends of the leads, so they can be pushed into the opposite half of the jumper, clipped component leads or solid core wire are good. Whenever I cut a lead off of a capacitor or from a resistor, I save them for making short jumper wires or whatever. Cut a length 0.5”, place in Igor’s hand, and solder to the end of the LED’s leads; shrink wrap the solder joint but leave 0.25” of the pin sticking out.


The ground wires to each of the LEDs will be tied to a single wire, a mini "Y" cable made out of the Teflon wire, 8:1. Solder a pin to the neck end of Medusa.
It is the smallest wire harness I ever made, even so, it was almost too big for the space. Set to the aside until we are ready to install the LEDs.


Take needle nose pliers and bend the end of the pin where the shrink-wrap ends so that there is a 90-degree angle; do this on all the lead wires. This is so they will fit within the bottle cap. Attach each of the the leads for the LEDs to the Mini, start with the ground wire, then place them into the jumpers going from pin 3 and in order of their sequence.


The power and ground wires for operating the Mini can be treated the same way, we are going to be powering the board with the two pins on the upper right side of chip, ground and +9V.


Now to add the button to the PCB, the button used for this project has two pins at the bottom for connecting the leads, I bent these so they would allow the button to sit flush when mounted to the circuit board. Center the button on the board and solder each pin to the pad at its end.


Push the micro-controller into the PCB board from the side opposite the solder pads. Be sure it is centered and there is an equal count of pads between the edge of the PCB and the corners of the controller. Place the 10K resistor at the end of the micro-controller, which is opposite the crystal, the resistor should be on the same side as the micro-controller with its leads sticking through to the side of the solder pads, do not solder now.


Remove the micro-controller before soldering the resistor leads. Solder the ground wire from the button, to one lead of  the 10K resistor. Create a small lead, about 1.5" out of the Teflon wire, prepare it with a pin and heat shrink on one end, solder the other end to the open lead of the resistor. This lead will go from the resistor to a ground pin on the micro-controller.

Make a new lead 1.5" out of Teflon wire with a pin on one end, push the wire through a hole on the opposite end of the PCB as the 10K resistor and solder it to the other pin of the button. It will be placed in the jumper on a pin of  the micro-controller that supplies +5V.  

Place the micro-controller into the PCB at the same position as before. Place a jumper on the ground pin of the Mini, 4th pin down on the left, and take the short lead we just attached to the 10K resistor and place its pin into the jumper for the ground connection.  


Push the end of a red Teflon wire prepared the same way as our ground wire and push it through a hole on the opposite side of the button so that it protrudes through the hole near the end of one of the button's pins and solder a connection. The pin of this wire connects to the +5V pin on the Mini opposite the ground we just installed. See diagram.


The PCB is ready to be installed into the bottle caps.


I attached two LEDs that are tied to +5 and ground with one lead going through a 150 ohm resistor. I used a yellow LED for the flower's disk.




Step 9: Prepare Bottle Cap



Components:

2 Bottle Caps
1 Rare Earth magnet

TOOLS:

Exacto knife
Drill
Multi-hole drill bit
Pen
Hot glue gun

Two bottle caps are being used in this project, one holds the LEDs and has a hole for the button in the center, the other holds a rare earth magnet and is a protective cap for the micro-controller. The PCB is larger than the caps but the illusion is to be viewed at night, though I do want it to look professional in the scrutiny of light, it is not necessary that it is a complete encapsulation of the board.

To prepare the back cap, place a rare earth magnet in the center and hot glue in place. Marking the cap with the holes for the LEDs was easy enough, I divided the total ridges around the circumference of the cap by the total LEDs  to get the quantity of ridges between each hole's center. Mark the lines, then with the patience and care, place the cap edge over a stick and drill slowly to start the hole; it would be a waste of time  if you drilled seven holes then failed on the last hole when the drill slips, this did not happen, if you have a press all the better.

Drill a hole the same diameter as the threaded part of the button, the button will protrude through in the center of the cap and the threads should provide an interference fit. With an Exacto knife, cut the small seal ridge on the inside top of the cap; making sure not to cut towards any fingers or flesh ,which keeps blood from leaking.  

With an exacto knife, cut two slits 1/4" apart  and 1/4" deep between two holes on the side of the cap, this is for the power cables that run to the 9V battery.

Place the flute end of the LED assembly and hot glue in place. Be sure to not stick the flutes too deep into the cap, we need the room for the wires. Solder each LEDs ground leads to a lead on our "Y" harness. Connect to the ground pin, 4th down on the right side.

Note: the pins on the Mini are numbered from the top left to bottom and then the bottom right to the top, but I do not want to use those numbers to avoid confusion with the number of the I/O pins.

Center the Back cap on the side of the micro-controller and hot glue a bead around its circumference.

Make all the connections for the LEDs, the "Y" harness is tied to pin 2, and each of the LED's positive leads in sequence from pin 3 to 10.

Prepare the power cable. It needs to be long enough to fit nicely in a pocket. As a trick to bundle the positive and negative leads through the length of the wire, I use 1/4" shrink tubing ever 3", I did not do that here, but have in the past and it has been good for wire management. Place a pin at the end of the positive and negative leads. Push these into the +9V and ground on the Mini, using teh jumpers as connectors.

Hook up a 9V battery and wait for the chip to initialize, when it is running, push the button and check the sequences.

Close the top cap so the button is sticking through the center of the cap, and the cap is flush with the PCB. I spot glued in 4 places around the cap so that I could open it in the future. This turned out to be a boon, since on Halloween night the rowdy crowd downtown was a bit rough on the flower and it needed to be fixed the next day. Have fun.


/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/

Mark S. Drummond  ->Gravity Boy
Artist, hacker, tinker, thud


Arduino Contest

Participated in the
Arduino Contest