Raspberry Pi controlled lamp using a relay & mains procedure

lampmainsraspberry pirelay

I am trying to turn on and off a lamp I have at home using a relay controlled by my Raspberry Pi. Here are the exact parts I will be using:

Raspberry Pi B+
enter image description here

My lamp:

enter image description here
enter image description here

My relays:

enter image description here

Potential outlets I would be using (mains):

enter image description here

OR:

enter image description here

With all the equipment being listed, my procedure would be:

Peel off the lamp cable and connect the lamp's power supply to the relay so whenever the Pi closes the circuit, the lamp is powered on.

I am aware that there are risks implied when tampering with the "mains" voltage. With that being said, I would like to ask the following questions:

  1. Will it be dangerous to do this with the hardware listed above? Please know that I would place the relay on a surface that does not conduct electricity (potentially wood), and the though of touching any hardware (not even the PI) while the lamp is connected WOULD NOT EVEN POP IN MY HEAD.

  2. I am aware that the relay may fail since I've read in some forums that this is supposedly a 5V relay (maybe not?). If it were to fail, would it be dangerous? As in, would my whole house be in a blackout or something like that? Any advice for that?

3.If you were to consider this safe, would it make a difference if I cut/tamper with the wire before or after the manual switch my lamp has? (please refer to the switch image above).

  1. How would I be able to identify which wire is positive and which negative if I cut open my lamp's cable?

  2. Would it make a difference to connect the lamp to the black extension cord (please refer to the picture above) rather than directly to the mains outlet?

I am still debating whether to give this a try or not due to security reasons. I am aware of how dangerous tampering with house-level voltage (especially current) is, therefore I need your help to better analyze the situation.

Thank you so much for your help!

QUICK EDIT:

FYI, I currently live in America, therefore I am assuming my mains V supply is 120V…

Best Answer

Here is a good way to do this project without getting yourself messed up with playing with live mains wiring.

  1. Acquire one of the many AC remote controlled outlet devices such as that pictured below. There are plenty of choices available for low prices on eBay or Amazon. Can be lower than price of the Raspberry Pi.

enter image description here

  1. Plug the AC unit into your mains outlet and then plug your unmodified lamp into the front of the AC unit.

  2. The wireless remote FOB contains a battery operated transmitter circuit that can be hacked to let the RasPi trigger the lamp on and off. The nature of the hack interface will be a far better learning experience for you than risking life and limb screwing around with your own relay controlled AC wiring.

  3. The simplest hack for the FOB will be to simply bring two small wires out of the FOB that connect to the active contacts of the push button and wire those over to your relay module. Everything is low voltage and safe.

Note that these low cost remote control units may not be of the highest quality but their usage will still be safer than what you have proposed in your posting.