the pill

if you take the pill on time everyday how long does it take for it to work against pregnancy ? i have been on it for 3 weeks and i'm about to start the end of the pills (week 4) tomorrow . do they work right away ? i have had unprotected sex a few times since i got on it .