Created
July 16, 2023 14:21
-
-
Save rafirh/8d8fc0afdb98051ab8478d72116ab01e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const int smokeSensorPin = A0; | |
const int buzzerPin = 9; | |
const int currentLevel = 0; | |
void setup() { | |
Serial.println("Running ..."); | |
pinMode(buzzerPin, OUTPUT); | |
pinMode(smokeSensorPin, INPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
int smokeLevel = analogRead(smokeSensorPin); | |
Serial.print("Smoke level: "); | |
Serial.println(smokeLevel); | |
if (smokeLevel > 700) { | |
alarmLevel3(); | |
} else if (smokeLevel > 600) { | |
alarmLevel2(); | |
} else if (smokeLevel > 500) { | |
alarmLevel1(); | |
} else { | |
digitalWrite(buzzerPin, LOW); | |
} | |
} | |
void alarmLevel1() { | |
for (int i = 0; i < 3; i++) { | |
digitalWrite(buzzerPin, HIGH); | |
delay(500); | |
digitalWrite(buzzerPin, LOW); | |
delay(500); | |
} | |
} | |
void alarmLevel2() { | |
for (int i = 0; i < 3; i++) { | |
digitalWrite(buzzerPin, HIGH); | |
delay(250); | |
digitalWrite(buzzerPin, LOW); | |
delay(250); | |
} | |
} | |
void alarmLevel3() { | |
digitalWrite(buzzerPin, HIGH); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment