How to hardwire different voltages to a rasberrypi

Common voltages could be:
120vac, 220vac, 24vdc, 12vdc

^^ so how could I connect this voltage safely to a rasberrypi to use the I/Os to run Node-RED?

Apparently there are some devices with names like:
Solid State Relay
Optoisolator
Converter module
and who knows what else..

But what would be better to use? and where can I get those items?

What are you trying to do?
Are you trying to detect/monitor the mains voltage value?
Are you trying to detect a current load?

First of all - mains voltages are extremely dangerous and can KILL you.

I would NOT attempt to connect any mains wiring anywhere near a Raspberry Pi as you immediately expose the mains connections unless you adequately shield them. You might know where those connections are located but someone else (another adult or a child) may not and could touch them with terrible consequences.

There are devices that will detect mains voltage, current load, phase angle, etc.. and report these values to Node-RED via MQTT. If you answer the above questions I may be able to advise.

I am trying to monitor on/off state of a solenoid.

Solenoids may work with different types of voltages.

I did watch a youtube video of a LED light connected using a resistor, but that was a rough example of how it works.... I assume there are better ways to do it.

You really should take note of Dave's warnings. Mains electricity can and does kill. Both directly and indirectly (e.g. fires).

A solenoid may have a low and a high voltage side. Typically, the low-voltage side would do the switching of the high voltage.

But there are a vast number of different solenoid types and voltages and you really need to know what you are doing.

A solenoid switchable by a 3.3v or 5v circuit could feasibly have a Pi connected into that circuit to detect its state. But even then, it is very easy to kill the Pi as its GPIO pins have no protection on them.

There are also non-contact current monitors that can detect when current is flowing through a mains circuit. That would be a lot safer if you are not used to dealing with mains voltages.

You won't run the solenoid at 3.3v... you would use something in parallel to step it down to 3.3v to feed it to the I/O.

There seem to be many options to explore, but not sure what would be most common / reliable / less expensive.

^^^ This is the hardwire option... I assume there would be something to convert the regular voltage signal into MQTT as well, but likely more expensive.

What would be cleaner? cost effective? safer? ... lots of variables yet to explore.

Like I was saying, there are LOTS of variables:

There are MANY options for mains switching using Wi-Fi and/or MQTT (or Zigbee or Z-Wave and MQTT). Look at the Shelly or SONOFF for examples.

These would be far safer and easier. Shelly in particular, I have multiple devices from them including an RGBW LED strip controller and some UK mains plugs. Each of them is controllable via MQTT over Wi-Fi with no hardware or software hacking.

2 Likes