Hey guys, I am new to this forum and arduino so please excuse me !
I am using an arduino UNO and an MQ2 Gas sensor for one of my projects, the code as given below:
int smokeA0 = A0;
int sensorThres = 400;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(smokeA0, INPUT);
Serial.begin(9600);
}
void loop() {
int analogSensor = analogRead(smokeA0);
Serial.print("V: ");
Serial.println(analogSensor);
if (analogSensor > sensorThres)
{
// turn the LED ON
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
// turn the LED OFF
}
else
{
digitalWrite(LED_BUILTIN, HIGH);
}
delay(100);
}
Its a very Basic Code but whenever I check the serial output, I get values around 24-28
and also, whenever I give a wrong value like:
int smokeA0 = A1;
I get values around 300 and they change a bit when i bring perfume near it but only by 5-10
I have connected A0 to A0 on the Arduino but also tried other analogue ports with the same results
GND to GND
VCC to 5V
Can't figure out whats wrong with it...