# Read pwm pin voltage and show in lcd

Hello everyone

I am trying to read the voltage in a pwm pin as I see in my multimeter I would like to show this value in an lcd but I can not, I tried through calculations but the values ​​are not accurate.

The value will be close to Vcc or close to zero.

rrsilver:
Hello everyone

I am trying to read the voltage in a pwm pin as I see in my multimeter I would like to show this value in an lcd but I can not, I tried through calculations but the values are not accurate.

The voltage on a PWM pin switches rapidly back and forth from 0 to 5V. While your meter may be low enough frequency to wash that out and make it look like a constant voltage, it isn't a constant voltage. You won't be able to measure it with analogRead if that's what you're after. You will have to filter it first through a low pass filter to remove the square wave.

Helo Delta_g

Can you help me with this circuit?

I am trying to read the voltage in a pwm pin

Do you mean a PWM output or an analogue input pin ?

Can you please give an example of the pin number that you are using and the board type ?

(deleted)

rrsilver:
I am trying to read the voltage in a pwm pin

Why ? You can calculate it easily.

Suppose you use analogWrite(pin, 63); then the average voltage will be 5 * 63 / 255 = 1.235

...R

UKHeliBob:
Do you mean a PWM output or an analogue input pin ?

used pin 8

Can you please give an example of the pin number that you are using and the board type ?

arduino mega

this value in the multimeter is the current value of pin 8 I just wanted to show on an equal lcd is in the multimeter, I tried to understand the low pass filter but I am not understanding the results I found in google.

rrsilver:
I am trying to read the voltage in a pwm pin as I see in my multimeter
I would like to show this value in an lcd but I can not,
I tried through calculations but the values are not accurate.

We did't see your calculation, but the right calculation is given in post#6.

AnalogWrite is not generating a voltage, but a square wave signal (0volt, 5volt), with varying on/off time.

Your multimeter will average that 5volt PWM signal, but it might not do that very accurately.

Tell us why you need a 'voltage'.
Leo..

The question you really haven't answered yet is this:

DO you want to just display the calculated value of that pin?

You weren't very clear about that and you've got answers going both ways. You need to be specific. If you just want to display the calculated value then you don't need any filter. If you want to measure it with an analog pin then you do.

the value will be handled by a person but only once it will be configured and shown in real time on an lcd after that it will be retained, I made a calculation but it is not accurate and shows only rounded values

I have this code but it's not accurate

``````double Vcc = 5.0; // not necessarily true
double volt = (final_voltsO2 / 255.0) * Vcc; // only correct if Vcc = 5.0 volts
Serial.println(volt);
``````

Wawa:
We did't see your calculation, but the right calculation is given in post#6.

AnalogWrite is not generating a voltage, but a square wave signal (0volt, 5volt), with varying on/off time.

Your multimeter will average that 5volt PWM signal, but it might not do that very accurately.

Tell us why you need a 'voltage'.
Leo..

I need to fool an automotive sensor but I must give this freedom to change the voltage to the user and he can see it on an lcd to know what he is doing.

Robin2:
Why ? You can calculate it easily.

Suppose you use analogWrite(pin, 63); then the average voltage will be 5 * 63 / 255 = 1.235

...R

I am using this code but it is not accurate and brings rounded results by ignoring the decimal places.

rrsilver:
I am using this code but it is not accurate and brings rounded results by ignoring the decimal places.

You're probably calculating it with integer math. Post your line of code and it can probably be fixed.

my code

``````analogWrite(8, 102); // OBS: 102 value is the int var final_voltsO2
double Vcc = 5.0; // not necessarily true
double volt = (final_voltsO2 / 255.0) * Vcc; // only correct if Vcc = 5.0 volts
Serial.println(volt);
``````

serial result is 2.00 volt in my multimeter now the value is 1.83 volts

rrsilver:
serial result is 2.00 volt in my multimeter now the value is 1.83 volts

Have you checked your reference voltage? Is it EXACTLY 5.0 volts? If not you need to use the actual value and not 5.0

Depending on the board you have there may be 1 or 2 internal voltage references. The 1.1V reference is usually pretty good and stable and accurate.

You also need to understand that your multimeter is not going to measure a PWM signal like it would a steady voltage. Right now your voltage is flickering back and forth from 0 to 5V really fast. IF your multimeter does anything other than flicker back and forth between 0 and 5V so fast you can't see it then the multimeter is lying to you. You are NOT creating 1.83 OR 2.00 volts. Only 0 and 5 volts.

`````` final_voltsO2 = map(vlr_eprom_lambda, 0, 5, 0, 255);
``````

this variable is used for the map value when user change values in lcd control

rrsilver:
I am using this code but it is not accurate and brings rounded results by ignoring the decimal places.

Simply change the int assignment to a float, then do 100*(5*60)/255 analogWrite(pin, 60);
Then when looking at the lcd screen the move the decimal place 2 places back or edit when printing the final str to the LCD.

rrsilver:

`````` final_voltsO2 = map(vlr_eprom_lambda, 0, 5, 0, 255);
``````

map() only works with integers.
That line only outputs five voltage levels (steps of one volt).
Leo..