Need a circuit to convert 230V sine wave into 5V square wave
The other technique would be to use an optoisolator (with appropriate isolation barrier ratings) along with some current limiting resistor(s).  For a nominal LED drive of 10-20mA drive you'd need about 24k-12k.  Overall dissipation is about 2.2W-4.5W, which would get warm, but you can either get a power resistor, or share the load with multiple series/parallel combination resistors (make sure they can take the 230VAC range).  Several things to watch for in terms of safety.  Flameproof resistors are recommended, put a diode across the optoisolator LED terminals but anode to cathode, to prevent the LED from seeing too much of a reverse bias voltage on the other half of the AC waveform (improves reliability). MOV and PTC is nice to have for incoming transients and faults.  Verify that the layout physically isolates the AC from the low voltage DC portion (creepage, etc.)  You want to make sure that any fault will not cross over to the low voltage side.