Customizable 0-5V output

Support forum for the Lambda Shield designed to connect Bosch LSU 4.9 wideband oxygen sensors to Arduino projects.
Post Reply
User avatar
Christian_Bylund
Posts: 126
Joined: 07 Mar 2015 18:09

Customizable 0-5V output

Post by Christian_Bylund » 16 Apr 2020 22:49

Mario wrote:How can I get a 0-5V output signal compatible with YourDyno?
Warning! Make sure you verify any signals before connecting it to sensitive equipment. Use at your own risk!

Image

The example code already have a PWM function to output an analog signal.

Code: Select all

void UpdateAnalogOutput() {

  //Local constants.
  const float AirFuelRatioOctane = 14.70;
  const int maximumOutput = 51; /* 1V */
  const int minimumOutput = 0;  /* 0V */

  //Local variables.
  int analogOutput = 0;
  float lambdaAFR = Lookup_Lambda(adcValue_UA) * AirFuelRatioOctane;

  //Convert lambda value to PWM output.
  analogOutput = map(lambdaAFR * 100, 2000, 1000, minimumOutput, maximumOutput);

  //Make sure we do not exceed maximum values.
  if (analogOutput > maximumOutput) analogOutput = maximumOutput;
  if (analogOutput < minimumOutput) analogOutput = minimumOutput;
  
  //Set PWM output.
  analogWrite(ANALOG_OUTPUT_PIN, analogOutput);
}
We need to adopt it to output 0V at 7.35 AFR and 5V at 22.39 AFR. We do this by modifying these two lines:
const int maximumOutput = 255; /* 5V */
analogOutput = map(lambdaAFR * 100, 735, 2239, minimumOutput, maximumOutput);


maximumOutput need to reflect the maximum output voltage 0 = 0V; 51 = 1V; 255 = 5V.

The map function is modified with the AFR max and min values * 100. 7.35 AFR at minimumOutput (0V) and 22.39 AFR at maximumOutput (5V). At this point the signal is a PWM signal adjusting the duty cycle with the map function. To filter the signal to a DC-voltage we need to add a RC-filter to the output as the following schematic describes.

Image
To improve response time, reduce resistance from 1k to 470R.

Here is the output signal at 22.39 AFR (5V):
Image

Also check out our video of a 0-1V output for a Lambda Gauge.
Best Regards,
Christian Bylund
Bylund Automotive AB

Post Reply