0
\$\begingroup\$

I have a device that has a terminal that goes to 5v at certain times. I wish to sense that voltage with an ESP32. I have built this circuit using an optocoupler:

schematic

simulate this circuit – Schematic created using CircuitLab

  1. How would this circuit change if I wanted to detect 12v instead? Is it just a matter of switching R2 for a higher value?
  2. I see that voltage dividers can also be used for the same job, but I think that would only work in cases where the sensor and MCU share a common ground. How can I achieve that in this case (if at all I can/should)?

EDIT: As requested, some details of the system.

The MCU is running off 5vdc converted from 8vac provided by a bell transformer connected to the mains (it is already sensing the doorbell using optos).

The device is an alarm panel, that has various terminals to attach motion sensors (that go to 5v) as well as provide signals that the alarm is set or has been triggered (these terminals go to 12v). The panel is connected directly to the mains, but I can see it has a built in transformer, as well as terminals providing ground and 13v.

\$\endgroup\$
  • \$\begingroup\$ 1) If you just want to detect that the 12 V is there or not: yes, increase R2 so that the current through the LED doesn't become to high. 2) Yes a resistor based voltage divider only works when there is one ground. \$\endgroup\$ – Bimpelrekkie Aug 7 at 13:56
3
\$\begingroup\$
  1. Yes, increase the value of R2.

  2. You can't use a simple voltage divider if you don't have a common ground. If you are asking how to "achieve" a common ground, you will need to tell us much more about your system.

\$\endgroup\$
  • \$\begingroup\$ Thank you for the direct answer. I'd be interested in the common ground for academic reasons but practically it sounds like I'll stick to the optos. I'll update the post to give more detail. \$\endgroup\$ – Spammy Aug 7 at 13:58
1
\$\begingroup\$

The optocoupler will have a spec over forward current, the recommended current through the photo diode when it is active. You need to adapt the resistor accordingly. It's just Ohm's Law from there, so if the spec says IF=20mA and you have 12V, you need a 600R resistor.

The whole point of the optocoupler is to isolate the systems. If you don't need to do that, a voltage divider is simpler and cheaper.

\$\endgroup\$
0
\$\begingroup\$
  1. How would this circuit change if I wanted to detect 12 V instead? Is it just a matter of switching R2 for a higher value?

Yes. You should familiarise yourself with some of the details of operation and use. I've written about it here.

  1. I see that voltage dividers can also be used for the same job, but I think that would only work in cases where the sensor and MCU share a common ground. How can I achieve that in this case (if at all I can/should)?

You are correct that a common ground is required. You need to determine why the systems are isolated at the moment and what would be compromised if you connect the grounds.


From the comments:

... but this topic is interesting to me because the opto circuit seems much easier to reason about even when monitoring a DC circuit, so I was wondering what the value of the voltage divider method was.

Optos better than resistor divider

  • Complete isolation up to thousands of volts.
  • Very simple.
  • Cheaper than transformer isolation solution.

Resistor divider better than opto

  • Simpler and cheaper.
  • Faster. Optos have a limited frequency response. (See the linked article.)
\$\endgroup\$
  • \$\begingroup\$ Thank you for the link, it's very helpful. I have already used optos in existing projects (the doorbell) where the monitored circuit was AC so have a level of understanding on how they work, but this topic is interesting to me because the opto circuit seems much easier to reason about even when monitoring a DC circuit, so I was wondering what the value of the voltage divider method was. \$\endgroup\$ – Spammy Aug 7 at 14:07
  • \$\begingroup\$ See the update. \$\endgroup\$ – Transistor Aug 7 at 14:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.