I just had unprotected sex can I take a test in two days or I have to wait longer?

Unprotected sex. Usually you have to wait till you miss a period. When fertilized it takes 5 days for the fertilized ovum to go to the uterus and only then it starts implanting. Once implanted is when HCG level is detected in the maternal blood. So its about 7-10 days after fertilization.
Wait. Tests may be positive as early as a week after unprotected sex, but the most reliable time is one week after a missed period. If you are trying to become pregnant or having unprotected sex please start on a prenatal vitamin with folate (folic acid) immediately to prevent birth defects.