I want to build something of a smart home device such as a smart switch /outlet for example that controls something like a light. However, I don't know what the wiring should be Like, if it's possible. The main power source will come from an outlet in the wall, after that, how can I use it to power the RPI at the right voltage, and use it with a relay to power a light. Thanks EDIT: All the tutorials I have seen use some sort of separate power supply for the pi (don't usually show, but could be laptop or from wall plug) which is used to control a different power supply (the power for the smart plug). I want to know how I can use one power supply for both?
I use my Raspberry Pi to control my grow lights using a power relay
This is a great way to control line voltage with a Pi and lets you do all sorts of fun stuff on your pi. for example, I use the Pi for timing the daily light cycles.
I do discourage designing your own power line relay. If you make a mistake, you risk severe electrical shock to yourself and others.
Instead, please consider using a relay to turn on a 12V LED light strip. This lower voltage is much safer and will allow you to automate, for example, under-counter kitchen lighting. Cool, right? It will also allow you to power your PI and the light with the same 12V power supply. All you need is a commonly available DC-to-DC buck converter such as the LM2596 to convert the 12V to 5V to power the Pi via extension header pins 2&4. The LM2596 is adjustable--be sure you are providing 5V before hooking it up to the Pi or you will have dead Pi.
The following relationships hold in the proposed circuit. The components are commonly available and affordable.
line voltage (e.g., 117V) -> LED Driver -> 12V 12V -> LM2596 -> 5.2V -> Pi 12V -> LED light strip
For specific information on circuits, you can consult SE Electronics For specific information on regulations regarding voltages subject to wet contact, search for "voltage wet contact NEC".
The RPI 3 requires 5 volts to operate. This is normally supply using the RPI 3's micro USB port. As the RPI 3 has the ability to run faster on multiple processor cores, it is stated here to get a power supply equal to or lager than 2.5 amps.
The GPIO pins of the RPI 3 do not supply enough current / voltage to drive most common relays directly. You will need to amply the signal first. Alternatively, there are many solid state relays which can be driven directly by a processor. Perhaps you can find project with goals similar to yours by searching for "Raspberry Pi" and "solid state relays".
You probably don’t want to power relays and a Pi from the same source. It’s not a big no-no, just a tip. Try to keep the Pi free from anything except its own powersource, which is noisy enough.
Get 5/12V relays (auto shops carry quality 12V relays), PC817 optocouplers, 2N2222A signal transistors or 2N7000 MOSFETs, a few 4.7Kohm pulldowns if using FETs, 2N5819 schottky diodes, some PTH board, 0.5mm solid core wire.
The PC817 optocoupler IR LED switches perfectly at 3V3 with a 1Kohm resistor.
Do not have shared ground between the relay power supply, and the return ground to your Pi. Keep relay power source competely separate, the only connection should be made via the optocoupler, which can withstand a nominal 5000V_RMS.
Ensure there is a 1.5-2mm groove between NC, COM, NO relay paths by scoring the glassfiber with a boxcutter, then cover these with hot glue. The occasional spark is a fire hazard. Embed your relay board in a safe enclosure (not directly in contact with metal), use a cut piece of rubber to insulate. I use 5mm from an auto shop.
For 25$ you can build a staggering amount of such relays. Adafruit really should stop pretending their products are not made in Asia. You local autoshop will have relays of a quality you cannot even buy from Adafruit:/