Advertisement
andretafta

Program Node MCU + Gas Sensor (MQ09)

Aug 18th, 2020
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int buzzer = D2;
  2. int smokeA0 = A0;
  3.  
  4. // Your threshold value. You might need to change it.
  5. int sensorThres = 600;
  6.  
  7. void setup() {
  8.  pinMode(buzzer, OUTPUT);
  9.  pinMode(smokeA0, INPUT);
  10.  Serial.begin(9600);
  11. }
  12.  
  13. void loop() {
  14.  int analogSensor = analogRead(smokeA0);
  15.  
  16.  Serial.print("Pin A0: ");
  17.  Serial.println(analogSensor);
  18.  // Checks if it has reached the threshold value
  19.  if (analogSensor > sensorThres)
  20.  {
  21.    tone(buzzer, 1000, 200);
  22.  }
  23.  else
  24.  {
  25.    noTone(buzzer);
  26.  }
  27.  delay(100);
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement