Sex related

Yasmina
Hi just wanted to know while pregnant is it safe to have sex and can that cause to miscarriage or hard to find heart beat on scan?? 
Has i been for scan and they couldnt find no heart beat so need to go agen for rescan but as far as i know i aint hurt myself or nothing but me and my partner do have intercourse now and then please help as its my first tome being pregnant