Hi all,
I'm a total beginner in electronics (self-taught), so any advice is really appreciated!
I’ve put together this circuit to sense mains voltage using an IO Expander, which I’ll connect via I2C to an ESP32.
Based on the MCP23018 datasheet:
Here’s what I understand:
A low signal should be less than 0.2 * Vdd = 0.2 * 3.3V =
0.66VA high signal should be more than 0.8 * Vdd = 0.8 * 3.3V =
2.64VFrom the mains side, I'm expecting:
Current: If = V/R ≈ 300V/300kΩ ≈ 1mA
According to the LDA210 datasheet:
I expect the voltage drop across the optocoupler to be less than 0.6V, meaning Vce should be around 2.7V.
I’ve built the circuit, and it’s working! The MCP detects a '1' when mains are present and '0' otherwise.
These are the readings from my oscilloscope
Avg: 2.72vBase: 2.68vMin: 2.41vIt takes about 200ms to switch from high to low, which is fine for my use case.
Now the questions:
1) Even though it seems to works on the bench, I feel I am too close to the lower limits of the MCP. Is there a better way of doing this?
I considered high-side switching, but I think I’d run into the same issues.
2) My test setup is a small workbench, sensing a 20cm wire. I am wondering what would happen if I use much longer floating wires (like in a normal house installation).
Will the optocoupler “pull down” to earth? Should I lower the resistance to increase the 1mA current reading? (My guess is that this wouldn't really help)
3) Is the ripple I’m getting normal for a household circuits? Or I should increase the capacitance? (Not a problem if discharging the capacitor takes too long)
Extra links:
Full Schematics:
https://github.com/crgarcia12/electronics-homeassistant-lightscontroll/blob/main/PCB/schematics-v23.8/readme-media/board-schematics.svgLDA210 datasheet:
https://www.mouser.ch/datasheet/2/240/media-3322391.pdfMCP23018 datasheet:
https://ww1.microchip.com/downloads/en/DeviceDoc/22103a.pdfThanks a lot for taking the time to read this long post