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:
- How would this circuit change if I wanted to detect 12v instead? Is it just a matter of switching R2 for a higher value?
- 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.