possible mq calibrating method?

I'm going to tinker with a couple of sensors. The Methane/MQ 4 I was thinking of doing this way:

Do the burn-in.
Fill a container with pure natural gas (supposedly 95-96% pure, so I'd factor for that).
Use a variable resistor and move it around until the analog output hits near the 1024 max. The point is that I'm trying to get the widest spread of analog readings, so that once the conversion to ppm is calculated, there's more accuracy overall.
Use the reading to write the conversion constant in a log 10 formula based on 950,000-960,000 ppm reflected in the analog reading. I saw where another poster had come up with a formula this way:

*Since the closest thing to a known methane value that that they had available was straight natural gas coming through the line to a valve in the chemistry lab at the school, they used that as a sample to represent a saturation value (in other words, a million ppm). They read that the average commercial natural gas supplied is about 96 percent pure, so they let the saturation count as 960000 ppm. The analog read value with the sensor next to the valve (as saturated as they could get it) was 690. The lowest analog read value they got was 38. *
Since the data sheet for the mq4 says that it's base 10 logarithmic, this is how they came up with their conversion:
960000=10k(690-38) or max val ppm= 10 k (max analog read-min analogread)
Log 960000 = k(652)
Log960000/652 = k = .009
so the final formula that converts the analog read to ppm is based on the formula:
Y= 10 .009(x-38) x being the analog read value

The math makes sense to me, but it seems that this would be improved by tinkering with the resistor value until a higher max analog read value comes out. Let's say that what I'm thinking of is correct and I get something like 1017 as my max saturated value (because bumping the potentiometer any more runs it into the 1024 limit of the analog read range and I don't want signal noise knocking it "out of zone") and 38 is my low. My k in this case would be .006110594, so the sketch would look something like this:

const int analogInPin = A0; // Analog input pin that the potentiometer is attached to
const int ledPin = 13; // LED connected to digital pin 13
const int audioPin = 8;
int sensorValue = 0; // value read from the sensor
void setup() {

  • // initialize serial communications at 9600 bps:*

  • Serial.begin(9600);*

  • pinMode(ledPin, OUTPUT); // sets the digital pin as output*

  • pinMode(audioPin, OUTPUT);*
    }
    void loop() {

  • // read the analog in value:*

  • // read the sensor:*

  • int sensorReading = analogRead(A0);*
    _ float ppmValue = pow(10,(.006110594*(sensorReading-38)));_

  • // print the sensor reading so you know its range*

  • Serial.print("ppm methane = " ); *

  • Serial.println(ppmValue);*

  • // map the analog input range (in this case, 400 - 1000 from the photoresistor)*

  • // to the output pitch range (120 - 1500Hz)*

  • // change the minimum and maximum input numbers below*

  • // depending on the range your sensor's giving:*

  • int thisPitch = map(sensorReading, 0, 1000, 35, 18000); *
    // print the results to the serial monitor:

  • tone(9, thisPitch, 10);*

  • delay(1); // delay in between reads for stability*

  • // determine alarm status*

  • if (sensorReading >= 400)*

  • {*

  • digitalWrite(ledPin, HIGH); // sets the LED on*

  • }*

  • else*

  • {*

  • digitalWrite(ledPin, LOW); // sets the LED off*

  • }*

}

Does this seem OK? Also, anyone finding that the suggested 3 minute warmup is indeed the best?

PS. Adding the audio is for fun.

I have no idea how to use that sensor or whether your code will work.

Purely looking at the code itself, the arguments to your call to map() do not match the corresponding comment, I don't know what "delay in between reads for stability" means but the delay seems pointless, and when you call pow() there is no need to put parenthesis around the second argument. In general I would suggest that comments such as "sets the digital pin as output" that just replicate the code serve no purpose, and comments such as "print the results to the serial monitor" are similarly misleading/wrong since it no longer does that; comments are best used to explain things that are not obvious from the code such as how or why the code does something or what values in the code represent. Otherwise it all looks great. Does it do what you want?