Automation of insulin infusion by closed loop control method is the center of attention for many researchers for the last few decades. The main idea behind the insulin automation is artificial pancreas for the accurate measurements of glucose level so the key role is played by the control strategy used to design control algorithm. This paper proposes a Proportional Integral Derivative (PID) algorithm based on switching technique to control and maintain the glucose level. We have used mathematical models like Havorka model and Meal Simulation model to deal with the dynamics of insulin and glucagon. Simulation results show that the PID control algorithm performs well in many situations such as insulin sensitivity. To check the effectiveness of the control scheme the glucose profile of patient is generated by using MATLAB. The presented control techniques found to be better as compared to traditional method of insulin injection and are helpful in reducing the risks of hypoglycemia.