Today we will connect a relay and use it to turn on an LED, but you can also easily turn on a lamp.
Warning : though Raspberry Pi can use similar to Arduino, needs a little more attention. The Pi contacts work at voltage 3.3 V while the Arduino uses 5V. While the Arduino can be broken, breaking the Pi is much easier since the pins are directly connected to the onboard chip — sending 5V down can fry it.
So be very careful when trying to reproduce Arduino projects on your Pi — either follow the specific Pi manual or make sure you have a good grasp of basic electronics.
- NPN transistor such as P2N2222A
- Resistor 1k
- Relay; I’m using a 4-relay 5v module which has an additional built-in protection circuit (so no need for additional diodes
- LED and 220 ohm resistor for testing
- Lay cable
Splitter cable («Cobbler Kit»)
The GPIO pins are located on the side of the Pi, next to the RCA video out connector.
While you could technically plug some female-ended patch cables directly into them, they’re not labeled in any useful way, and so you’re more likely to break something. Instead, get a breakaway cable like one from Adafruit, or one of the many cheaper clones on eBay. You may need to solder this as it will come in kit form.
While there is a notch on the side of the board to indicate proper cable placement, the Pi side does not. Make sure the 3v and 5v pins on the far corner of the Pi are aligned with the corresponding pins on the board. Of course, if you bought a case that doesn’t show the GPIO header, you’ll need to work with a bare Pi or cut a hole.
Alternatively, you can get a complete board that sticks on top of your Pi and usually comes with a bunch of useful components.
Set up the schema as described below. I omitted the relay diagram as this will vary. Use terminals NO (normally closed) and COM your relay for your LED or other device.