RS_air = sensor_volt/(5.0-sensor_volt); I am guessing that they are converting the voltage back to resistance?? Can anyone explain how that equation works, or point me in the right direction ? I am trying to understand how they came up with that equation.

The grove alcohol sensor uses an MQ303A sensor.Datasheet for the grove module and the MQ303A sensor can be found within the wiki (see link above).

To accurately convert an ADC value to voltage, it is correct to divide by 1024, but probably not to multiply by 5.0. Substitute the actual ADC reference voltage instead.

The RS_air value is a dimensionless ratio that is useful for calculating the sensed alcohol concentration. In principle it could be a resistance (note the comment "omit *R16") and comes from the use of a voltage divider in the sensor. Consult the sensor data sheet for more information.

It looks to me that the code (as well as the comments) in the second part of the tutorial is wrong, specifically this section. The RS_gas formula lacks the parentheses.

As you can see, the R1 is missing from their equation.Then I suddenly realised (as you pointed out) that they use this RS_air value in a ratio.

Which means that when you divide RS_gas by RS_air, the R1 values cancel out.So you don't need to know the R1 value - and probably why it is omitted.

I did not know what "R16" was in their code comment. But now it makes sense when you look at the datasheet for the grove sensor (that you highlighted). It is the 10k resistor connected to the MQ303A, alcohol sensor. And I guess it acts like a voltage divider.

Thank you very much for your help.

Now, the next niggling point, that relates to the sensor_volt calculation:

There are 1024 steps in the ADC result, so 1024 is the divisor to use. (You would not use "1" as the divisor for a 2 step ADC).

If you want to know the best estimate of the actual voltage reported by the ADC, you have to use the actual value of the reference voltage, which is almost never 5.000 V. If you are using USB to power the Arduino, it is probably about 4.5V. Measure it with your multimeter.

Many people incorrectly use 1023 as the divisor, and this has been debated many times, particularly on this forum. Please look up those discussions.

Anyone who understands basic mathematics and thinks about it for a bit can explain why 1024 is correct. ...It is silly to stick with someone else's example, if it gives you the wrong answer.

I personally don't think that the ability to do basic maths has anything to do with the "divide by 1023 vs 1024" debate. I do think, however that there are far too many examples on the internet (including the one from the official Arduino website), that show the method that I employed above, and not enough examples which explain the key information required to make an informed decision.

The biggest misconception that I had - actually related to the Analog reading of 1023, and what that reading actually means. I thought that the reading of 1023 equates to 5V, or to the Vref. So when you have that misconception, it doesn't make sense to divide by 1024 ----------------------------------------------------------------------------For example,If Vin is 5V, and Vref is 5V, then using the formula you provided, ADC = 1024. But you never get a reading of 1024, you get a reading of 1023.

Put another way, if you get a reading of 1023 on the analog pin, and know that Vref is 5V, and try to calculate Vin using that formula, you will NOT get the expected answer of 5V. You get 4.995117. But if you instead, divide by 1023, you get the expected result of 5V... and the misconception is fortified.-----------------------------------------------------------------------------But there is some VERY IMPORTANT INFORMATION MISSING.

According to the datasheet:"The ADC converts an analog input voltage to a 10-bit digital value through successive approximation. Theminimum value represents GND and the maximum value represents the voltage on the AREF pin minus 1 LSB. "

With that information in mind, the formula you provided from the datasheet makes a whole lot more sense.That means, if you have a Vref of 5.0, the maximum Vin that the ADC can detect is actually 4.995117 and not 5V.

Which means, that if you supply any voltage between 4.995117 to 5V to the Analog pin, it will show a reading of 1023. Penny dropped at that moment.

Which means that if you choose to divide by 1024, you must understand that the calculated Vin may be out by as much as 1 LSB. So not only must you use the formula that you provided, you also need to calculate 1 LSB, in order to understand the range that the Analog reading represents.

Now that may have been clear to you all along, but if more people provided that key bit of information, then there would be much less debating.

The 1023/1024 thing depends on the nature of the ADC circuitry, either is entirely possible. Infact with a SAR (successive approx) ADC, its the inbuilt DAC's characteristics that determinewhich the correct divider is. R-2R DACs are in the 1024 camp, resistor-string are 1023, unless ithas 1/2R resistors at each end. Some ADC techniques won't be that accurately defined anyway.

This doesn't matter as its only going to matter for high accuracy where you'd be calibrating anyway.

It would matter a lot for a 3-bit ADC, of course!

[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]