December 07, 2010 by nanaeem Hi, Using a few project descriptions on the web I am creating an IR remote using NK for my Nikon D5000. I have the basic functionality working but was thinking that the IR range is less than I had hoped for (works well upto 3 feet). My question concerns increasing this range. I am unaware of which IR LED I am using (no-name brand that I found with no accompanying datasheet). A thorough search of this and other forums leads me to believe that 80mA is a safe current to pulse the led. The voltage across the LED at 100mA pulsed for 20ms is typically 1.5V. I am using a current limiting resistor (currently 1K). Basic setup: PC5 (pin 28) connects to the 1K resistor which connects to the IR LED. Q1: I read somewhere in the nerdkits tutorials that "Atmega168 chip allows 40mA max into or out of any pin". Does that mean that with my current setup I can not possibly increase the current over 40mA. (if I was to remove the resistor completely I would get max 40mA at the LED?) Q2: For my current setup I calculate the following: - somewhere on the forum I read that when PC5 is set, the voltage is 4.2V. That said, if I assume a 1.5V drop over the LED this means that the current flowing with my current setup using V=IR, 4.2-1.5/1K = 2.7mA (very low and possible reason for poor range). Q3: If I was to switch the 1K resistor with a 33 ohm resistor I calculate that the current should be 4.2-1.5/33=81.8mA. This would be ideal in my case (I think). However: - will this work given the statement that: "Atmega168 chip allows 40mA max into or out of any pin". Maybe the answer to Q3 is no I cannot drive 81mA with the current setup and that is why I have seen a number of projects use a BC547 NPN transistor. The base is connected to the pin, Collector connects via a small resistor (33ohm) to the IR LED (which is connected to 3V in this particular project) and emitter is connected to ground (I believe this is the standard "switch" use of a transistor). Q4: Is this the right approach to take. If yes, I will have more follow up questions :) Disclaimer: I have a CS background but no previous electronics knowledge. Only started messing around with the NK a couple of weeks ago. If I have used any lingo incorrectly feel free to correct me :) Waiting to hear back from someone. -N. The pin current isn't self-limiting. If you try to draw too much current you can damage the chip, assuming that the power supply you're using can supply the current, i.e. it might not be a problem on 9V battery power. The 40mA limit is something that you need to impose on your design to protect the microcontroller. If you need to drive more current, have the MCU drive the gate pin of a MOSFET (draws zero current) and use the MOSFET to switch on/off the power to the LED. Thanks bretm. That does make a lot of sense. I will use a MOSFET. However, for my curiosity can you confirm the following if I was not to use a MOSFET: 1- When using a 5V supply, if a pin is set high does that mean I get the full 5V at the pin or is there a decrease: I seem to remember reading the number 4.2V somewhere. 2- Assuming I get the full 5V and that the IR Led will have a voltage drop of 1.5, to get 40mA I should have a resistor of (5-1.5)/40=87.5 ohms. Now for using the MOSFET: 1- Are the following connections correct: I connect the gate to the MCU pin. I connect the Drain to the IR LED's cathode via some resistor R and I connect the source to ground. I connect the IR LED anode to 5V. 2-Computing the value R if I want to limit current to 80mA. Can I assume that the MOSFET has negligible resistance so that the only two resistances are from the LED and resistor R. In this case to get 80mA: 5-1.5/80 = 43 ohms. Appreciate the help. -N. When the pin is high it just means the voltage will be within an agreed-upon range. It is not regulated, and will vary by the load on the pin and even on other pins. The math is right, but don't assume 5V and don't assume 1.5V. Look for an I-V curve for a typical infrared LED and it will tell you what the voltage drop will be at 40mA. Or make a quick little circuit with a pot and adjust the current to 40mA and then measure the voltage drop. The connections are right for an n-channel MOSFET. For p-channel you'd need to swap the drain and source. You don't need to assume anything about the resistance, and you definitely can't assume it's negligible. Find the datasheet (I think the Nerd Kit comes with 2N7000 n-channel MOSFETs) and look at the characteristic curve for Vgs=5V. It will show you that there will be a small voltage drop Vds when Ids is 80mA. Thank you so much for your explanation. I have been finding it hard to understand datasheets. There is so much information in there which I have no clue about. I will look into this in more detail myself. Once again Thanks. -N.