Advertisement
safwan092

Untitled

May 12th, 2023
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #include <Servo.h>
  2.  
  3. Servo myservo;
  4.  
  5. #define Servo_pin 2
  6. #define Flame_pin 3
  7. #define buzzer_pin 4
  8. #define Gas_A_pin A6
  9.  
  10.  
  11.  
  12. int Gas_State;
  13. int Flame_State;
  14.  
  15.  
  16.  
  17. void setup() {
  18. Serial.begin(9600);
  19. pinMode(Gas_A_pin, INPUT);
  20. pinMode(Flame_pin, INPUT);
  21. pinMode(buzzer_pin, OUTPUT);
  22. myservo.attach(Servo_pin);
  23. myservo.write(0);
  24. digitalWrite(buzzer_pin, 0);
  25. }
  26.  
  27. void loop() {
  28. Gas_State = analogRead(Gas_A_pin);
  29. Flame_State = digitalRead(Flame_pin);
  30. Serial.println(Gas_State);
  31. Serial.println(Flame_State);
  32. if (Gas_State > 500 || Flame_State == 0) {
  33. myservo.write(90);
  34. digitalWrite(buzzer_pin, 1);
  35. delay(5000);
  36. }
  37. else {
  38. myservo.write(0);
  39. digitalWrite(buzzer_pin, 0);
  40. delay(2000);
  41. }
  42. delay(50);
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement