0
votes

This is a general question, I believe it maybe a math question but it is for the Arduino platform.

I'm doing a ball levitation project that will keep a ping pong ball suspeneded at a setpoint in a tube, the balls position is read with a laser position sensor that gives an analog voltage related to the balls position. The sensor output is pretty linear for the operating range of the tube's length.

Then I have a fan controlled with PWM as a %, this is manually adjusted with a pot, and I marked a scale on the tube in one inch increments.

Basically I made a table of sensor voltage output values, related to PWM% values of the motor for different positions in the tube.

I made a graph relating the two variables and it is surprisingly pretty linear. I did a trendline in excel and got a line equation of Y = 3.0265X + 15.05

X is the sensor position(in volts) and Y is the PWM value in %,

The part I'm having trouble with is taking the analog voltage from the analog pin that is a value of 0 to 1023 in the arduino and relating it to a PWM to analogWrite to the motor (A value from 0 to 255).

I know the analogRead() is and ADC so do I convert the 0 to 1023 value to a voltage by (5.0 * analogvalue)/ 1023;

That will give me volts, but I dont understand how how to relate this to PWM, like a change in sensor voltage to a change in PWM to the motor. I think I'm on the right track but not connecting the dots together.

Any help will be appreciated!

Thanks

1

1 Answers

2
votes

Generally speaking, the PWM percentage is directly related to the voltage of the supply voltage. That is, if you have a 5 volt Arduino, and the PWM percentage is 75%, the output should be 3.75 volts, provided you have a output circuit that is able to "filter" out the individual pulses.

Keep in mind that the PWM values are in the range 0 to 255, so you'll need to divide the desired "analogRead()" value, which is in the range 0 to 1023, by a factor of four to produce the correct output voltage using PWM.