Struggling to understand part of a code

I have a small LCD project that I like to work on when I have time, compared to most things on here it is very simple. I would like to display some data from the Arduino but cannot figure out how to code it.

Voltage Display
0.15 9.7
0.31 9.9
0.46 10.1
0.62 10.3
0.78 10.5
0.93 10.7
1.09 11.0
1.24 11.4
1.4 11.7
1.56 12.1
1.71 12.4
1.87 12.8

Should I just turn this into a big if string or are there smarter ways of writing this?

How about if I wanted to display 0 to 5 volts and all the voltage in between but have them displayed as a percentage surely this could be done quite simply?

There are smarter ways but you have not provided enough information to know which smarter way is appropriate.

How did you get the Voltage and Display numbers?

The numbers are taken from page 2 of this PDF

I have this Wideband oxygen sensor but rather than buy one of their displays I would like to couple it to my own display so I can have other relevant information on the same screen. Without plotting these numbers on a graph but I cannot be sure, but I am of the opinion that this is not linear.

I've got one of those. Unfortunately mine got a bit melted. :frowning:

Why don't you just use the linear output? Then you can use the formula they give you to work out lambda or AFR.

Mine is a version 1, it has no linear output unfortunately.

Excel claims this is the sixth order polynomial fit...

-0.3481pow(V,6) + 3.4583pow(V,5) - 12.813pow(V,4) + 22.269pow(V,3) - 18.043pow(V,2) + 7.4273pow(V,1) + 8.8711

The highest error is 1.17% (at 2.65, 15.6). Accurate enough?

The "Display" values are only given to one decimal. If you put +/- 0.1 error bars on the Y axis you can see that a quadratic fits just as well.
Display = 0.4972 * Voltage * Voltage + 0.8003 * Voltage + 9.59

Thanks for the input on this, but, how do you manage to work it out? Having the answer is good, but I can't figure out how you got there. Can you explain, or point me in the direction of a resource that will help me understand a little better the information you posted?

This is what I did...

• Start Excel
• Navigate to the datasheet
• Select, copy, and paste the data into Excel
• Insert a simple scatter plot of the data
• Select a data point, right-click to display the context menu, click Add Trendline
• Fiddle with the trendline parameters until the fit appears to be good
• Ensure Display Equation on Chart is checked
• Click Close

The box containing the equation is a simple text box. The equation can be selected and copied.

I'll never look at excel the same way again.

If I use that equation in the code somehow, could I get the display to show the AFR value based on the voltage that is inputted into the Arduino?

If so, that could potentially remove a very long 'if' string and replace it with just a few lines of code couldn't it?

Yes and yes.

Great, thank you for your help.