Introduction: Heartbeat Pulsing LED

This work is heavily derived from several tutorials that I scraped together from other places to get all the info in one place. I will cite all references at the end.

The Project:

Those following me will come to notice that I tie my projects together. I love to learn with a purpose/goal so in this case, the purpose is to improve my Mandalorian Mercs costume. This Instructable will be to improve one of my gauntlets. The large blue "displays" are EL panels but util now the LED domes are just decorative. In this project I'll be adding an LED into one of these spots which will fade in, beat twice then fade out for a heartbeat effect like the attached video.

Materials:

  • Arduino Trinket (Get the 3-volt version for this)
  • Wire and/or Breadboard jumpers
  • Soldering Iron and Solder
  • LED
  • Desktop/Laptop computer with an avalable USB port
  • Mini-USB Cable
  • 3.7V LiPo Battery (optional)

Step 1: Set Up Your Computer

This is going to be the hardest step. If you already use the Arduino IDE, you might need to modify your IDE to work with the Trinket. If you don't already use the Arduino IDE then you can download a special version that already has the changes built in. Naturally, this step will vary depending on which OS your computer uses.

Assuming you are new to the Arduino, the easiest way will be to download the pre-modified version from the Adafruit website. They have instructions and tips for each OS and I found them easy to follow so I won't copy/paste them here.


Step 2: Build the Circuit

The circuit is as simple as it gets. Your Trinket will come without the header pins attached so you can choose for yourself if you want to solder directly to the board, solder to the pins, or use a breadboard.

Breadboard:

If you don't want to commit the Trinket then the breadboard works well. Solder on the header pins that came with your Trinket and they're spaced ready for a breadboard, no sweat. Take one breadboard jumper from PIN 4 to the positive lead of the LED [the longer one] and one from the negative lead to the GND pin. Done. Really.

Solder:

If you like the project and decide to commit a Trinket to this, you'll need to solder leads from PIN 4 to LED+, then from LED- to the GND pin on the Trinket. I grabbed a random red LED that I had laying around and it has been running for three days straight without an inline resistor. I tried a 220Ω resistor inline out of habit but it was too much and the LED couldn't be seen since the Trinket is only passing 3V as it is. If you bought the 5V Trinket you may want a small resistor in there.

Step 3: Program the Trinket

For those unfamiliar with Arduino, a program to be uploaded into an Adruino is called a "sketch".

Open up the Arduino program that you installed in Step 1 and it will give you a blank page to type your new sketch. Paste in the code below:

int ledPin = 4;    // LED connected to digital pin 4 for Trinket

void setup()  { 
  // nothing happens in setup 
} 

void loop()  { 
  // fade in from min to max in increments of 5 points:
  for(int fadeValue = 0 ; fadeValue <= 255; fadeValue +=5) { 
    // sets the value (range from 0 to 255):
    analogWrite(ledPin, fadeValue);         
    // wait for 20 milliseconds to see the dimming effect    
    delay(20);                            
  } 
  
  delay (100);
  analogWrite(ledPin, 0);
  delay (80);
  analogWrite(ledPin, 255);  
  delay (100);
  analogWrite(ledPin, 0);
  delay (80);
  analogWrite(ledPin, 255);  

  // fade out from not-quite-max to min in increments of 5 points:
  for(int fadeValue = 200 ; fadeValue >= 0; fadeValue -=5) { 
    // sets the value (range from 0 to 200):
    analogWrite(ledPin, fadeValue);         
    // wait for 30 milliseconds to see the dimming effect    
    delay(30);                            
  } 
}

Once that is pasted in, make sure the Trinket is plugged into your USB port and press the button on the Trinket. Your Red light on the Trinket will start to flash to let you know it is ready to receive the code. While it is flashing, hit the right arrow on the computer. If all goes well, you will see "Compiling sketch" flash pretty quickly then "Done uploading".

If you get any errors, check the Troubleshooting step. I'll put in what I can think of now and add more tips as people ask.

If you didn't get any errors, your LED should be beating away and you're either staring at it or plugging away at the code trying to figure out how to make it do something different.

Step 4: Troubleshooting:

If you have trouble uploading the sketch to your Trinket, the first things to check are in the Tools menu.

Ensure that Tools > Board > Adafruit Trinket 16Mhz is selected. If you don't see this then I am guessing you didn't install the modified version of the IDE from Step 1 or you tried to install it side by side with the unmodified version. I ended up uninstalling the original version and use only the modified one.

Another thing to check will be to make sure Tools > Programmer > USBtinyISP is selected.

If both of those are ticked and you are still getting an error, drop me a line and we'll try to get it sorted so i can add it here for others.

Step 5: What Now?

If you are like me, you've already tried messing with the code to see what you can change and flashed a few other variants to the Trinket to see how they work. Mess around with the speed of the fade-in and fadeout, change the delays on the heartbeat pulses. The best part of the Trinket over using 555 timers and resistors is that you can try dozens of different speeds and get it exactly how you want. The Trinket only has one PWM pin so only one LED can fade in and out, but on another pin you can do on/off.

Set the pin that you are using:

int led2 = *pin number*;
pinMode(led2, OUTPUT);

From there, to turn the LED on you use:

digitalWrite(led2, HIGH);

to turn the LED off is:

 digitalWrite(led2, LOW);

Step 6: Citations:

Halloween Props Contest 2015

Participated in the
Halloween Props Contest 2015