The Japanino, and using LEDs

Ok, so you've gotten the Japanino, you've written your sketches to your heart's content, and you've pretty much gotten your money's worth from the P.O.V. You're ready to move on and build your own circuits. You've studied basic electronics, read the Arduino tutorials on how to solder and build boards, you've got a breadboard and you ran to Radio Shack or Fry's to pick up a handful of LEDs and some jumper wires. Then, as you were reading the various articles on how to hook up the LEDs to the Japanino you found yourself in a quandary. Some of the articles tell you to connect a resistor to the LED and some don't. The articles that do, state that you'll destroy the LED unless you have that resistor, and the ones that don't have videos showing the LEDs running just fine without explaining why.

So, what's the deal? Do you need that resistor or not? If so, what size? If not, then why don't the LEDs burn out?

First, an LED (light emitting diode) is a very small piece of crystal (a diode) that emits light when a current runs through it in the correct direction (in the wrong direction the current doesn't flow at all). Generally, LEDs have a specific voltage that they run at, and increasing the current at that voltage causes the LED to emit more light. When you exceed the current rating of the LED, the crystal gets destroyed and you might as well throw it away.

The voltage across the diode (the voltage rating) depends on the color of the LED, and can be 1.6V to 2.0V for red LEDs, and 2.48V to 4.0V for purple LEDs. The current through the LED can be 1mA to 20mA (or more), depending on the design. So, when you buy the LEDs, you can check in advance the voltage and current ratings for them.

The output pins of the Japanino can supply 20 to 40mA (milli-amps). What will happen is that when the output pin turns on, it will try to go to 5V. Normally, the output pin will succeed and it will read around 5V if you connect a voltmeter to the pin. However, if the output pin hits its maximum limit for output current, it will then stop at whatever voltage the diode is on at (that is, if it's a purple LED, the output pin will max out at 4V). This won't damage the Japanino, but it may stress the LED somewhat. The main impact is that the LED will be very bright. And, if the LED can handle 20-40mA, everything will be fine.

A Secondary Warning: There are several fanatical electronics engineers on the net that will scream themselves red in the face if you don't add that resistor, that they generally recommend to be 220 ohms. If you plan on going to an Arduino forum to ask for help on some circuit you're playing with, make sure that your schematic at least SHOWS that you have the resistor in place, or they won't even bother talking to you.

As shown in the picture, the Japanino has an "internal buffer", which is a fancy way of saying that there's some built-in resistance for each output pin that restricts the maximum amount of current each output pin can supply.

On the other hand, it is a good idea to add a resistor in series with the LED just to extend your battery life. (Or to protect you if you accidentally connect the LED directly to the 5V pin, which is GUARANTEED to blow it out.) The less current the LED draws, the longer the batteries will last. Many of the circuit designs I've seen suggest just a 100 ohm resistor. You can try using alligator clips to connect 2 or 3 100 ohm resistors in series and see which value gives you the amount of light you desire from the circuit.

Naturally, if you have the requirements for the LED, you can use Ohms law. The Japanino battery pack is 4.5V. If you have a red LED that uses 20mA at 1.7V, then

V = I * R (Voltage = current * resistance)
or, R = V / I

R = (4.5V - 1.7V) / 0.02 = 140 ohms.

For a purple LED at 4V and 10mA:

R = (4.5 - 4.0V) / 0.01 = 50 ohms.

So, using a 100 ohm resistor would probably work in most cases, if you don't want to bother buying individual 50 or 140 ohm resistors.

The easiest thing to do is to prove this yourself. Go to back to Radio Shack or Fry's and get a 100 ohm resistor.

(Our starting set-up: The Japanino, a red LED, and a 100 ohm resistor.)

Run the below sketch to set all of the output pins (D0-13 and A0-A5) to 1's.

// Set all output pins HIGH sketch

void setup() {
for(int i=0; i<20; i++) {
pinMode(i, OUTPUT);
digitalWrite(i, HIGH);
}
}

void loop() {
}

Connect the short pin of the LED to the ground pin (Gnd) on the Japanino, and one end of the resistor to D13. Use a jumper wire to connect the free pin of the resistor to the long pin of the LED.

If you did this right (and you have power turned on to the Japanino), the LED should light.

(Notice that I'm actually using pin D8 here to get some space between the LED and the resistor.)

Now, take the jumper wire running between the LED and the resistor from the resistor and connect it instead directly to the D13 pin.

(Or directly to pin D8. Doesn't matter because all of the output pins are outputting 1's.)

The LED should continue working, only now it will be a little brighter.

(If it stays dark, either you need to recheck your wiring or you just burned it out, proving that you really do need the resistor for that style of LED. To verify that the LED is still good, reconnect the jumper wire from the long leg of the LED to the free pin of the resistor as you had it before.)

Notice that in the above sketch we can do all the work in the setup() function, which will leave the main loop() function empty. This is because we just need to run the digitalWrite() commands once, and if we put them in the loop() they'd be running infinitely.

--------------------------
=================
--------------------------

Again, though, the Japanino output pins are buffered in order to allow you to connect the LEDs directly to any pin, without needing to use a resistor. This is good for those cases where you're limited on space on the circuit board and don't mind going through batteries fast and probably shortening the lifespan of the LED. If you don't want to be yelled at by some engineer, then add the resistor.