sherzaad:
Is this the sensor you using?
Gas Sensors / FIGARO Engineering inc. World leader in gassensing innovation
If so, you code looks likes you have recycled it from somewhere else. The naming make no sense!
but looking at the datasheet, something like this may work (untested!):
NOTE: look at the datasheet wiring of the sensor!
const uint8_t SENSOR_HEATER_ENABLE = 30; //pin to enable heater. Change pin assignment as required!
const uint8_t SENSOR_ENABLE = 31; // pin to enable sensor reading Change pin assignment as required!
const uint8_t SENSOR_READ = 32; // analog pin to read sensor
const uint8_t CYCLE_TIME = 236; // 236ms as per datasheet (250ms -14ms)
const uint8_t HEATER_ON_TIME = 14; // 14ms as per datasheet
uint16_t Sensor_Reading = 0;
unsigned long oldtime;
//IMPORTANT NOTE: following code follows the TGS2444 datasheet timing and suggested wiring circuit!!!!
void setup() {
Serial.begin(115200);
pinMode(SENSOR_ENABLE, INPUT);
pinMode(SENSOR_HEATER_ENABLE, INPUT);
digitalWrite(SENSOR_ENABLE, LOW);
digitalWrite(SENSOR_HEATER_ENABLE, HIGH);
}
void loop() {
oldtime = millis();
digitalWrite(SENSOR_HEATER_ENABLE, LOW); //enable sensor heater
delay(2); //delay as per data sheet
digitalWrite(SENSOR_ENABLE, HIGH); //enable sensor for readout
delay(5); //delay as per data sheet
Sensor_Reading = analogRead(SENSOR_READ); //take a reading from the optical sensor pin
digitalWrite(SENSOR_ENABLE, LOW); //disable sensor
while (oldtime - millis() < HEATER_ON_TIME); //14ms delay as per data sheet. using millis to compensate for other delays
oldtime = millis();
digitalWrite(SENSOR_HEATER_ENABLE, HIGH); //disable sensor heater
Serial.println(Sensor_Reading); // the analog reading of the optical sensor
while (oldtime - millis() < CYCLE_TIME); //236ms delay as per data sheet. using millis to compensate for other delays
}
same things seems not work same value. TGS2603