Calculate the total electricity consumption of a project

I'have questions.
How to calculate the power consumption of several components?
And how to force a component to have as consumption 5v and not 12v ?
thank you in advance

Read the datasheet, and normally you cant.

Components in Arduino projects rarely have a constant current consumption, it varies depending on what exactly the Arduino and each of its components are doing.

And how to force a component to have as consumption 5v and not 12v ?

I have no idea what you mean by that.

"How to calculate the power consumption of several components?" Measure the voltage and current, then multiply them. I am not sure this is what your question really is.
"And how to force a component to have as consumption 5v and not 12v ?" This question is unclear to me, probaly others too.

Volts are not a measure of consumption. They are a measure of "electrical pressure".

Amps measure the amount of current flow (usually) resulting from the electrical pressure applied to a circuit.

Ohms measure the resistance of a circuit to the flow of current.

Watts measure the power dissipated by the resistances in a circuit, and are calculated by multiplying the electrical pressure (V) across the component(s) of interest, by the current (A) flowing in them.

From your question, it isn't clear what you are asking. Most electronic modules (circuit boards, integrated circuits, etc) need a particular voltage (or voltage range) to operate properly. Are you asking how to run a circuit that requires 5V off a 12V supply?

For each supply voltage used sum up the currents taken by each component on that supply and multiply by the voltage to get the power. Current is generally fairly easy to measure if the datasheet isn't helpful. You can just measure the total current on the supply directly without having to sum up anything

Total the power consumptions for each supply rail for the total power.

Power is measured in watts (W), the voltage is not relevant once you'd done the power calculation.

Perhaps you are asking about when a 5V supply is derived from a 12V supply or vice versa? The former can be done with a linear regulator, both can be done with a switch-mode regulator (buck or boost, specifically).

Linear regulators waste power as heat, so for instance if you have 5V 1A component powered by a 5V linear regulator supplied from 12V, the regulator dissipates 7W as heat (7 volts across it times the 1A through it).

Switchmode regulators are more efficient, perhaps 90% or so, so 5V 1A load on a switchmode regulator run from 12V would dissipate perhaps 0.5W, taking 5.5W from the 12V, which is 0.46A (less than its load). 5W is passed to the 5V load, 0.5W ends up as heat in the switchmode regulator.

Its not a bad plan to derive multiple voltage rails from each other like this as it means everything powers up together, and you only need one (bulky/costly) mains supply for the project.

When sizing power supplies don't skimp - if the circuit needs 10W, a 10W supply is a very bad choice (its running at its absolute limit). Go for 15W or better rated supply so it has some headroom and will run cooler.

For 5V or 12V, this is for a compenents, a switch/led. In his datashit explain that 5V or 12V
in next the link of the switch :switch link