I want to use an optocoupler to detect mains (230V) voltage.

Which optocouplers do I have (salvaged from old PC PSU's probably):

Found circuits

schematic

Source: AC Optocoupler for 230V line detection

AC line Detection Schematics and Circuit

Source: [230v/110v AC Mains Detection Module Hookup Guide](230v/110v AC Mains Detection Module Hookup Guide)

schematic detecting mains voltage

Source: How to detect mains voltage with a microcontroller?

Experiment

image-20230929180130007

I feel like I don't have enough knowledge to decide what's good. I will experiment with the above very cautiously. For the diodes I suppose the 1N4007 are necessary for a high voltage.

First I try this with an AC-AC adapter.

image-20230930113534545

In the above picture my scope's ground was unconnected. In the picture below here it was.

DS1Z_QuickPrint2

How about a capacitor to smooth out those valleys?

Anyway, I feel ready to test safely with mains voltage. This is what I did first, and made a stupid beginners mistake:

image-20230930121916108

A small bang and a flipped fuse-switch. Obviously I cannot just connect my scope's ground to the circuit as it is directly connected to mains ground.

I can just not use the scope ground, like this (the circuit has to have a ground to simulate though):

image-20230930122204587

The simulated output:

image-20230930122240348

Which looks pretty close to the output on the scope:

image-20230930122316026

Next step: A circuit that detects when the optocoupler gives a signal, then turns on a LED.