You are on page 1of 3

4.

1 Programul software
int buzzerPin = 8; //piezo buzzer pin
int micPin = 7; //sound detector pin
int pirPin = 6; //motion detector pin
int ledPin = 13; //led pin

int pirState = LOW; //current pir state


int micState = LOW; //current mic value
int alarmState = LOW; //current alarm state

int noteDuration = 0;
int pauseBetweenNotes = 0;

int melody[]={NOTE_C8, NOTE_C8, NOTE_C8, NOTE_C8, NOTE_C8, NOTE_C8};

int noteDurations[]={4, 9, 9, 9, 4, 4};

void setAlarm(String value)


{ if(value.equals("ON"))
{ digitalWrite(ledPin, HIGH);

for (int thisNote=0; thisNote < 6; thisNote++){

noteDuration = 1000 / noteDurations [thisNote];


tone(8, melody [thisNote], noteDuration);

pauseBetweenNotes = noteDuration * 1.30;


delay(pauseBetweenNotes);
}
}

else{
digitalWrite(ledPin, LOW);
//stop the tone playing
noTone(buzzerPin);
}
}
void setup()
{ pinMode(buzzerPin,OUTPU
T); pinMode(ledPin,OUTPUT);
pinMode(pirPin,INPUT);
pinMode(micPin,INPUT);
}

void loop(){

pirState = digitalRead(pirPin);
micState = digitalRead(micPin);

if (pirState == HIGH and alarmState == LOW){


setAlarm("ON");
alarmState = HIGH;
}

if(micState == HIGH and alarmState == LOW){


setAlarm("ON");
alarmState = HIGH;
}

if(pirState == LOW and micState == LOW and alarmState == HIGH){


setAlarm("OFF");
alarmState = LOW;
}
}

You might also like