How can I implement mathematical formulas in Arduino?

I´m making a project with rc car, in that project using sensors i need to obtain some variables, for example with the current sensor " Acs712", I obtain so to speak the power of the rc car, and the value obtained I replaced it on this formula Fengine=P/V where "Fengine", I calculate the force that the engine produces, "P" power obtained with senesor and "V" velocity of the car, how can i get the result using sensor and formulas in an Arduino code?

I am not sure what you asked about, but the basic mathematical expressions would be written in the code almost as simple as on the paper:

Fengine= P / V;

You can connect a rotary encoder to your motor and measure engine RPM. From that you can compute speed.
Or you could connect the encoder directly to a wheel to obtain the speed.

perhaps it's not clear which equations

since you have a eletrical current sensor, P is power presumably in Watts, W, when the current, I, is multipled by the Voltage, V.

but power doesn't directly translate into speed (velocity is speed and direction). power can be translated in to horsepower, HP and into force, F (lbF) which ironically depends on the speed (horsepower is proportional to lbF / (ft/sec).

when you apply Newtons Laws, that force detemines the acceleration, A = Mass / Force = ft/sec/sec, and the acceleration can be integrated to determine the resulting speed, ft/sec.

@lem_arduino welcome to the forum!

Is this just for fun, or do you need the calculated value to actually be correct?

There are some problems with your equation, if your goal is to determine the "force that the engine produces".

First, as already noted by @gcjr, the power (P) is not equal to the motor current (I). You also need a measurement of the motor voltage (Vm), after which you can compute the electrical power supplied to the motor as

P = Vm×I

Second, not all of this power goes to propelling the car. Some power (I2R) is dissipated in the resistance (R) of the motor windings, so the net power used for propulsion will be

Pnet = Vm×II2×R

Third, the motor ("engine") does not produce force (F), it produces torque (T). The mechanical power produced by the motor is

Pm = T×ω

where ω is the angular velocity of the motor shaft. If you know the gear ratio (G) and the wheel radius (r), then the angular velocity of the motor can be determined from the speed of the car (V):

ω = G×V/r

Solving for the motor torque after setting Pnet = Pm gives

T = [(Vm×II2×Rr] / (G×V)

If you really need to know the force that is propelling the car, then you would also need information about frictional losses in the motor and drivetrain before the force can be estimated.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.