Miscarriage and sex

How long after a miscarriage can you have sex ? Might seem heartless but can you start once all the blood is gone or till your ob says so.