How to measure power in PID controlled circuit

There is delay of 500 msec in the code.