The valves open and close in response to pressure changes in the heart chambers. When the ventricles contract (systole), the AV valves close to prevent backflow, and the semilunar valves open to allow blood to be pumped out. When the ventricles relax (diastole), the semilunar valves close to prevent backflow, and the AV valves open to allow the chambers to fill with blood.