Electrical – Optocouplers vs Voltage Dividers

#nodemcugroundopto-isolatorvoltage divider

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.

Best Answer

  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.