Page 250 - MDP2022-3
P. 250
# 화재감지센서
const int sensor = 2;
const int warning_led = 12;
const int safe_led = 11;
int val = 0;
void setup() {
Serial.begin(9600);
pinMode(sensor, INPUT);
pinMode(13, OUTPUT);
}
void loop() {
val = digitalRead(sensor);
if (val == HIGH) {
Serial.println("warning!!");
tone(13, 262);
digitalWrite(warning_led, HIGH);
delay(1000);
}
else if (val == LOW) {
Serial.println("safe");
noTone(13);
digitalWrite(warning_led, LOW);
delay(1000);
}
}