I want to illuminate an LED built into a switch with the Photon’s digital I/O but I do not know what resistor to use with the LED.
The switch in question is the 3 volt version of this one:
Any suggestions?
I want to illuminate an LED built into a switch with the Photon’s digital I/O but I do not know what resistor to use with the LED.
The switch in question is the 3 volt version of this one:
Any suggestions?
Welcome to the community.
Without knowing the forward bias of the LED - a 10mA source from the Photon pin gives 300 ohms - so say 330 ohms as a standard value. Someone will probably suggest a more exact value but that should work fine.
I can’t find the datasheet, the site is in a different language. Since it comes for different voltages, my guess is that the resistor is already built in. The 3V version should work fine at 3.3V, but you have to check how much current it will draw. You can safely get 10mA from an I/O pin, depending on which Particle device you want to use.
I used a 270 ohm resistor and it worked great. Thanks for the help!
I’m planning on using 8 switches on a photon. How would you determine how much current the LED will draw?
@mjpalm21, if you use 8 switches, each with a resistor limiting current to 10mA, then that makes a total of 80mA draw. Depending on what other hardware you have drawing current from the 3V3 pin, you may want to consider adding a separate3.3v LDO powered from the Vin pin. This assumes you are lighting all switches all the time and not driving those LEDs via GPIO pins.
Since I can’t find a datasheet, a basic multimeter will do.
I will be driving the LEDs with the GPIO pins. Basically the switches will be used as inputs and the LEDs will be used to indicate that the switch is on/off.
The Photon’s data sheet indicates that each GPIO can do 25mA - so I’m thinking it would be fine driving the LEDs…
@mjpalm21, I am confused.
You plan to drive the I/O to turn on the LED? Then, what reads the switch state? The same I/O pin or a different one? I wouldn’t short the I/O pin with the switch while it is high.
You could wire it such that the I/O does not drive any current.
When the switch is closed, the LED is on and the I/O will read zero.
When the switch is open the LED is off and the I/O will read 1.
If you switch the position of the LED and the switch, you get the opposite states.
You might need a resistor (100k) in parallel with the LED to guarantee some leakage current.
I agree that it almost certainly includes the the appropriate resistor for each of those listed supply voltages. If it were me, I would try the 3V version: first with no resistor, and then add whatever resistance is needed to get the currrent down to 10 mA.
You have to take heed to what @peekay123 is saying. There is more to it than just looking at the current output of a pin in the data sheet. In a situation where one is driving more that typical logic currents to drive things (I.E. relays, leds, and such) you need to make sure your not going over the package total current rating.
The Photon has a spec named “Iio total”, which is 120ma MAX. As an example, if 5 I/O pins are driving 25ma, your exceeding the package total current capability’s. Just keep this in mind for how many things you drive with I/O pins.
I’m using momentary switches to toggle the switch state. The LED indicates the current state which can be changed via the momentary switch or software via timers etc…
Yep, it does have an internal resistor. I hooked it up directly between 3v3 and ground and it measures just 3.2 mA.
Does the above discussion apply to the Photon 2 as well, and that 330Ω ought to be OK?
Good question - whilst 330ohm was OK for Gen2 device like Photon/Electron - Photon2 /P2 is much less. I am struggling to find the maximum current on GPIO pins in the reference data. For the RGB status LED the recommended resistor is 1K ohm on each LED - try this value and you won't damage anything.
Thanks so much for this, @armor. It'd be good if one of the Particle people could weigh in on this (or perhaps this is their cunning way to sell more Photon 2's, by having me short out one or two
).
On the P2 and Photon 2, the pin drive strength is always 16 mA.
For the nrf52840-based Gen 3 devices, the drive strength is much lower at 2mA (default) and 9mA, max. For the original STM32-based Photon and Electron, the drive strength is 25mA max though the overall GPIO current sink could not exceed 200mA.
So, for the Photon 2, there are two things to consider. First, the 500mA output current limit of the onboard 3.3v switching regulator and second, the current limit of the GPIO (and inherently, the overall GPIO current as well I suspect). For the first condition, make sure the current being pulled from the Photon 2's 3.3v pin doesn't exceed 235mA which is the 500mA max minus the 265mA peak needed for the WiFi connection.
For the LEDs, I would suggest that current be limited to below 6mA per LED and, assuming red LEDs with a 1.8V voltage drop, that would mean a (minimum) current limiting resistor value of 250 ohms per LED. The previously stated 330 ohms would also work. If you need more current, I would suggest using drive transistors, coupled with appropriate current limiting resistor for each LED, powered by Vusb or Li+ directly.
Thanks, @peekay123. Is it correct that this is all cumulative? That the total being drawn from the 3.3V pin and the GPIO pins should never exceed 235 mA?
Yes,the total (cumulative) current drawn from the 3.3v pin should not exceed that amount.