The pin numbering on my IDC plug should be though of from above the connector, to make it correspond with the 26-pin header numbering. I’d recommend you double check these two components before powering up. The pin ordering varies by type, so check the datasheet. Similarly, take care to correctly identify the collector, base, and emitter pins on your transistor. Take care to orient the diode correctly, or you’ll short 5V to ground via the transistor when the GPIO is high. when switched off), allowing the power to dissipate more gradually, avoiding a voltage spike. The diode in the circuit is there to conduct the current generated by the de-energising coil back across the coil (e.g. Most general purpose NPN transistors with an minimum hFE of say 50 to 100 could be used in place of the BC337 – it will depend on a) how much current you’re willing to draw from the GPIO pin, b) how much current is required to energise the relay’s coil, c) the actual hFE of the transistor in your hand, since they vary wildly and the current gain could easily be significantly more than the stated minimum. This current is enough to saturate the BC337 transistor, causing current to flow on the 5V rail through the transistor, and therefore also through the relay’s coil. The choice of GPIO 17 was simply because I considered it less likely to conflict with other peripherals likely to be in use.Īlthough the pin is marked 3.3V on the schematic, don’t confuse this with the 3V3 pin – I labelled it with the voltage to highlight that a 3.3V GPIO pin is driving a 5V load – it could also drive a 24V coil, for example, if an appropriate DC power supply is used rather than the Raspi’s 5V line.Įssentially, to activate the relay, all the circuit does is send a few milliamps at 3.3V from the GPIO pin, through a 1K resistor (you may choose to increase this to 1.2K if you want to be strictly below 3mA). The GPIO pin used in the example code is GPIO_17, which appears on pin 11 of the Raspberry Pi’s 26-pin expansion header (opposite GPIO_18 (PCM_CLK) and beside GPIO_21 (PCM_DOUT)). Don’t ever put AC mains into your breadboard! Schematic for a relay via GPIO on the Raspberry Pi Relays sometimes don’t fit easily onto a breadboard, so you might want to build the circuit on veroboard instead, or just mount the relay on veroboard and add two pins for the coil contacts (allowing you to breadboard it). In general, large loads need heavier contacts, which in turn need bigger coils to switch them, and bigger coils need more power from your circuit. DC loads are rated lower because they arc (spark) more, which eventually wears the contacts to the point of failure. for your lamp, motor, etc.) that can be carried at the given AC and DC voltages. The AC and DC load ratings relate to the switch-contacts, and state the maximum load current (e.g. The most important to our circuit is the coil rating, which is the current at a specified voltage required to energise the coil (activate the switch), sometimes expressed as milliwatts (mW). Essentially, the transistor is used to energise the relay’s coil with the required voltage and current.Ī relay will often have 3 significant voltage/current ratings specified coil, AC load, and DC load. A relay (5V DC coil), a BC337 NPN transistor, a diode, and 1K resistor. There are four components to this circuit. Tip: you can buy plug-in low-voltage AC power-supplies if you want to play with triacs. I recommend sticking with mechanical relays until you’re entirely sure about what you’re doing. opto-coupled Triac), but it’s quite easy to make a wrong assumption and blow everything up with a loud bang and a big spark. A more efficient alternative to switch an AC load would be to use a solid-state relay (e.g. a 9V DC battery/bulb circuit for testing), and the concept of a mechanical switch is very easy to grasp. A mechanical relay allows a safe learning environment, since you can switch any load with it (e.g. Even a cheap relay like the Omron G5LA-1 5DC can switch loads of 10A at 240V.Ī word of caution: don’t tinker with mains voltages unless you’re really ( really) sure about what you’re doing. There are only four components required, and the cost for these is around 70p, so it would be a good candidate for a classroom exercise. Although a simple project, I still learned some new things about the Raspberry Pi while doing it. There’s something exciting about crossing the boundary between the abstract world of software and the physical ‘real world’, and a relay driven from a GPIO pin seemed like a good example of this.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |