Arduino LED IR remote control multiplier

More progress on my house LED Christmas decoration project.

If you haven’t read the prior post about my Christmas lights go read it now.

My LED strands can be controlled by an IR remote. I built a simple IR detector circuit with an Arduino and used the IRRemote library to determine the IR hex codes I needed to mimic this hand-held remote controller. Given that, I have this problem statement:

Problem statement: Control up to 16 identical IR-commanded devices in unison. Each IR command sent must hit 16 devices simultaneously. The devices are physically separated but within “wires can be run to them” distance.

Previously I prototyped a trivial, always-on, circuit of multiple IR emitters in series. That was just a way to learn some of the key parameters I needed to know, such as the forward voltage drop of the IR emitters.

In this next step I’m hooking up a MOSFET to control that series circuit so they can be turned on and off to actually send the hex codes. I also did some more calculations and tests to optimize the circuit values. My result, shown below, can drive 8 IR emitters from one Arduino output:
ex1

You may wish to click on that picture to expand it to full size / full resolution.

The MOSFET is a “logic level” N-channel Power MOSFET from International Rectifier, part number IRLB8721. It can handle far more voltage and power than necessary in this circuit. I picked it because it was easy to find (e.g., Adafruit sells them) and, more importantly, it turns on at a “logic level” of Vgs = 4.5V at the Gate G. The Arduino output pins supply 5V so this will work well for controlling the MOSFET from an Arduino output pin.

Ignoring all the resistors for a moment, the operation of this circuit is pretty simple. When Arduino pin 3 is low (0V) the MOSFET is off and no current can flow from the Drain (D) to the Source (S). Therefore the IR emitter LEDs are off as they have no connection to circuit ground. When Arduino pin 3 is high (5V) the MOSFET turns on and current can flow from D to S, connecting the ground side of the series of IR emitters and allowing current to flow through them and turn them on.

Now when my IRRemote-driven software modulates Arduino output pin 3 and drives it high/low in an IR code pattern, the MOSFET turns the series of 8 emitters on and off accordingly. Their power is coming from an external wall wart supply, not the Arduino. The voltage of that supply is labelled Vx = 12.6V in the diagram.

My wall wart was unregulated and its output voltage varies according to load. It actually says “9V” on it but supplies 13.9 volts completely unloaded and “less than 13.9 volts” under various loads. My prototype circuit gave me an idea what this approximate unregulated voltage would be — around 12.6 volts with about 40mA of load. I used that “about 12.6 volts” guess to pick some resistance values and build this circuit and then measured the results and tweaked accordingly.

Note to self: Next project use a zener diode voltage regulator. Though in this project none of the values are critical; the primary constraint is to keep the current through the IR emitters between 20mA and 100mA. That’s a huge range and it really doesn’t matter where inside that range I end up because the emitters are literally taped right onto the receivers so the power they run at is irrelevant. This is a case of “anything in that wide range is good enough” even though it’s kind of a hack.

To test some values I attached the Gate G directly to +5V so the MOSFET would simply always be on and then measured the “as loaded” Vx value. I then adjusted the resistor values accordingly. There’s some circularity here because changing resistance values changes the current, which can change the IR emitter voltage drops, and thus can circularly affect the resistance calculation. But in practice it just doesn’t matter since, as already explained, if I just get close and don’t exceed any maximum values I’ve got something that works just fine for this application (once again note to self: use a regulated supply next time).

So, with that test I found Vx = 12.6V as shown in the diagram. The voltage drop across all 8 IR emitters was 10.1V leaving 2.5V to be dropped across current-limiting resistor R1.

The current flowing through the IR emitters (and the DS portion of the MOSFET) is thus

I = (12.6V – 10.1) / R1

I picked R1 = 56Ω to get a current flow (computed) of about 45mA.

NOTE: I haven’t yet built the second copy of this circuit. Since I have more than 8 devices to control I will build a second copy of this circuit and hook it up to the same Vx supply and the same Arduino pin 3 output. It’s possible that the current draw for the second copy of the circuit will lower the supply voltage below 12.6V. I plan to measure that but, as already noted, so long as the resulting current flow through all the LEDs remains above 20mA this really won’t matter. If necessary I will come back and recalculate new R1 values with the full 16 IR emitter loads. Expect at least one more post on this topic with all that verified.

