We have to see Descartes on physiology and psychology.
The main references are :
From L'Homme :
Part I : On the machine of the body
These men will be composed, as we are, of a soul and a body. And I must describe for you first the body on its own; and then the soul, again on its own; and finally I must show you how these two natures would have to be joined and united so as to constitute men resembling us.
Next, in order to understand how the external objects that strike the sense organs can instigate the machine to move its members in a thousand different ways, note that the tiny fibres (which, as I have already told you, come from the innermost part of its brain and make up the marrow of the nerves) are arranged in every part serving as the organ of
some sense in such a way that they are easily moved by the objects of that sense.
Now I hold that when God unites a rational soul to this machine, as I intend to explain later on, He will place its principal seat in the brain and will make its nature such that the soul will have different sensations depending on the different ways in which the nerves open the entrances to the pores in the internal surface of the brain.
Part 5 : On the structure of the brain of this machine, and how the spirits are distributed there so as to cause its movements and its sensations
Here the disussion is centered around the role of The Pineal Gland.