Hello there
I have made a project using MQ2 gas sensor.
I have tested it with a lighter but it is not detecting anything
It only returns with the value 1023 in serial monitor
Can you please help what I am doing wrong
int redLed = 12;
int greenLed = 11;
int buzzer = 10;
int smokeA0 = A5;
// Your threshold value
int sensorThres = 400;
void setup() {
pinMode(redLed, OUTPUT);
pinMode(greenLed, OUTPUT);
pinMode(buzzer, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.print("Pin A0: ");
Serial.println(analogSensor);
// Checks if it has reached the threshold value
if (analogSensor > sensorThres)
{
digitalWrite(redLed, HIGH);
digitalWrite(greenLed, LOW);
tone(buzzer, 1000, 200);
}
else
{
digitalWrite(redLed, LOW);
digitalWrite(greenLed, HIGH);
noTone(buzzer);
}
delay(100);
}
Report this ad
Mediavine
View raw code
Vi/code]
I am worried that is my sensor not working or is there any problem with arduino.
I powered it with the usb that is connected to pc only
And I have found that during testing the power led of sensor is not glowing
So does it mean the sensor is dead.
If it is dead how it can return with the value of 1023
For an analog input you don’t use “ pinMode” , so you can delete that line from setup .
I’d disconnect the buzzer too , we don’t know much about that , but you don’t need it and it may be taking a high load .
Hi,
Lift the wire from the output pin of the sensor and connect it to the Vcc pin of the sensor and read what the monitor indicates.
Then;
Move the wire from Vcc pin to gnd pin of the sensor and see what the monitor indicates.
What you will be doing is using A0 as a crude voltmeter.
On Vcc you should see 1023
On gnd you should see 0 or close to it.
Can you post a picture of your project please so we can see your component layout?
Vaibhav2710:
Look I have found this. Is this true
Cause I haven't used the sensor for more than 2 months
Leave the sensor powered for 24 hours and try again. Like I said: "You are supposed to keep the device powered up for 24 hours before trying to get a reading but I don't think that would cause a full-scale reading."
TomGeorge:
Hi,
Lift the wire from the output pin of the sensor and connect it to the Vcc pin of the sensor and read what the monitor indicates.
Then;
Move the wire from Vcc pin to gnd pin of the sensor and see what the monitor indicates.
What you will be doing is using A0 as a crude voltmeter.
On Vcc you should see 1023
On gnd you should see 0 or close to it.
What type of pin I have to use for this (digital or analog)