Regarding my program, it is a program that does some calculations and then outputs a voltage based on the result using analogWrite function. However my problem is that I had done my programming based on a misconception that analogWrite function via PWM does output an analog voltage, where in fact it only "simulates" the analog voltage instead.
Here are the relevant parts of my code :
int pwmOutput = 11;
int pwm = 0;
void compareNewOldVoltageYes(void)
{
if(pv_Vnew > pv_Vold && pwm != 255)
{
++pwm; //increasing value
}
else if(pwm != 0)
{
--pwm; //decreasing
}
}
void compareNewOldVoltageNo(void)
{
if(pv_Vnew > pv_Vold && pwm != 0)
{
--pwm;
}
else if(pwm != 255)
{
++pwm;
}
}
void loop()
{
reading();
PowerCalculation();
if(pv_NewP > pv_OldP)
{
compareNewOldVoltageYes();
}
else
{
compareNewOldVoltageNo();
}
analogWrite(pwmOutput, pwm); //analogWrite
float displayPWMvolt = pwm * 0.0196;
Serial.print("Output Voltage: ");
Serial.print(displayPWMvolt);
Serial.println(" V");
pv_OldP = pv_NewP;
Serial.print("Previous Power: ");
Serial.print(pv_OldP);
Serial.println(" W");
}
As for the circuitry, output pin 11 is being connected to a 1 ohm resistor and then to GND. (Where I measured the voltage) I am using Arduino Uno board.
UPDATE:
As said in the comments by @DatHa, pwm does not output voltage. Is there a way to output voltage as said, without changing the board?