Electronic – Use a Transformer to feed a Mains current to a RPI GPIO pin

current-limitinginputmainsraspberry pitransformer

I have a standard mains (240v) motion detector that activates an outdoors lamp. I want to notify my Raspberry Pi when the lamp is activated.

My plan is to use a 240v to 3.3v transformer that I have already purchased. I intend to wire the transformer in parallel to the feed wire of the lamp so that when the lamp is activated, so too is the transformer and thus the GPIO pin can get its 3.3v activation signal. The transformer output is specified at 3.3V dc 1A 3W (Hi-Link HLK-PM03). I read that you should never source or sink more than 0.5 mA into an input pin.

Is it safe for me to connect this transformer directly to the GPIO pin or do I need to add a resistor or do something to limit the power from the transformer?

Best Answer

Hi-Link HLK-PM03 as mains voltage detector into R'Pi

This will be a very effective solution and much cheaper than a 230/240VAC relay.

One small point, the Hi-Link HLK-PM03 is a small SMPS power supply ….not a transformer (and even though it will contain a small ferrite transformer).

I'd suggest that you do need to provide a resistive and clamp network on the output of the power supply:

  1. To provide a minimum load on the power supply when active
  2. To provide a quicker drop in the output voltage when turned off
  3. To ensure that the R'Pi input is protected

A Circuit such as this would be effective:

schematic

simulate this circuit – Schematic created using CircuitLab

This provides a minimum load on the power supply of about 55mA, and sets the input voltage to the GPIO pin to about 2.75V.