Why is my voltage less when using this code

You'll have to post your electrical schematic. Code seems fine.