I’m trying to control a relay from Raspberry Pi that will switch an LED on/off. The relay is working (lightning up and clicking), but the LED doesn’t turn on.
Here is how I wired everything:
VCC – 5V
IN2 – GPIO pin 19
GND – GND
NC – GND
COM2 – 9V Battery Positive side
I’m aware that the way I wired NC and COM are probably wrong and I would like to know how I should wire the LED side so that it can be controlled from the relay and Raspberry Pi
- Welcome and nice to meet you. (1) Your wiring list seems not complete. (2) It is not clear why there is a “COM2”. Do you have a dual relay module with two relays on board, so you have COM1 and COM2? (2) I am using a random relay as an example, so your relay might not match my wiring diagram. (3) It would be nice if you can show us a photo or a link to your relay. Please feel free to ask us any newbie questions. Have a great project! Cheers. – tlfong01 53 mins ago
(1) How to use Rpi to control a relay to switch on/off a LED?
(2) How to wire the NC and COM terminals of the relay?
Let us use the following example and look at right side, the relay switch with the COM, NO, and NC terminals:
Part A – How to wire the COM and NO terminals
(1) COM (Common) – The COM terminal connects to the power source, eg +5V, +6V, +9V, +12V of a battery.
(2) NO – (Normally Open) – The NO terminal connects to the load, ie the LED, with a series protecting resistor, usually 4k7 to 1k2.
(3) Grd – (Ground) The ground terminal connects to the other end of the load.
(4) NC (Normally Open) – The NC terminal is not used, ie, left open or disconnected.
Part B – Troubleshooting notes
(1) It is important to connect a protective resistor in series with the LED, otherwise too much current would flow through the LED and fry it.
(2) Usually an ordinary LED needs 5mA ~ 20mA to turn on. The value of the protective series resistor can be calculated as below:
(a) Vcc = Voltage to power the LED, supposing 9V,
(b) V = voltage across the LED, supposing 0.4V,
(a) Ir = current flowing through the resistor and LED, supposing 10mA,
(c) Vr = voltage across the protective resistor, = 9V – 0.4V = 8.6V,
(d) R = value of resistor = Vr / Ir (Ohm’s Law) = 8.6V / 10mA ~= 860Ω
So you need a 860Ω resistor to protect the LED. Usually you don’t need to be that precise, because all values of components and power etc are only rough numbers, so a resistor of 512Ω to 1kΩ should be good enough.