Reading PWM in and converting to DC output

An example of what I'm trying to do:

Arduino 1, pin 3(pwm) : PWM varying output from 0 to 255 Arduino 2, pin A0 : reading Arduino 1 pin 3's output Arduino 2, pin 2(pwm) : puts out voltage proportional to the value read on pin A0

My problem is Arduino 2 is only reading a series of 0(low) and 1023(high) that varies in frequency with arduino 1's output. I want it to read a 50% duty cycle as 2.5 volts, not high half the time and low the other half.

Any suggestions on how to do this? Am I going to have to write a code that converts the length of time high using pulseIn to a corresponding voltage out?

MicroUser:
An example of what I’m trying to do:

Arduino 1, pin 3(pwm) : PWM varying output from 0 to 255
Arduino 2, pin A0 : reading Arduino 1 pin 3’s output
Arduino 2, pin 2(pwm) : puts out voltage proportional to the value read on pin A0

My problem is Arduino 2 is only reading a series of 0(low) and 1023(high) that varies in frequency with arduino 1’s output. I want it to read a 50% duty cycle as 2.5 volts, not high half the time and low the other half.

Any suggestions on how to do this? Am I going to have to write a code that converts the length of time high using pulseIn to a corresponding voltage out?

Yes, you need to convert the on/off digital output signal the PWM writes to a true analog voltage able to be read correctly by a arduino analog input pin. This can be done by using a simple low pass filter comprised of a resistor and a capacitor. I think I use to use a 5k ohm resistor and a 10ufd cap, but the values aren’t too critical. Just wire one end of the resistor to the pwm output pin, other end of resistor to the positive end of the cap and the negative end of cap to ground. Then wire from the analog input pin to the junction of the resistor/capacitor network.

Keep in mind that the analog read will return a 10 bit value of the 8 bit value you use in the PWM output command, so you will need to divide the analog input value by 4 before using it as the value to send out on a different analogWrite() pwm pin.

Lefty

retrolefty:

MicroUser: An example of what I'm trying to do:

Arduino 1, pin 3(pwm) : PWM varying output from 0 to 255 Arduino 2, pin A0 : reading Arduino 1 pin 3's output Arduino 2, pin 2(pwm) : puts out voltage proportional to the value read on pin A0

My problem is Arduino 2 is only reading a series of 0(low) and 1023(high) that varies in frequency with arduino 1's output. I want it to read a 50% duty cycle as 2.5 volts, not high half the time and low the other half.

Any suggestions on how to do this? Am I going to have to write a code that converts the length of time high using pulseIn to a corresponding voltage out?

Yes, you need to convert the on/off digital output signal the PWM writes to a true analog voltage able to be read correctly by a arduino analog input pin. This can be done by using a simple low pass filter comprised of a resistor and a capacitor. I think I use to use a 5k ohm resistor and a 10ufd cap, but the values aren't too critical. Just wire one end of the resistor to the pwm output pin, other end of resistor to the positive end of the cap and the negative end of cap to ground. Then wire from the analog input pin to the junction of the resistor/capacitor network.

Keep in mind that the analog read will return a 10 bit value of the 8 bit value you use in the PWM output command, so you will need to divide the analog input value by 4 before using it as the value to send out on a different analogWrite() pwm pin.

Lefty

Thanks, thats a fairly simple and effective method!

This is sort of in the same vein as the posts above, so hoping someone can help. I think I am almost there, just a bit confused about anologRead/Write
What I am trying to do. Use a variable capacitor to measure fuel depth, with a reference capacitor (for temperature stability) outputting to an Arduino Pro Mini.
From this Pro Mini I want to output a 0-5v signal proportional to the fuel level to be input to another remote Pro Mini to be used to display a bar on an LCD.
Why 2 Pro Minis?, because I need to keep the leads, both shielded and short from the variable capacitor/fuel sensor to the 1st Pro Mini to avoid interference and
I have another Pro Mini driving an LCD and receiving other sensor inputs remote from the fuel tank.I am assuming the proportional voltage output will not be subject
to the same interference.
I am OK with the CapacitiveSensor part of the sketch, having that running fine. Also the display part on the 2nd Pro Mini.
All based on http://www.instructables.com/id/Building-a-Capacitive-Liquid-Sensor
The bit I am not sure of is getting the “fuel” value turned into a voltage to send to the second Pro Mini.I have attempted to write that part of the sketch, but am confused
with analog read and write. I do know that the PWM output must be run through a low pass RC filter of something like 5koms and 10uF

Sketch below

#include <CapacitiveSensor.h>
CapacitiveSensor cs_5_6 = CapacitiveSensor(5,6);// variable capacitor made of two concentric aluminium tubes. Centre connected to 6 with 1Mohm connected between 5&6, outer to ground.
CapacitiveSensor cs_7_8= CapacitiveSensor(7,8);// Reference capacitor equal to variable cap on empty.Connected to 7 with 1Mohm connected between 7&8, other to ground.

int val=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{ long fuel;
long Ref;
fuel = cs_5_6. capacitiveSensorRaw (200);
Ref = cs_7_8. capacitiveSensorRaw (200);
fuel = fuel-Ref-200;
//Adjust 200 in line above to read fuel as 0 for tank on empty, then uncomment line below

//fuel = fuel / 44;
//Adjust 44 in line above to give fuel = 255 or 1023 with tank full, not sure which???

//THIS NEXT BIT IS THE BIT I HAVENT QUITE GOT YET.

analogWrite(3,fuel); // write the resulting value of fuel to digital pin 3 or analog pin 3??
delay (50);
val=analogRead(3); //Read the value of pin 3 and assign as val
delay (50);
analogWrite(2,val/4);//Send val to pin 2 to use as a voltage varying between 0 at empty and 5 volts to be read as an input to another Arduino.
//This output to be run through a low pass RC filter, using 5kohm and 10uF.

{
Serial.print(fuel);
Serial.println(“Fuel”);//debug fuel
}

delay (100);
}