So I'm using an MQ2 smoke sensor in a project and the project requires wifi also
When I don't include the wifi code the sensor read value
When I include the wifi code the sensor doesn't read and gives 0.
I'm using an esp32 dev kit v4 and the MQ2 smoke sensor is connected to pin 25
This is my code
#include <WiFi.h>
const char* ssid = "ssid";
const char* password = "password";
int MQ2Sensor;
int MQ2;
int buzzer = 18;
int led = 16;
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
Serial.print("Got IP: "); Serial.println(WiFi.localIP());
delay(10000);
}
void loop() {
MQ2Sensor = analogRead(25);
MQ2 = MQ2Sensor - 2000;
Serial.print("Sensor Value: ");
Serial.print(MQ2);
if (MQ2 > 400)
{
digitalWrite(buzzer, HIGH);
digitalWrite(led, HIGH);
}
else {
digitalWrite(buzzer, LOW);
digitalWrite(led, LOW);
}
Serial.println("");
delay(2000); // wait 2s for next reading
}
What can I do to solve it?