At the first,I try the MQ2 and this is my code:
int sensorValue = analogRead(A0);
I have some question about it.
first:What’s the meaning about it ((vol=(float)sensorValue/1024*5.0;))
second:I test the code and in the monitor it displayed .What’s the 1.5 mean and what ppm of it
(float) is a cast - it forces the next expression to be of that type - in other words the value of sensorValue is converted
to floating point before the division (otherwise it would be integer division which would truncate).
The calculation is giving the voltage on the analog pin, assuming the default analog reference of Vcc is used and
Vcc is actually 5V.
For ppm you need to look at the datasheet for the sensor to see how to convert voltage to ppm.