Merging 3 sketches NOOB ALERT!

Replace val with

byte micVal =0;
byte pirVal =0;
byte tempVal =0;

and adjust the placed where val gets used to use the appropriate variable.