Motor and sensor

Swaggydogy:
but does you're code:

boolean motorMoving = false;

No. It just creates a variable and gives it the value false. This is the computer equivalent of taking a sheet of paper out of a packet and writing the name "motorMoving" in the top left corner and writing the word "false" in the middle.

The line

analogWrite(motorPin, pwmValue);

is what causes the motor to move.

I had assumed you knew enough about your own program to infer all that.

It seems that you need to take some time out to learn the basics of programming. There are lots of tutorials on the web and you should also study several of the examples that come with the Arduino IDE.

...R