I have started a project where arduino works as boost enrichment at vehicle. So when i install a turbo to naturally aspired car, the arduino is checking narrow band oxygen sensor voltage (100-900mV) and if car runs too lean under boost, extra fuel injector starts injecting more gas to intake manifold.
Problem is to get as accurate voltage as possible from O2 sensor.
So if i c&p the code above, does it mean i can just put O2 voltage wire to A0 and i'll get pretty precise voltages or does that only check the arduinos internal voltages?
Have a look at this as well. Depending on what type of Arduino your using you can set the Analogue reference voltage to 1.1V so your analogRead values should range between 0 at 0V to 1023 at 1.1V
NollaQ:
I have UNO. Does it work with it and how accurate it is? I have AREF pin, i guess thats the one?
For the UNO you use analogReference(INTERNAL); to select the internal 1.1V reference. As the name implies it is an internal voltage reference not an external one connected to the AREF pin.
Be aware if your connecting a voltage to the AREF pin you can damage the Arduino if you don't observe the warning...
If you're using an external reference on the AREF pin, you must set the analog reference to EXTERNAL before calling analogRead(). Otherwise, you will short together the active reference voltage (internally generated) and the AREF pin, possibly damaging the microcontroller on your Arduino board.
As for accuracy...
Using the default 5V reference your getting about 0.0049V per ADC step but using the 1.1V as reference your getting about 0.0011V per step so almost 5 times as accurate.
I would offer that the teensy have a 16 bit ADC so with a simple chip change, you get a much higher resolution.
an alternative is to use any ADC chip that would be fast enough and have enough accuracy for you.
consider that if you use the 1.1v input from the arduino and have a 900mV signal, you are working with 82% of the 10 bit ADC range. that means your readings from 0 to 900mV will result in 0-837 steps on the ADC.
if you used a 12 bit ADC, that would offer 8,1268 steps.
if you used the same 81% of that, you would have 6,650 steps.
I do not know if the Teensy offers a 1.1 internal reference voltage.
So if i use internal reference and put O2 sensor voltage wire to A0, how do i calculate voltage?
Use the ADC as you normally would (with the 1.1 V reference), but first use it to measure one or more accurately known voltages between 0 and 1 V, and find a calibration factor that reproduces those values as closely as possible.
Ok. I think 837 steps would be enough. For example 0.5V is perfect air/fuel ratio. If it goes under 0.47V, injector strarts pushing more gas for short pulses and if voltage drops even more, pulse lasts longer.
The voltage you get from the O2 sensor will be very noisy, you need filtering hardware and software to get a reading.
These may help.
google O2 sensor Arduino