PANE - Sensor de movimiento PIR - BUZZER

Prof. Jorge Arévalos
mail@pastecode.io avatar
unknown
c_cpp
a year ago
2.1 kB
14
Indexable
Never
// C++ code
//
int EstadoSensor = 0;

int counter;

void setup()
{
  pinMode(2, INPUT);
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
  Serial.begin(9600);
  pinMode(11, OUTPUT);
}

void loop()
{
  //  Leer el estado del sensor / entrada digital
  EstadoSensor = digitalRead(2);
  //  compruebe si el pin del sensor es ALTO. si es
  // así, encienda el LED.
  if (EstadoSensor == HIGH) {
    digitalWrite(13, HIGH);
    digitalWrite(12, LOW);
    digitalWrite(11, LOW);
    Serial.println(" Sensor activado!");
    delay(1000); // Wait for 1000 millisecond(s)
    for (counter = 0; counter < 2; ++counter) {
      tone(11, 392, 200); // play tone 55 (G4 = 392 Hz)
      delay(200); // Wait for 200 millisecond(s)
      tone(11, 392, 200); // play tone 55 (G4 = 392 Hz)
      delay(200); // Wait for 200 millisecond(s)
      tone(11, 440, 400); // play tone 57 (A4 = 440 Hz)
      delay(400); // Wait for 400 millisecond(s)
      tone(11, 392, 400); // play tone 55 (G4 = 392 Hz)
      delay(400); // Wait for 400 millisecond(s)
      tone(11, 523, 400); // play tone 60 (C5 = 523 Hz)
      delay(400); // Wait for 400 millisecond(s)
      tone(11, 494, 500); // play tone 59 (B4 = 494 Hz)
      delay(500); // Wait for 500 millisecond(s)
      tone(11, 392, 200); // play tone 55 (G4 = 392 Hz)
      delay(200); // Wait for 200 millisecond(s)
      tone(11, 392, 200); // play tone 55 (G4 = 392 Hz)
      delay(200); // Wait for 200 millisecond(s)
      tone(11, 440, 400); // play tone 57 (A4 = 440 Hz)
      delay(400); // Wait for 400 millisecond(s)
      tone(11, 392, 400); // play tone 55 (G4 = 392 Hz)
      delay(400); // Wait for 400 millisecond(s)
      tone(11, 587, 400); // play tone 62 (D5 = 587 Hz)
      delay(400); // Wait for 400 millisecond(s)
      tone(11, 523, 500); // play tone 60 (C5 = 523 Hz)
    }
  } else {
    noTone(11);
    digitalWrite(13, LOW);
    digitalWrite(12, HIGH);
    digitalWrite(11, LOW);
    Serial.println(" Sensor desactivado!");
  }
}