Thursday, 18 October 2018

switches - Connecting a Raspberry Pi to a 220V switch


I have a switch that works at 220-230V AC and I'd like to link it to my Raspberry Pi and I want to know what I have to do from an electrical point of view.


So my switch, when switched on, places 220V AC on a wire, which somehow I'd like to transform it to 3.3V DC so I can react from software when the switch is on.


I should mention that the switch may stay switched on or off an indeterminate period of time (which of course I will handle in software) and I wouldn't like to damage my raspberry.



How do I do this? Is a transformer the solution here?



Answer



You can use an opto-isolator to convert your 220V to a 3.3V logic system. You can use this circuit for the same:


220V Logic to 3.3V Logic


When you turn on the switch, the optocoupler will get some of the current from it (1-2 mA). This will turn on the transistor and you will detect a HIGH logic with your raspberry pi. Also, your ac input will be sinusoidal so the DC side output will be sinusoidal as well. To take care of this, a capacitor has been used which will ensure a continuous HIGH logic till the ac switch is turned ON.


Once you turn the ac switch OFF, the capacitor will discharge through the 390K resistor and you will get a logic LOW. There will be a delay of approx 100-200 milliseconds though, between switch getting turned OFF and your raspberry Pi detecting LOW because capacitor will take a while to discharge.


Besides being low cost, this circuit also gives you the added benefit of optical isolation. Even if something goes wrong on ac side, your raspberry pi is safe.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...