Resistor Rg protects the Arduino output pin from excessive current draw when the MOSFET transitions from off to on. When the MOSFET is off and Arduino pin first rises to 5V, the Gate input G acts somewhat like a capacitor between G and S. This is just inherent in how MOSFETs work. This means DC current will flow for a brief instant between G and S until the MOSFET accumulates enough charge and blocks further DC current flow “somewhat like a capacitor between G and S“. This is all part of the transition of the MOSFET from the OFF state (very high resistance between D and S) to the ON state (very low resistance D to S). To keep that brief current spike below the Arduino max pin output of 40mA, I choose Rg at 220Ω which leads to this calculation for the current draw when G and S are momentarily (effectively) shorted:

Ig = 5V / 220Ω = 23mA

That 23mA (which is within the 40mA limit) will only be drawn for a brief fraction of a second as the MOSFET charges. During the instant of time the 23mA is flowing the resistor will dissipate:

W = I^2 * R = (0.023 * 0.023) * 220 = 116mW

I’m using a 1/4W resistor which is more than enough to tolerate this approximate 1/8W (that happens for a short period anyway).

It is worth pointing out that I have some uncertainty around this topic; truth be told when I first built this circuit I had no Rg in there and my Arduino did not blow up. I assume this is because the effective capacitor between G and S charges so quickly that a very brief instantaneous current spike doesn’t have enough time to fry the Arduino. There may be other complex reasons the Arduino did not fry. Regardless, it seems like a bad practice to let that current spike happen so I added the Rg resistor to the circuit as soon as I had read about the capacitance effect.

As I’m writing this I realized this will lead to a 46mA spike being drawn when I hook up the second copy of this circuit (against an Arduino recommendation of 40mA max), because there will be two MOSFET gates hooked up to the single pin 3 output. Honestly this didn’t occur to me until just now as I’m writing up this posting (one benefit of writing this stuff up!).  So I’ll likely go back and bump Rg up to 330Ω which reduces that current to 15mA for one circuit, 30mA for two, and also slightly alters the calculation below (but not in any way that changes anything important).

The other resistor, Rgs, ensures that the gate G will be pulled down to ground even if the Arduino is turned off. Sometimes this is called a gate bleed resistor because it also serves to discharge the effective capacitor charge between G and S (discussed above) during a transition from ON to OFF. In our application the Arduino can actively sink current so Rgs isn’t needed for bleeding the capacitor. Regardless, it’s another “good practice” to put this in there and, as noted, it ensures the gate will be at ground potential if the Arduino happens to be off.

l picked a value large enough to ensure that the voltage appearing at G will still exceed 4.5V as the two resistors Rg and Rgs form a voltage divider between the Arduino output pin (when it is high at 5V) and ground:

Vgs = 5V * (Rgs / (Rgs + Rg)) = 4.94V

which is still plenty to trigger the gate (if Rg is increased to 330Ω this still works out to 4.9V). When the Arduino output pin is high there is a current flowing through these two resistors of:

I = 5V / (Rgs + Rg) = 0.2mA

i.e., one fifth of a milliamp, nothing to be concerned about.

Still to do:

  • Build the second copy of this circuit
  • Reverify the unregulated wall-wart voltage level when driving both circuits; possibly update R1.
  • Change Rg to 330Ω “on general principles” to ensure the instantaneous draw remains under 40mA during MOSFET turn-on transition.
  • [optional] learn more about what that instantaneous draw really is to get a better handle on future Rg for future projects.

2 thoughts on “Arduino LED IR remote control multiplier”

  1. On the Rg thing, the capacitor current model equation: I(t) = C * (dV(t) / dt) tells us that the instantaneous current draw will depend on the rate of change of the Arduino pin from zero volts to 5 volts. If it changed instantly, in a true square wave, the current flow would be infinite (as the derivative of V(t) would be infinite). Of course we know it doesn’t change instantly; it presumably ramps .. steeply, but still ramps. This is just a teaser of math to say that I still really don’t know: a) why the Arduino didn’t blow up without Rg and b) what the true instantaneous current draw without Rg would be.

Leave a Reply

Your email address will not be published. Required fields are marked *