easy programming help

Good Morning 8)

I am trying to create a program that takes an input from a throttle position sensor and runs it thru an equation and then outputs a new voltage. Below is my programming code and it is working but not giving me the correct values. Does anyone know where my error is? For example if the TPS is sending 1.19v to the arduino pin 3 then I expect the output pin 3 to be 4.5v.

int pwmPin = 3; // output pin supporting PWM int inPin = 3; // voltage connected to analog pin 3, e.g. a potentiometer int val = 0; // variable to store the read value float voltoutput = 1; float volt = 4; // variable to hold the voltage read float voltfinal = 5;

void setup() { pinMode(pwmPin, OUTPUT); // sets the pin as output } void loop() { val = analogRead(inPin); // read the input pin float volt =(5.0 * val) / 1023; float voltoutput = (5 - ((1.461 * volt) - 1.23859)); float voltfinal = 255 * (voltoutput / 5);

analogWrite(pwmPin, voltfinal); }

I may have misunderstood your intention with this project but if you are trying to vary the output voltage then a PWM pin will not do that. PWM pins will, for example, fade an LED which gives the appearance that the voltage is rising or falling but it is in fact a steady voltage that is being pulsed off and on for longer or shorter periods

For example if the TPS is sending 1.19v to the arduino pin 3 then I expect the output pin 3 to be 4.5v.

Instead, it's? How are you measuring it?

Yes I was hoping that I could send a pwm signal to the receiving computer but planned to add a RC filter of that didn’t work.

Paul
I was getting a value of 2.xx volts on the output measured with a multimeter.

I was getting a value of 2.xx volts on the output measured with a multimeter.

Wrong device. You need an oscilloscope to measure the PWM output.