Smart Livestock Management
The mq2 will need a 5v, gnd, and an analog output pin for my application. The 2 ESP32 pins that are analog output are GPIO 25 & 26 (info on pinout from here).
#define MQ2pin 25 // or 26, either is fine
float sensorValue; //variable to store sensor value
void setup() {
Serial.begin(9600); // sets the serial port to 9600
Serial.println("MQ2 warming up!");
delay(20000); // allow the MQ2 to warm up
}
void loop() {
sensorValue = analogRead(MQ2pin); // read analog input pin 0
Serial.print("Sensor Value: ");
Serial.println(sensorValue);
delay(2000); // wait 2s for next reading
}
#define Buzzer 4 // (can be any except 34-39)
void setup(){
Serial.begin(115200);
Serial.println("Hello Buzz!");
pinMode(Buzzer, OUTPUT);
}
void loop(){
delay(1000);
digitalWrite(Buzzer, HIGH);
delay(1000);
digitalWrite(Buzzer, LOW);
}
#define MQ2pin 25 // or 26, either is fine
#define Buzzer 4 // can be any
float sensorValue; //variable to store sensor value
int dangerValue = 800; // arbitrary
void setup() {
Serial.begin(9600); // sets the serial port to 9600
Serial.println("MQ2 warming up!");
pinMode(Buzzer, OUTPUT);
delay(20000); // allow the MQ2 to warm up
}
void loop() {
sensorValue = analogRead(MQ2pin); // read analog input pin 0
Serial.print("Sensor Value: ");
Serial.println(sensorValue);
if (sensorValue >= dangerValue ) {
digitalWrite(Buzzer, HIGH); // buzzer on
delay(20000); // buzzer on for 20 s to allow the miner to react
}
delay(2000); // wait 2s for next reading
}
Wowki wiring diagram: